Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Django 1.3, PostGIS 2.0 , Postgresql 9.0 and GeoDjango.

I had a database with a table for places. This table had latitude and longitude for places in the US. I enabled this database with PostGIS. I added PointField to my model. Then, updated this table with

SELECT AddGeometryColumn('table', 'poly', 4326, 'POINT', 2)

CREATE INDEX "table_poly_id" ON "table" USING GIST ( "poly" )

UPDATE table
SET poly = ST_PointFromText('POINT(' || longitude ||' '|| latitude ||')', 4326)

Now, I want to make query to find places within 5 miles of given latitude and longitude of a user's location. So, I did this

ref_pnt = fromstr("POINT(%s %s)" % ("-87.627778", "41.881944"))
records = Table.objects.filter(poly__distance_lte = (ref_pnt,D(mi=5)))

But, I am getting an error

DatabaseError: Coordinate values are out of range [-180 -90, 180 90] for GEOGRAHY type

I also get an error when I do this

SELECT ST_PointFromText(poly) FROM table 

ERROR:  parse error - invalid geometry
HINT:  "0101000020E61000007E" <-- parse error at position 20 within geometry
CONTEXT:  SQL function "st_pointfromtext" statement 1

What could be the problem?

share|improve this question

I had a similar problem, in my case, I was storing coordinates inverted.

In WGS84 and postgis, the order in point is longitude, latitude.

In Django, the point object is like: Point(x=longitude, y=latitude)

share|improve this answer

i think the problem is about projection system. my advice is that connect your postgis table to qgis. and then open your table and reproject it to WGS84.


SELECT placename, st_astext(geom), st_x(geom) AS x, st_y(geom) AS y
FROM Points           
        st_x(geom) < -180 OR
        st_x(geom) > 180 OR
        st_y(geom) < -90 OR
        st_y(geom) > 90;

this sql code checks if your geom objects greater than 180 and 90...

i hope it helps you...

share|improve this answer
How to solve the projection system problem? I opened the table in qgis and set to WGS84. But how to reproject? – carlsen Apr 26 '12 at 8:45
for qgis reprojectioning. after this save your file and then use SPIT tool - Shapefile to PostGIS Import Tool, overwrite your old file... – Aragon Apr 26 '12 at 10:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.