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.

Reply via email to