[postgis-users] Points in a geometry.

Kevin Neufeld kneufeld at refractions.net
Wed Feb 4 09:25:18 PST 2009


Hi Paul,

Yes, there is a way.

ST_PointN will extract the Nth point from a LINESTRING.  When used with generate_series, you can extract all POINTs from 
a LINESTRING.
(http://postgis.refractions.net/documentation/manual-svn/ST_PointN.html)
(http://www.postgresql.org/docs/8.3/static/functions-srf.html)
(http://postgis.refractions.net/documentation/manual-svn/ch07.html#Geometry_Accessors)

ST_GeometryN will extract the Nth geometry in a MULTILINESTRING.  Again, use generate_series to extract all LINESTRINGs 
from a MULTILINESTRING.

ST_Boundary will extract the boundary from a MULTIPOLYGON as a MULTILINESTRING.

So, put together, to extract all points from a table with MULTILINESTRINGs:
SELECT
    ST_PointN(
       lines,
       generate_series(1, ST_NPoints(lines)))
FROM (
    SELECT
       ST_GeometryN(
          ST_Boundary(the_geom),
          generate_series(1, ST_NumGeometries(ST_Boundary(the_geom)))
       ) AS lines
    FROM my_multipolygon_table
    ) AS foo;


You should note that there is no ST_Dump equivalent for points yet (ST_Dump expands MULTI* geometries extremely 
quickly).  Using generate_series is all we can do at the moment for extracting Points.  If your geometries have more 
than a few thousand points, you'll notice a significant reduction in performance.  This is something we have on our TODO 
list for future PostGIS enhancements.

On a side Paul, when creating a new topic, don't reply to an old thread or your question will get buried in someone 
else's topic.  Rather, create a new thread.

Hope that helps,
Kevin

Moen, Paul T. wrote:
> Is there an easy way to get all the points from a geometry?  For 
> instance, I have a multipolygon and I would like to get the distance 
> from a point to each point that makes up the multipolygon.  I know how 
> to do it by parsing the wkt, but was wondering if there was a better way 
> to do it using Postgis and SQL.
> 
> Thanks,
> 
> Paul
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users



More information about the postgis-users mailing list