Re: GeoDjango question about US zipcode lookup and spatial query
> 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 -~--~~~~--~~--~--~---
Re: GeoDjango question about US zipcode lookup and spatial query
On Sat, Nov 29, 2008 at 12:24 PM, Justin Bronn <[EMAIL PROTECTED]> wrote: > > > I do have a few basic questions > > - on slide 37, there's a Zipcode model, how does one populate this model? > > Are we using fe_2007_us_zcta500.shp? If so, is there a program which > > converts the zipcode shape from the shape file? > > Yes, you use that shapefile. The script that loads the data is also > in the presentation, go to slide 68 (in the `LayerMapping` section). > 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 I followed the example and did: def test_zipcode(): zipcode_mapping = { 'code' : 'ZCTA5CE00', 'mpoly' : 'MULTIPOLYGON', } zipcode_shp = '/usr/local/share/census/fe_2007_us_zcta500.shp' lm = LayerMapping(Zipcode, zipcode_shp, zipcode_mapping) lm.save(verbose=True) and tried a few zipcode in Admin interface. I see several problems and want to make sure it's a data error rather than installation error: 1. There's no 08544 zipcode after the layer mapping. 08544 should point to Princeton NJ. 2. I do see 08540 and 08542. 08542 seems correct but 08540 shows North Pole?? 3. I also did a shp2pgsql dump with srid=4269 which seems the closest match of the prj file as compared to spatial_ref_sys in the pgsql db. shp2pgsql -s 4269 fe_2007_us_zcta500 zipcode > zipcode.sql and 08544 is not there. If so, it does look like the zipcode is incomplete even though the dataset is fairly recent and from census. Do you have recommendation on what maybe a better DataSource? > > > - on slide 41, there is an Address model, does GeoDjango provide > geocoding > > which converts it to (lat, lon) for spatial query? If not, does it mean > that > > one has to query Google/Yahoo/MSFT WebServices? > > No, GeoDjango does not provide geocoding services. Geopy [1] is a > popular Python geocoding interface. > 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? What do you recommend as the best practice? Thanks -Aaron > > Regards, > -Justin > > [1] http://code.google.com/p/geopy/ > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: GeoDjango question about US zipcode lookup and spatial query
> I do have a few basic questions > - on slide 37, there's a Zipcode model, how does one populate this model? > Are we using fe_2007_us_zcta500.shp? If so, is there a program which > converts the zipcode shape from the shape file? Yes, you use that shapefile. The script that loads the data is also in the presentation, go to slide 68 (in the `LayerMapping` section). > - on slide 41, there is an Address model, does GeoDjango provide geocoding > which converts it to (lat, lon) for spatial query? If not, does it mean that > one has to query Google/Yahoo/MSFT WebServices? No, GeoDjango does not provide geocoding services. Geopy [1] is a popular Python geocoding interface. Regards, -Justin [1] http://code.google.com/p/geopy/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
GeoDjango question about US zipcode lookup and spatial query
Hi all, I am checking out GeoDjango and going through the installation and presentation. I esp. like this one which is very well done http://geodjango.org/presentations/GeoDjango%20-%20A%20world-class%20Geographic%20Web%20Framework%20(DjangoCon%20-%20Sept.%206,%202008).pdf I do have a few basic questions - on slide 37, there's a Zipcode model, how does one populate this model? Are we using fe_2007_us_zcta500.shp? If so, is there a program which converts the zipcode shape from the shape file? - on slide 41, there is an Address model, does GeoDjango provide geocoding which converts it to (lat, lon) for spatial query? If not, does it mean that one has to query Google/Yahoo/MSFT WebServices? Thanks -Aaron --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---