Unix Technical Forum

beginner postgis question lat/lon

This is a discussion on beginner postgis question lat/lon within the Pgsql General forums, part of the PostgreSQL category; --> Hi, This may seem like a very simple question...it is...but I can't find documentation on it to help. I've ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 11:21 PM
shadrack
 
Posts: n/a
Default beginner postgis question lat/lon

Hi,
This may seem like a very simple question...it is...but I can't find
documentation on it to help. I've seen some posts about lat/long but
none that give simple solutions on how to insert lat/long in tables.
I'm a new user to postgis...I've been using mysql for a while but
needed the spatial functions so just recently downloaded postgresql/
postgis.
How do I create a simple table with several linestrings that have
coordinates in latitude/longitude?
Eventually, I'd like to create polygons with coordinates in lat/long
and see if they intersect various linestrings, but I'm trying to start
out simple.
Here's what I've done so far...

postgis=# \d routes_geom;
Table "public.routes_geom"
Column | Type | Modifiers
--------+-----------------------+-----------
id | integer |
name | character varying(25) |
geom | geometry |
Check constraints:
"enforce_dims_geom" CHECK (ndims(geom) = 2)
"enforce_geotype_geom" CHECK (geometrytype(geom) =
'LINESTRING'::text OR geom IS NULL)
"enforce_srid_geom" CHECK (srid(geom) = 4326)
postgis=# insert into routes_geom values(1, 'J084',
GeomFromText('LINESTRING(38.20 -121.00, 38.20, -118.00)', 4326));

I receive this error:
ERROR: parse error - invalid geometry
CONTEXT: SQL function "geomfromtext" statement 1

Do you have a good way to input lat/lon and do spatial relationships
using lat/long coords?
Thanks for any help,
Shad
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 11:21 PM
Martijn van Oosterhout
 
Posts: n/a
Default Re: beginner postgis question lat/lon

On Wed, Feb 27, 2008 at 04:59:07PM -0800, shadrack wrote:
> postgis=# insert into routes_geom values(1, 'J084',
> GeomFromText('LINESTRING(38.20 -121.00, 38.20, -118.00)', 4326));
>
> I receive this error:
> ERROR: parse error - invalid geometry
> CONTEXT: SQL function "geomfromtext" statement 1


You have an extraneous comma after the 38.20.

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> Those who make peaceful revolution impossible will make violent revolution inevitable.
> -- John F Kennedy


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFHxsojIB7bNG8LQkwRAnh5AJ42nRydE7g7XD2uMljLWu/GkCTQdACeJLii
37UIZMnkkMxlDTcG+qNZ1SA=
=1snk
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 11:21 PM
Michael Fuhr
 
Posts: n/a
Default Re: beginner postgis question lat/lon

On Wed, Feb 27, 2008 at 04:59:07PM -0800, shadrack wrote:
> This may seem like a very simple question...it is...but I can't find
> documentation on it to help. I've seen some posts about lat/long but
> none that give simple solutions on how to insert lat/long in tables.


See the PostGIS documentation, in particular Chapter 4 "Using PostGIS":

http://postgis.refractions.net/docs/ch04.html

(The site isn't responding right now; hopefully it'll be available
soon.)

> postgis=# insert into routes_geom values(1, 'J084',
> GeomFromText('LINESTRING(38.20 -121.00, 38.20, -118.00)', 4326));
>
> I receive this error:
> ERROR: parse error - invalid geometry
> CONTEXT: SQL function "geomfromtext" statement 1


There are two problems with the geometry string: the syntax error is
due an extra comma in the second pair of coordinates, and coordinates
should be (X Y) therefore (lon lat) instead of (lat lon). Try this:

insert into routes_geom values(1, 'J084', GeomFromText('LINESTRING(-121.00 38.20, -118.00 38.20)', 4326));

You might wish to subscribe to the postgis-users mailing list if you
have additional questions.

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 11:21 PM
shadrack
 
Posts: n/a
Default Re: beginner postgis question lat/lon

Thanks for the help! Stupid error,
Shad

On Feb 28, 7:04*am, m...@fuhr.org (Michael Fuhr) wrote:
> On Wed, Feb 27, 2008 at 04:59:07PM -0800, shadrack wrote:
> > This may seem like a very simple question...it is...but I can't find
> > documentation on it to help. I've seen some posts about lat/long but
> > none that give simple solutions on how to insert lat/long in tables.

>
> See the PostGIS documentation, in particular Chapter 4 "Using PostGIS":
>
> http://postgis.refractions.net/docs/ch04.html
>
> (The site isn't responding right now; hopefully it'll be available
> soon.)
>
> > postgis=# insert into routes_geom values(1, 'J084',
> > GeomFromText('LINESTRING(38.20 -121.00, 38.20, -118.00)', 4326));

>
> > I receive this error:
> > ERROR: *parse error - invalid geometry
> > CONTEXT: *SQL function "geomfromtext" statement 1

>
> There are two problems with the geometry string: the syntax error is
> due an extra comma in the second pair of coordinates, and coordinates
> should be (X Y) therefore (lon lat) instead of (lat lon). *Try this:
>
> insert into routes_geom values(1, 'J084', GeomFromText('LINESTRING(-121.0038.20, -118.00 38.20)', 4326));
>
> You might wish to subscribe to the postgis-users mailing list if you
> have additional questions.
>
> --
> Michael Fuhr
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> * * * * * * * *http://www.postgresql.org/docs/faq


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:56 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com