> Thanks Justin, I was using MySQL and it looks like I do need Postgres to get > the best gis support. > Do people normally switch their DB backend entirely or do they start a new > project for geo stuff and connect the main site to this as a separate > backend? I can see the pros and cons of each approach. Just want to hear > about people's experience >
Prior to writing geographic web apps I was a heavy MySQL user. While I initially learned Postgres to just use PostGIS, I've personally found it to be more robust, stable, and an overall better database than MySQL. Thus, I ended up switching my backend entirely -- I can't speak for others, but I've heard of GeoDjango users switching after finding MySQL's GIS offerings to be inadequate. However, there's nothing to stop you from having a PostGIS site that serves up geographic content via a RESTful interface to a MySQL- powered app. > 1. There's no 08544 zipcode after the layer mapping. 08544 should point to > Princeton NJ. The data in the shapefile is from the 2000 census -- thus, it may not include recent ZIP code additions. I believer there are commercial providers of up-to-date datasets, but I don't know any off-hand. > 2. I do see 08540 and 08542. 08542 seems correct but 08540 shows North > Pole?? Both 08540 and 08542 appear properly over Princeton, NJ in my admin. > Let say I want to do something similar to your example of HoustonCrimeMap, > and I use Geopy to perform the geocoding to get back the (lat, lon) for each > crime event location and I also want to show the events within a certain > radius R from a point P. Do you store the lat lon as a Point for each event > and construct a polygon of a circle(P,R) and check if the event point is > contained inside the polygon? For HCM, each crime has a FK to an address model, which in turn has the PointField. There's two ways you can do this: 1. Use the existing distance lookup API to find the events: >>> from django.contrib.gis.measure import D >>> from django.contrib.gis.geos import Point >>> P = Point(lon, lat, srid=4326) # X, Y (lon, lat), NOT (lat, lon) >>> qs = Crime.objects.filter(address__point__distance_lte=(P, D (km=50))) Assuming the PointField is using 4326, this is OK and GeoDjango will use the the PostGIS `ST_distance_sphere` routine in its query to find all crimes within 50km of the point `P`. However, for geometry fields other than PointField that use a geographic coordinate system (e.g., those that use angular units of latitude/longitude like WGS84 (srid=4326)) then this query will not work because PostGIS does not support spherical distance queries on non-point geometries. 2. Create a buffer from point P with radius R >>> from django.contrib.gis.geos import Point >>> P = Point(-74.65613, 40.34380, srid=4326) >>> P.transform(2824) >>> buf = P.buffer(2000.0) >>> qs = Crime.objects.filter(address__point__intersects=buf) Here I'm creating a point centered on Princeton in WGS84. Next I transform it to a projected coordinate system for New Jersey (srid=2824) [1] that has its units in meters. Finally, I create a 2000 meter buffer around that point and use it to query the database (the buffer will be implicitly transformed at the SQL level by GeoDjango). Regards, -Justin [1] http://spatialreference.org/ref/epsg/2824/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---