94 | | * Because these map to the separate OGR routines [http://www.gdal.org/ogr/ogr__api_8h.html#59a5b3f954b11cfbf6e78807c28d6090 OGR_G_Transform] and [http://www.gdal.org/ogr/ogr__api_8h.html#43af4c2127cea0a5059692a62c0feb63 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 [http://www.gdal.org/ogr/ogr__api_8h.html#59a5b3f954b11cfbf6e78807c28d6090 OGR_G_Transform] and [http://www.gdal.org/ogr/ogr__api_8h.html#43af4c2127cea0a5059692a62c0feb63 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: |
| 97 | {{{ |
| 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>] |
| 104 | }}} |