12.07.2015 Views

PostGIS 1.5.8 Manual - Fedora Project Packages GIT repositories

PostGIS 1.5.8 Manual - Fedora Project Packages GIT repositories

PostGIS 1.5.8 Manual - Fedora Project Packages GIT repositories

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>PostGIS</strong> <strong>1.5.8</strong> <strong>Manual</strong>83 / 310Build province boundaries with holes representing lakes in the province from a set of province polygons/multipolygons and waterline strings this is an example of using <strong>PostGIS</strong> ST_AccumNoteThe use of CASE because feeding a null array into ST_MakePolygon results in NULLNotethe use of left join to guarantee we get all provinces back even if they have no lakesSELECT p.gid, p.province_name,CASE WHENST_Accum(w.the_geom) IS NULL THEN p.the_geomELSE ST_MakePolygon(ST_LineMerge(ST_Boundary(p.the_geom)), ST_Accum(w.the_geom)) ENDFROMprovinces p LEFT JOIN waterlines wON (ST_Within(w.the_geom, p.the_geom) AND ST_IsClosed(w.the_geom))GROUP BY p.gid, p.province_name, p.the_geom;--Same example above but utilizing a correlated subquery--and PostgreSQL built-in ARRAY() function that converts a row set to an arraySELECT p.gid, p.province_name, CASE WHENEXISTS(SELECT w.the_geomFROM waterlines wWHERE ST_Within(w.the_geom, p.the_geom)AND ST_IsClosed(w.the_geom))THENST_MakePolygon(ST_LineMerge(ST_Boundary(p.the_geom)),ARRAY(SELECT w.the_geomFROM waterlines wWHERE ST_Within(w.the_geom, p.the_geom)AND ST_IsClosed(w.the_geom)))ELSE p.the_geom END As the_geomFROMprovinces p;See AlsoST_Accum, ST_AddPoint, ST_GeometryType, ST_IsClosed, ST_LineMerge7.3.24 ST_MakePointST_MakePoint — Creates a 2D,3DZ or 4D point geometry.Synopsisgeometry ST_MakePoint(double precision x, double precision y);geometry ST_MakePoint(double precision x, double precision y, double precision z);geometry ST_MakePoint(double precision x, double precision y, double precision z, double precision m);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!