How to import Lat/Long data into PostgreSQL
PostgreSQL / Django / newbie here.
I've got a bunch of JSON data with venues and lat/long information, and I'm looking to import it into my database. So far I've fenagled a script to format my JSON into SQL statements, so I can import them with a slew of INSERT statements.
But my 'location' fi开发者_高级运维eld (a PointField) is giving me grief when I try to use ST_PointFromText('POINT(lon lat)') syntax. Specifically:
ERROR: new row for relation "finder_venue" violates check constraint "enforce_srid_location"
So how do I generate a proper SRID?
Or, given Django's ease, I can't help but feel like I'm committing programmatic heresy here. Can someone point me in a more intelligent direction?
Thanks,
Jon
If you want to set the SRID in PostGIS, you can do this:
ST_SetSRID(ST_PointFromText('POINT(-122 37)'), 4326)
(4326 is the SRID here.)
For GeoDjango, your model will be defined like this:
from django.contrib.gis.db import models
class Thing(models.Model):
# ...
location = models.PointField(srid=4326)
objects = models.GeoManager()
If you're actually using 4326, you can leave it out, as that's the default.
Then, you'll set the location
of your model instances so:
from django.contrib.gis.geos import Point
some_thing.location = Point(-122, 37)
精彩评论