Changes between Version 104 and Version 105 of GeoDjango

12/08/2007 09:53:50 PM (13 years ago)

Updated FAQ.


  • GeoDjango

    v104 v105  
    9292   * Geographic queries require {{{GeoManager}}}, even if the model does not have a geographic field itself (in the case of a foreign key to a geo-field).  The reply in the discussion gives detail into why.
    9393 * '''Q:''' Why are the OGRGeometry methods {{{transform}}} and {{{transform_to}}} separate?
    94    * Because these map to the separate OGR routines [ OGR_G_Transform] and [ OGR_G_TransformTo].  Specifically, the {{{transform}}} routine takes a !CoordTransform object as a parameter, whereas the {{{transform_to}}} routine takes a !SpatialReference object.  The {{{transform_to}}} "function requires internal creation and initialization of [a CoordTransform] object [and] it is significantly more expensive to use this function to transform many geometries than it is to create the [CoordTransform object] in advance, and call transform() with that transformation. This function exists primarily for convenience when only transforming a single geometry."
     94   * They are no longer separate, as `transform` now accepts `CoordTransform` and `SpatialReference` objects, as well as string WKT and integer SRID values (`transform` checks the input type and dispatches to the correct routine).  The former reason for the separation was that each mapped to the separate OGR routines [ OGR_G_Transform] and [ OGR_G_TransformTo].  For better performance use `CoordTransform` objects when you will be performing the same transformation repeatedly.
     95 * '''Q:''' Why don't `Q` objects work?
     96   * `Q` object functionality is for use with models that use `QuerySet`.  Because !GeoDjango models use `GeoQuerySet`, use the `GeoQ` object instead:
     98>>> from django.contrib.gis.db.models import GeoQ
     99>>> from geoapp.models import City, Country, State # See django.contrib.gis.tests.geoapp
     100>>> tx = Country.objects.get(name='Texas')
     101>>> ks = State.objects.get(name='Kansas')
     102>>> City.objects.filter(GeoQ(point__within=tx.mpoly) | GeoQ(point__within=ks.poly))
     103[<City: Houston>, <City: Dallas>, <City: Lawrence>]
    96106== Example ==
Back to Top