GeometryField.geography = True Syntax Help GIS Model

184 views
Skip to first unread message

JJ Zolper

unread,
Oct 20, 2012, 1:22:32 PM10/20/12
to django...@googlegroups.com
Hello everyone,

So I've decided for my GeoDjango application I want WGS84 along with a geography database column, rather than geometry.

I was reading here:


GeometryField.geography

If set to True, this option will create a database column of type geography, rather than geometry. Please refer to the geography type section below for more details.


that to set up a new column as geography I had to set GeometryField.geography = True.

I am unsure of the syntax of how to do this? There was no example given. Or where to properly place this line?

Here is the model.py file I am working on. If you could tell me where to fit this in that would be great?


from django.contrib.gis.db import models

class Artist(models.Model):
    name = models.CharField(max_length=30)
    genre = models.CharField(max_length=30)
    city = models.CharField(max_length=60)
    state = models.CharField(max_length=30)
    country = models.CharField(max_length=50)
    website = models.URLField()
    objects = models.GeoManager()

    def __unicode__(self):
       return self.name



Thanks so much,

JJ

JJ Zolper

unread,
Nov 2, 2012, 9:30:00 PM11/2/12
to django...@googlegroups.com
Wait so does anyone know how to do this?

I posted this a long time ago.

How do I define a geography field? I need a geography column so I can perform geographic queries on it and the documentation doesn't give me a definitive way on how to do it.

Would it be like:

city = models.CharField(max_length=50, GeometryField.geography = true)

???

Christiano Anderson

unread,
Nov 2, 2012, 10:14:57 PM11/2/12
to django...@googlegroups.com
First of all, you have to create a geo database. Postgis (a PostgreSQL extension) is the best choice. 

After that, you have to define some geography fields and import your data, shape files (shp), etc. 

GeoDjango Tutorial provides all the steps to get it done. 


If you are not familiar with geo concepts, I recommend to take a look at http://geodjango.org/presentations/

Hope that helps you




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/tWBJBDuXZzYJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Christiano Anderson | http://christiano.me/
http://twitter.com/dump

JJ Zolper

unread,
Nov 3, 2012, 2:24:32 PM11/3/12
to django...@googlegroups.com
Thanks for the reply.

I actually already have PostgreSQL.

So my question was pretty direct, or so I thought.

I'll try and spell this out again. So if I want to create a column in my database with type "geography" is this the syntax:

mpoly = models.MultiPolygonField(geography=true)

I cannot find an single example where we specify that we want the geography type to be used instead of using geometries.

All I need to know is if that is right? Is it a capitalized "true" so "TRUE" ?

Thanks so much,

JJ
Message has been deleted

si.a...@gmail.com

unread,
Apr 8, 2014, 7:26:21 PM4/8/14
to django...@googlegroups.com
Hope you got to the bottom of this, and yes I thought your original question was pretty direct.

If you haven't worked it out already and are still trying to get this working (or if anyone else stumbles across this), then essentially yes you would pass in geography=True, just as you would specify max_length=30 or any other field property.  The documentation suggests this only works with SRID 4326, so you need srid=4326 on your field as well.
Reply all
Reply to author
Forward
0 new messages