I am having trouble converting latitude and longitude. Both are in double precision in the table. So, I am doing this
UPDATE my_table SET geom = ST_PointFromText('POINT(' || longitude ||' '|| latitude ||')', 4326) But, when I do this SELECT ST_PointFromText(geom ) FROM my_table I am getting an error ERROR: parse error - invalid geometry HINT: "0101000020E6100000D" <-- parse error at position 19 within geometry CONTEXT: SQL function "st_pointfromtext" statement 1 thanks On Apr 26, 9:57 am, Jani Tiainen <rede...@gmail.com> wrote: > 25.4.2012 19:17, vishy kirjoitti: > > > Hi, > > > I need to do spatial queries like find places within 5 miles of a > > location given in latitude and longitude. So, I am thinking of > > exploring PostGIS and GeoDjango. I have installed both. Now, I already > > have a database which has a table for places with latitude and > > longitude. Can I enable this db to use postgis and add column to this > > table? Or, do I have to create a separate spatial db, create a table > > with a column of geometry type and import data into that table (from > > places table).? If I can use the existing database, how do I enable it > > to use PostGIS? > > It depends on your environment but basic workflow is same is in *nix > instructions. And it's not even hard. : > > createdb yourdatabase > createlang plpgsql yourdatabase > psql -d yourdatabase -f postgis.sql > psql -d yourdatabase -f postgis_comments.sql > psql -d yourdatabase -f spatial_ref_sys.sql > > Of course in your case you can skip creation of database. Just create > language and install postgis stuff. > > After that you need to make sure that your database user has access to > geometry_columns and spatial_ref_sys tables. > > Add new column (For PostGIS 1.5.x, newer postgis has simpler alternative > syntax): > > SELECT AddGeometryColumn('my_table', 'my_geom', 4326, 'POINT', 2) > > And after that just update new geometry column: > update my_table set my_geom = GeomFromText('POINT(' + x + ' ' + y +')', > 4326) > > And don't forget to commit. If you have lot's of geometries (1M+) you > probably want to drop out spatial index and recreate it afterwards. > Otherwise building index takes just long time. > > -- > Jani Tiainen > > - Well planned is half done and a half done has been sufficient before... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.