[postgis-users] shp2pgsql: How are x,y-coordinates stored?

Bruce Rindahl rindahl at lrcwe.com
Wed Aug 9 08:40:37 PDT 2006


Your answer is right there.  I assumed you had a table of POINTs but you
have a table of MULTIPOLYGONs.  The table has one row consisting of a simple
polygon.  You can't ask for the X and Y of a point because there are 161
points in the polygon.  You have figured out how to get the coordinates as
text, the bounding box, summary, etc.  Now you need to keep looking at the
manual to use the other functions.  Do you really want the individual
points?? Try:
select X(pointN(ExteriorRing(GeometryN(the_geom,1)),1)) from
countryboundaries
and:
select Y(pointN(ExteriorRing(GeometryN(the_geom,1)),1)) from
countryboundaries

Change the ,1 above to ,2 ,3 ...,161 to get all the points.
Again get familiar with the manual to understand what is going on in the
queries.

Bruce Rindahl


-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of H.Lekin
Sent: Wednesday, August 09, 2006 8:55 AM
To: postgis-users at postgis.refractions.net
Subject: [postgis-users] shp2pgsql: How are x,y-coordinates stored?

> I simple terms the x,y coordinates are stored together in a big blob.
> Polylines and Polygons are stored in bigger blobs.  The secret to PostGIS
is
> the blobs have a very specific form and there are lots of functions to do
> what you want.
> To prove it run the SQL command 
> 
> SELECT X(the_geom), Y(the_geom) from yourtablename

gistest=> select X(the_geom), Y(the_geom) from countryboundaries;
ERROR:  Argument to X() must be a point
# Same applies to GRASS command.

gistest=> select AsText (the_geom) from countryboundaries;
---snip---
MULTIPOLYGON(((3.71071599999999 50.380975,...,3.71071599999999 50.380975)))
(18 Zeilen)
# There are coordinates!

gistest=> select gid, isvalid(the_geom) from countryboundaries;
 gid | isvalid
-----+---------
   1 | t
   2 | t
   3 | t
---snip---
  16 | t
  17 | t
  18 | t
(18 Zeilen)
# Description: Returns true if this geometry is valid.
# No idea what that is supposed to mean; at least things are valid.

gistest=> select Summary(the_geom) from countryboundaries;
---snip---
MultiPolygon[B] with 1 elements
  Polygon[] with 1 rings
   ring 0 has 161 points
(18 Zeilen)

gistest=> select extent(the_geom) from countryboundaries;
                                  extent
--------------------------------------------------------------------------
BOX(3.71071577072144 45.2058982849121,17.1880855560303 57.1254005432129)
(1 Zeile)

What's wrong with the way I try to access coordinates?
> 
> Where yourtablename is the name you specified.   You should get a table
with
> the x,y coordinates of your data.
> 
> The functions X() and Y() are PostGIS functions to get the x and y
> coordinates from a point stored in your table.  Apparently QGIS knows how
to
> do this already from your e-mail but GRASS does not.  There are lots of
GIS
> functions in PostGIS - that's why you were told to look at the
documentation
> since nobody knows exactly what you want to do.

By the way, I have to admit that I don't even know this myself [yet].
Basically, I want to find out what somebody can do with open source GIS
tools. This is done on a new Debian installation (couldn't compile
PostGIS on Cygwin; in this respect the manual is rather jokey). I am my
own PostgreSQL admin as well as I'm trying to understand the GRASS
philosophy, if there really is one.
Please be patient, if I ask unprecise, a little foolish questions. I
really appreciate any help.

>                                                   I don't know what GRASS
> needs to have to import the data so I can't help you there.

I get the same error in GRASS, i.e. Argument to X() must be a point.
> 
> Bruce Rindahl
Thanks a lot,
H.L.
_______________________________________________
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