Anonymous avatar Anonymous committed a0ddfa7

Apply patch from hobu for faster trasforms - closes issue #7

Comments (0)

Files changed (1)

shapes/views/export.py

 from django.http import HttpResponse
 from django.contrib.gis.db.models.fields import GeometryField
 from django.contrib.gis.gdal.libgdal import lgdal as ogr
-from django.contrib.gis.gdal import Driver, OGRGeometry, OGRGeomType, SpatialReference, check_err 
+from django.contrib.gis.gdal import Driver, OGRGeometry, OGRGeomType, SpatialReference, check_err, sCoordTransform
 
 # todo use: qs.query._geo_field()
 # todo: support multiple querysets == multiple shapefiles
         
         # If true we're going to reproject later on 
         if self.proj_transform:
-            srs = SpatialReference(self.proj_transform)
+            out_srs = SpatialReference(self.proj_transform)
+        else:
+            out_srs = None
+        
+        if out_srs:
+            ct = CoordTransform(srs, out_srs)
         
         # Creating the layer
         layer = ogr.OGR_DS_CreateLayer(ds,os.path.basename(tmp.name), srs._ptr, ogr_type, None)
             # to match the shapefiles projection 'to-be'
             
             if geom:
-                if self.proj_transform:
-                    geom.transform(self.proj_transform)
                 ogr_geom = OGRGeometry(geom.wkt,srs)
+                if out_srs:
+                    ogr_geom.transform(ct)
                 # create the geometry
                 check_err(ogr.OGR_F_SetGeometry(feat, ogr_geom._ptr))
             else:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.