Feasibility of postgis fields?

5 views
Skip to first unread message

nick

unread,
Jun 15, 2006, 4:11:34 AM6/15/06
to Django users
Hi - as a person investigating django for managing metadata that will
also have a spatial/gis component (lat/lon bounding boxes), would the
reccommended approach be to create a new field for use in my models?
Admittedly this would be specific to the postgres+postgis backend.

I'd be looking to implement a basic a polygon datatype and at runtime
allowing for queries to search for intersections of these with
user-defined points. The postgres+postgis && operator acheives this in
simple sql:

SELECT
ID, NAME
FROM ROADS_GEOM
WHERE
GEOM && GeomFromText('POLYGON((191232 243117,191232 243119,191234
243117,191232 243117))',-1);

See http://postgis.refractions.net/docs/

Has anyone done this already and and I likely to run into any brick
walls from the framework if I attempt to implement additional backend
functionality through model fields?

An aside, there seems to be no implementation of interfaces for the
existing field types. Is this deliberate? Maybe I'm barking up the
wrong tree if they're not meant to be extended.

Jeroen Ruigrok van der Werven

unread,
Jun 15, 2006, 4:51:52 AM6/15/06
to django...@googlegroups.com
Hi Nick,

On 6/15/06, nick <bower...@gmail.com> wrote:
> Hi - as a person investigating django for managing metadata that will
> also have a spatial/gis component (lat/lon bounding boxes), would the
> reccommended approach be to create a new field for use in my models?
> Admittedly this would be specific to the postgres+postgis backend.

About custom fields I cannot tell you anything, but I recently helped
the developer(s) of GeoTypes to release 0.6.0, which is also
installable through CheeseShop/easy_install. I think this could be
helpful providing you with the OpenGIS/PostGIS geometry types at
least.

See http://cheeseshop.python.org/pypi/GeoTypes/

--
Jeroen Ruigrok van der Werven

Adrian Holovaty

unread,
Jun 15, 2006, 11:17:13 AM6/15/06
to django...@googlegroups.com
On 6/15/06, nick <bower...@gmail.com> wrote:
> Hi - as a person investigating django for managing metadata that will
> also have a spatial/gis component (lat/lon bounding boxes), would the
> reccommended approach be to create a new field for use in my models?
> Admittedly this would be specific to the postgres+postgis backend.
>
> I'd be looking to implement a basic a polygon datatype and at runtime
> allowing for queries to search for intersections of these with
> user-defined points. The postgres+postgis && operator acheives this in
> simple sql:
>
> SELECT
> ID, NAME
> FROM ROADS_GEOM
> WHERE
> GEOM && GeomFromText('POLYGON((191232 243117,191232 243119,191234
> 243117,191232 243117))',-1);

Hey Nick,

I've been using Django successfully with PostgreSQL/PostGIS for more
than a year on http://www.chicagocrime.org/ . What I do is
deliberately *exclude* the "GEOM" field from being defined in the
model (because it doesn't yet have a Python/Django field class), and I
use custom SQL statements in model methods to do the queries I want to
do. Django doesn't really care if the database defines columns that
aren't in the model, as long as you don't try to insert/change into
that undefined field with the Django database API -- so I'm exploiting
that.

So, yeah, it's totally possible and easy to do. I'd be happy to post
sample model code if you're interested.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com

nick

unread,
Jun 15, 2006, 9:51:48 PM6/15/06
to Django users
Hi thanks for the replies - I'm surprised this is the only way to do
it as using the model api would seem neater. Have you encountered many
problems separating out the geom fields like this (eg - not being
searchable in admin / whatever)?

Yes I'd be interested in an example of how custom sql is implemented
within the model code thanks.

So how are you injecting the data into the database? Sounds like you'd
need to do it in 2 steps using this approach - 1) create the model
instance and commit, then 2) execute a method on the model from your
dataloader to manually update the geom field afterwards with custom
sql.

Thanks, Nick

Reply all
Reply to author
Forward
0 new messages