X-B4, 2012
RENSICS
layers and almost
of the data in the
ata itself contains
ols to make these
1e standard spatial
the measurements
e newest PostGIS
and opened some
distance and area
011, PostGIS 2.0
otivated our early
; compatible with
vork describes the
in our production
in the hope that it
eSQL installation.
tribution channels
es), and therefore
han one minute to
ile from source.
rface and may fol-
t check the option
staller from www.
GIS with the com-
package manager
2:
ite channel (faster)
)
tGIS with the com-
International Archives of the Photogrammetry, Remote Sensing and Spatial Information Sciences, Volume XXXIX-B4, 2012
XXII ISPRS Congress, 25 August — 01 September 2012, Melbourne, Australia
After these steps the user can populate the database with data and
start using it. Compiling from source may take a long time mainly
because the user has to gather appropriate versions of all the nec-
essary libraries and make sure that the resulting environment is
sound for entering production. The faster approach is to use an
alternate source like ppa:sharpie/postgis — nightly (this works for
Ubuntu Server), but such sources available at this time are clearly
marked as unstable.
PostGIS 2.0 can be installed on an existing database using the
same procedures (it is recommended that any changes - related or
not to PostGIS - to a production database are first validated on a
testing environment).
12 Usage
Let us consider the following questions an Environmental Foren-
sics expert in the Brazilian Federal Police might need answered:
e Is the deforested area in a national park?
e How far is the nearest water body from the landfill?
e When was this area deforested?
* Does this person have a mining permit for extracting gold in
this part of the river?
* Have any forensic reports ever been produced near this area?
Let us also consider a hypothetical PostgreSQL 9.1/PostGIS 2.0
database containing the tables used in the examples populated
with the correct information.
For the first question, the following example query would list all
the national parks that intersect with that area and output the ac-
tual overlapping area:
SELECT name,ST_Intersection(geom,deforested_area)
FROM protected_areas. national parks
WHERE ST Intersects(geom,deforested area);
For the next question, this is how we would find the distance in
meters, the name and the geometry of the N nearest water bodies:
SELECT
name,
ST Distance(geom: :geography,
landfill geom: :geography) as distance,
geom
FROM physical maps.water bodies
ÜRDER BY distance ASC NULLS LAST
LIMIT N;
The third question may not be directly answerable using only a
query, but we may search the image footprint database for satel-
lite Images of the area for visual inspection:
SELECT id,date,download_path,geom
FROM Satellite images.image catalog
WHERE ST Intersects(geom,deforested area) ;
Another alternative would be to use the new raster extension in
PostGIS 2.0 for querying the satellite images directly and return-
ing just the part of the images that overlap the area of interest.
The other two questions could be answered in a similar way.
These examples demonstrate what kind of usage a spatially en-
abled database could be put to. End users would not make this
kind of database access, but these queries could be run on the
background by an application.
2 POSTGIS 2.0 FEATURE HIGHLIGHTS
PostGIS 2.0 has several new features and improvements from ver-
sion 1.5.3. Some of these features are very interesting from a
database maintenance but these stand out from the rest.
2.1 Fixing invalid geometries
The new function ST. MakeValid tries to automatically produce a
valid version of invalid geometries without losing vertices. This
operation does not work with all possible invalid geometries, but
it tries to salvage as much as possible. That functionality is im-
portant for Inteligeo because the data in the system is produced by
third parties and arrives with very low quality control. ST. MakeValid
provides an alternative to discarding invalid geometries from the
Source data.
The new function ST_IsValidDetail can be of great help if one
tries to correct the data manually because it provides details on
the reason for the invalidity and the precise location of the viola-
tion. That can help a GIS analyst to be more efficient at correcting
inconsistencies.
3
4
(a) Invalid “bowtie” polygon (b) Topologically correct version
Figure 1: Invalid geometry before and after correction with
ST_MakeValid
Figure la displays the graphical representation of the polygon
defined in the WKT form POLYGON((-1 0, 1 0, 0 1, 0 -1, -
1 0)), which is considered to be topologically invalid (section
4.3.5 of [5]) because it self-intersects. Another issue with this
geometry is that vertices have to be traversed in the clockwise
order for the boundaries of polygons and counter-clockwise for
the holes inside polygons. The implications of this are immedi-
ately perceived when we try to calculate the area of such polygon:
ST.Area of the geometry in Figure la yields 0 (zero area). The
same operation applied on the geometry generated by ST. MakeValid
on Figure 1b produces the correct area of 1. That geometry can
be represented in WKT as MULTIPOLYGON(((-1 0, 0 0, 0 -1,
-1 0)),((0 0, 0 1, 1 0, 0 0))).
Other geometrical operations also produce unexpected results when
applied to invalid geometries; Figure 2 displays the result of buffer-
ing (ST-Buffer) the geometries in Figure 2.