def reproject(self, prj, name=None, chunk=1000): """ Reprojects a layer. *prj* is the destination :class:`Projection <geoscript.proj.Projection>` *name* is the optional name as a ``str`` to assign to the resulting reprojected layer. This method returns a newly reprojected layer. The new layer is create within the containing workspace of the original layer. >>> from geoscript import geom >>> l = Layer() >>> l.proj = 'epsg:4326' >>> l.add([geom.Point(-111, 45.7)]) >>> >>> l2 = l.reproject('epsg:26912') >>> l2.proj.id 'EPSG:26912' >>> [f.geom.round() for f in l2.features()] [POINT (500000 5060716)] """ prj = proj.Projection(prj) name = name or Layer._newname() # reproject the schema rschema = self.schema.reproject(prj, name) # create the reprojected layer rlayer = self.workspace.create(schema=rschema) # create a query specifying that feautres should be reprojected q = DefaultQuery(self.name, Filter.PASS._filter) if self.proj: q.coordinateSystem = self.proj._crs q.coordinateSystemReproject = prj._crs # loop through features and add to new reprojeced layer fit = self._source.getFeatures(q).features() try: while True: features = readFeatures(fit, self._source.getSchema(), chunk) if features.isEmpty(): break rlayer._source.addFeatures(features) finally: fit.close() return rlayer
def reproject(self, prj, name=None): """ Reprojects a layer. *prj* is the destination :class:`Projection <geoscript.proj.Projection>` *name* is the optional name as a ``str`` to assign to the resulting reprojected layer. This method returns a newly reprojected layer. The new layer is create within the containing workspace of the original layer. >>> from geoscript import geom >>> l = Layer() >>> l.proj = 'epsg:4326' >>> l.add([geom.Point(-111, 45.7)]) >>> >>> l2 = l.reproject('epsg:26912') >>> l2.proj.id 'EPSG:26912' >>> [f.geom for f in l2.features()] [POINT (499999.42501775385 5060716.092032814)] """ prj = proj.Projection(prj) name = name or Layer._newname() # reproject the schema rschema = self.schema.reproject(prj, name) # create the reprojected layer rlayer = self.workspace.create(schema=rschema) # create a query specifying that feautres should be reproje`cted q = DefaultQuery(self.name, Filter.PASS._filter) if self.proj: q.coordinateSystem = self.proj._crs q.coordinateSystemReproject = prj._crs fc = self._source.getFeatures(q) i = fc.features() # loop through features and add to new reprojeced layer while i.hasNext(): f = feature.Feature(schema=rschema, f=i.next()) rlayer.add(f) fc.close(i) return rlayer