Database Reference
In-Depth Information
Simplifying
geometries
with
PostGIS
topology
Inapreviousrecipe,weusedthe ST_SimplifyPreserveTopology functiontotry
to generate a simplification of a polygonal PostGIS layer.
Unfortunately,whilethatfunctionworkswellforlinearlayers,itproducestopological
anomalies(overlappingandholes)insharedpolygonborders.Youusedanexternal
toolset ( GRASS ) to generate a valid topological simplification.
In this recipe, you will use the PostGIS topology support to perform the same task
withinthespatialdatabasewithoutneedingtoexportthedatasettoadifferenttoolset.
Getting ready
To get started, follow the ensuing steps:
1. BesurethatyouhavethePostGIStopologysupportenabledinyourdatabase
instance. This support is packaged as a separate extension and, if you are
usingPostgreSQL9.1ornewerversions,youcaninstallitusingthefollowing
SQL CREATE EXTENSION command:
postgis_cookbook=# CREATE EXTENSION
postgis_topology;
2. Download the administrative area archive for Hungary from the gadm.org
website at http://gadm.org/country (or use the copy included in the code
bundle provided with this topic).
3. Extractthe HUN_adm1.shp shapefilefromthearchivetoyourworkingdirect-
ory, working/chp03 .
4. ImporttheshapefiletoPostGISusingatoolsuchas ogr2ogr or shp2pgsql ,
as follows:
ogr2ogr -f PostgreSQL -t_srs EPSG:3857
-nlt MULTIPOLYGON -lco
GEOMETRY_NAME=the_geom -nln chp03.hungary
Search WWH ::




Custom Search