[postgis-users] Why doesn't startpoint work? (and X() for that matter)

strk at refractions.net strk at refractions.net
Tue Dec 28 01:16:50 PST 2004

On Mon, Dec 27, 2004 at 05:14:51PM -0700, Ethan Alpert wrote:
> >From the docs:
> X(geometry)
> Find and return the X coordinate of the first point in the geometry.
> Return NULL if there is no point in the geometry.
> StartPoint(geometry)
> Returns the first point of the geometry as a point.
> spatialdb=> select startpoint(the_geom),X(the_geom),the_geom from snaps
> where catalogid ='101001000379CE01';
> -[ RECORD 1]
> startpoint | 
> x          | 
> the_geom   | SRID=4326;POLYGON((73.2565444444444
> 45.141725,73.4717277777778 45.1421555555556,73.4707527777778
> 44.9756666666667,73.257175 44.975625,73.2565444444444 45.141725))
> So what gives?! Why do these return NULL? Is there a better reference
> doc somewhere?

These are OGC functions. StartPoint/EndPoint should only work with 
LineString inputs (postgis actually extends this looking for the
first LineString in a complex geometry, but that 'extension' should
probably be dropped for OGC *strictness*). X/Y/Z/M should only
work with Point geometries.

Your query should be:

=> SELECT StartPoint(OuterRing(the_geom)), X(StartPoint(OuterRing(the_geom)))
   FROM snaps WHERE catalogid = '101001000379CE01';

> While we're on the subject how can I convert between geometry types? I'd
> like to turn some polygons into lines.

There is no function available for this. You should script it
with calls to ExteriorRing(), NumInteriorRing() and InteriorRingN().


> -e
> _______________________________________________
> 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