Changes between Version 32 and Version 33 of GeoDjango
- Timestamp:
- Mar 11, 2007, 7:01:03 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GeoDjango
v32 v33 37 37 38 38 == Phase 1 == 39 Assume existing data and columns, and that the UOM given is same as backing data. 40 Support a custom manager (and queryset) to support lookups. 39 * Create Geometry-enabled fields and manager. Status: complete (not yet in SVN). 40 * Allow for Geometry-enabled queries. Status: complete (not yet in SVN). 41 * Here is an example of how the model API currently works (assume this example is in geo_app/models.py): 41 42 42 === GeoTypes ===43 GeoTypes 0.7 supports both psycopg1 and psycopg2. Upside is conversion from type params to SQL. Simplifies (avoids?) QuerySet modification. Maintainer of GeoTypes has been responsive as of Feb 26 2007 on the psycopg mailing list.44 Example code, where point and box are types from GeoTypes.OG*:45 43 {{{ 46 from django.db import models 47 from django.contrib.gis import db as gis_db 44 from django.contrib.gis.db import models 48 45 49 class School(meta.Model): 50 name = ... 51 objects = gis_db.Manager() 46 class District(models.Model): 47 name = models.CharField(maxlength=35) 48 num = models.IntegerField() 49 poly = models.MultiPolygonField() 52 50 53 Assume a location column has already been added to the DB, e.g. 54 select addgeometrycolumn('','schools_school','location',-1, 'POINT', 2); 51 objects = models.GeoManager() 55 52 56 Then this would work: 57 from django.contrib.gis.geometry import Point 58 x = Point(-95.36819458007812, 30.2184318620219) 59 School.objects.geo_near('location', point=x, radius=1.0) 53 class School(models.Model): 54 name = models.CharField(maxlength=35) 55 point = models.PointField() 60 56 61 This could construct a LinearRing approximating the circle around x 62 and issue something like: 63 64 poly = "POLYGON (...points from curve approximation...)" 65 _where.append(""" 66 where schools_school.location && %s and 67 within(schools_school.location, %s) 68 """) 69 _params.append(poly, poly) 57 objects = models.GeoManager() 70 58 }}} 71 59 72 === Geos === 73 I'm not sure how we can use GEOS without also doing something like GeoTypes down in the QuerySet. Ideas? 60 * Use the manage.py just like you normally would: 74 61 62 {{{ 63 $ python manage.py sqlall geo_app 64 BEGIN; 65 CREATE TABLE "geo_app_school" ( 66 "id" serial NOT NULL PRIMARY KEY, 67 "name" varchar(35) NOT NULL 68 ); 69 CREATE TABLE "geo_app_district" ( 70 "id" serial NOT NULL PRIMARY KEY, 71 "name" varchar(35) NOT NULL, 72 "num" integer NOT NULL 73 ); 74 SELECT AddGeometryColumn('geo_app_school', 'point', 4326, 'POINT', 2); 75 SELECT AddGeometryColumn('geo_app_district', 'poly', 4326, 'MULTIPOLYGON', 2); 76 COMMIT; 77 $ python manage.py syncdb geo_app 75 78 79 }}} 80 81 * PostGIS additions to the API may now be used: 82 83 {{{ 84 >>> from geo_app.models import District, School 85 >>> qs1 = District.objects.filter(poly__bbcontains='POINT(-95.362293 29.756539)') # Same as PostGIS '&&' operator 86 >>> qs2 = District.objects.filter(poly__intersects='POINT(-95.362293 29.756539)') # Same as PostGIS Intersects() (from GEOS) 87 88 }}} 76 89 77 90 == Phase 2 == 78 === Field Types === 79 * To allow update through ORM, new fieldtypes would be needed. 80 81 82 === GIS utilities === 83 wrapper for geos, have the ability to do something like 84 85 {{{ 86 from django.contrib.gis import area 87 area(bbox.geom) 88 }}} 91 * Add as much from the PostGIS as possible. 92 * Add geometry-enabled routines to the fields that call directly on GEOS routines -- like area(), centroid(), etc. 93 * Contemplate a JS framework for mapping. I know Django community is against including any type of JS/AJAX framework, but having a way to generate maps would be a great addition. Also, any type of framework would be limited to the contrib package only. 89 94 90 95 = Installation =