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 GEOGRAPHY 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?

2 Answers 2


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)


I think the problem is about projection system. My advice is: 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 are greater than 180 and 90...

  • How to solve the projection system problem? I opened the table in qgis and set to WGS84. But how to reproject?
    – carlsen
    Apr 26, 2012 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, 2012 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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