From: Regina Obe Date: Mon, 21 Jul 2008 12:09:30 +0000 (+0000) Subject: Move over ST_GeometryType, ST_MakePolygon X-Git-Tag: 1.4.0b1~828 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a759715664ebfe8b0b0497d6c4d8ec1134a4a27;p=postgis Move over ST_GeometryType, ST_MakePolygon git-svn-id: http://svn.osgeo.org/postgis/trunk@2871 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/doc/reference.xml b/doc/reference.xml index 7fb8db45e..70350f400 100644 --- a/doc/reference.xml +++ b/doc/reference.xml @@ -637,18 +637,6 @@ GROUP BY gid, field1,field2; - - ST_GeometryType(geometry) - - - Returns the type of the geometry as a string. EG: - 'ST_Linestring', 'ST_Polygon','ST_MultiPolygon' etc. This function differs from - GeometryType(geometry) in the case of the string and ST in front that is returned, - as well as the fact that it will not indicate whether the geometry - is measured. - - - ST_X(geometry) @@ -1589,89 +1577,6 @@ GROUP BY gid, field1,field2; - - ST_MakePolygon(linestring geometry) - - - Creates a Polygon formed by the given shell. Input - geometries must be closed LINESTRINGS (see ST_IsClosed and ST_GeometryType). This function will - not accept a MULTILINESTRING. - - -SELECT ST_MakePolygon(ST_GeomFromText('LINESTRING(75.15 29.53,77 29,77.6 29.5, 75.15 29.53)')); ---If linestring is not closed ---you can add the start point to close it -SELECT ST_MakePolygon(ST_AddPoint(foo.open_line, ST_StartPoint(foo.open_line))) -FROM ( -SELECT ST_GeomFromText('LINESTRING(75.15 29.53,77 29,77.6 29.5)') As open_line) As foo - - - - - - ST_MakePolygon(linestring geometry, linestrings - geometry[]) - - - Creates a Polygon formed by the given shell and array of - holes. You can construct a geometry array using ST_Accum or the PostgreSQL ARRAY[] and - ARRAY() constructs. Input geometries must be closed LINESTRINGS - (see ST_IsClosed and ST_GeometryType). - - ---Build a donut with an ant hole -SELECT ST_MakePolygon( - ST_ExteriorRing(ST_Buffer(foo.line,10)), - ARRAY[ST_Translate(foo.line,1,1), - ST_ExteriorRing(ST_Buffer(ST_MakePoint(20,20),1)) ] - ) -FROM - (SELECT ST_ExteriorRing(ST_Buffer(ST_MakePoint(10,10),10,10)) - As line ) - As foo; - ---Build province boundaries with holes ---representing lakes in the province from a set of ---province polygons/multipolygons and water line strings ---this is an example of using PostGIS ST_Accum ---NOTE: the use of CASE because feeding a null array into ---ST_MakePolygon results in NULL ---NOTE: the use of left join to guarantee we get all provinces back even if they have no lakes -SELECT p.gid, p.province_name, - CASE WHEN - ST_Accum(w.the_geom) IS NULL THEN p.the_geom - ELSE ST_MakePolygon(ST_LineMerge(ST_Boundary(p.the_geom)), ST_Accum(w.the_geom)) END -FROM - provinces p LEFT JOIN waterlines w - ON (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 array ---NOTE: use of case because ST_MakePolygon ---evidentally doesn't like empty arrays either -SELECT p.gid, p.province_name, CASE WHEN - EXISTS(SELECT w.the_geom - FROM waterlines w - WHERE ST_Within(w.the_geom, p.the_geom) - AND ST_IsClosed(w.the_geom)) - THEN - ST_MakePolygon(ST_LineMerge(ST_Boundary(p.the_geom)), - ARRAY(SELECT w.the_geom - FROM waterlines w - WHERE ST_Within(w.the_geom, p.the_geom) - AND ST_IsClosed(w.the_geom))) - ELSE p.the_geom END As the_geom -FROM - provinces p; - - - - ST_Polygonize(geometry set) @@ -2656,15 +2561,6 @@ WHERE n*100.00/length < 1; - - ST_GeometryType - - - Return the geometry type of the ST_Geometry value. - - SQL-MM 3: 5.1.4 - - ST_GeomFromText diff --git a/doc/reference_new.xml b/doc/reference_new.xml index 5304b3ef8..aeb8772b0 100644 --- a/doc/reference_new.xml +++ b/doc/reference_new.xml @@ -580,6 +580,113 @@ SELECT userpoints.id, ST_MakeLine(startpoint, endpoint) As drawn_line + + + + ST_MakePolygon + + Creates a Polygon formed by the given shell. Input + geometries must be closed LINESTRINGS. + + + + + + geometry ST_MakePolygon + geometry linestring + + + + + geometry ST_MakePolygon + geometry outerlinestring + geometry[] interiorlinestrings + + + + + + Description + + Creates a Polygon formed by the given shell. Input + geometries must be closed LINESTRINGS. Comes in 2 variants. + Variant 1: takes one closed linestring. + Variant 2: Creates a Polygon formed by the given shell and array of + holes. You can construct a geometry array using ST_Accum or the PostgreSQL ARRAY[] and + ARRAY() constructs. Input geometries must be closed LINESTRINGS. + + This function will not accept a MULTILINESTRING. Use ST_LineMerge or ST_Dump to generate line strings. + + + + + + Examples: Single closed LINESTRING + +SELECT ST_MakePolygon(ST_GeomFromText('LINESTRING(75.15 29.53,77 29,77.6 29.5, 75.15 29.53)')); +--If linestring is not closed +--you can add the start point to close it +SELECT ST_MakePolygon(ST_AddPoint(foo.open_line, ST_StartPoint(foo.open_line))) +FROM ( +SELECT ST_GeomFromText('LINESTRING(75.15 29.53,77 29,77.6 29.5)') As open_line) As foo + + + + Examples: Outter shell with inner shells + + Build a donut with an ant hole + +SELECT ST_MakePolygon( + ST_ExteriorRing(ST_Buffer(foo.line,10)), + ARRAY[ST_Translate(foo.line,1,1), + ST_ExteriorRing(ST_Buffer(ST_MakePoint(20,20),1)) ] + ) +FROM + (SELECT ST_ExteriorRing(ST_Buffer(ST_MakePoint(10,10),10,10)) + As line ) + As foo; + + Build province boundaries with holes + representing lakes in the province from a set of + province polygons/multipolygons and water line strings + this is an example of using PostGIS ST_Accum + The use of CASE because feeding a null array into + ST_MakePolygon results in NULL + the use of left join to guarantee we get all provinces back even if they have no lakes + + SELECT p.gid, p.province_name, + CASE WHEN + ST_Accum(w.the_geom) IS NULL THEN p.the_geom + ELSE ST_MakePolygon(ST_LineMerge(ST_Boundary(p.the_geom)), ST_Accum(w.the_geom)) END + FROM + provinces p LEFT JOIN waterlines w + ON (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 array + + SELECT p.gid, p.province_name, CASE WHEN + EXISTS(SELECT w.the_geom + FROM waterlines w + WHERE ST_Within(w.the_geom, p.the_geom) + AND ST_IsClosed(w.the_geom)) + THEN + ST_MakePolygon(ST_LineMerge(ST_Boundary(p.the_geom)), + ARRAY(SELECT w.the_geom + FROM waterlines w + WHERE ST_Within(w.the_geom, p.the_geom) + AND ST_IsClosed(w.the_geom))) + ELSE p.the_geom END As the_geom + FROM + provinces p; + + + + See Also + , , , , + + @@ -676,6 +783,49 @@ SELECT userpoints.id, ST_MakeLine(startpoint, endpoint) As drawn_line (1 row) + + + + ST_GeometryType + Return the geometry type of the ST_Geometry value. + + + + + + text ST_GeometryType + geometry g1 + + + + + Description + + Returns the type of the geometry as a string. EG: 'ST_Linestring', 'ST_Polygon','ST_MultiPolygon' etc. This function differs from GeometryType(geometry) in the case of the string and ST in front that is returned, as well as the fact that it will not indicate whether the geometry is measured. + + + + + + + This method implements the SQL/MM specification: + SQL-MM 3: 5.1.4 + + + + Examples + + SELECT ST_GeometryType(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)')); + --result + ST_LineString + + + + See Also + + + + ST_NPoints