def create(self, dest_srs=4326, source_srs=None): from ambry.geo.sfschema import TableShapefile if self.identity.table: tsf = TableShapefile(self.bundle, self._db_class.make_path(self), self.identity.table, dest_srs = dest_srs, source_srs = source_srs ) tsf.close() self.add_tables(self.data.get('tables',None))
def test_sfschema(self): from ambry.geo.sfschema import TableShapefile from ambry.geo.analysisarea import get_analysis_area _, communities = self.bundle.library.dep('communities') csrs = communities.get_srs() gp = self.bundle.partitions.new_geo_partition(table='geot2') with gp.database.inserter(source_srs=csrs) as ins: for row in communities.query(""" SELECT *, X(Transform(Centroid(geometry), 4326)) AS lon, Y(Transform(Centroid(geometry), 4326)) as lat, AsText(geometry) as wkt, AsBinary(geometry) as wkb FROM communities"""): r = {'name':row['cpname'], 'lat': row['lat'], 'lon': row['lon'], 'wkt': row['wkt']} ins.insert(r) return aa = get_analysis_area(self.bundle.library, geoid = 'CG0666000') path1 = '/tmp/geot1.kml' if os.path.exists(path1): os.remove(path1) sfs1 = TableShapefile(self.bundle, path1, 'geot1' ) path2 = '/tmp/geot2.kml' if os.path.exists(path2): os.remove(path2) sfs2 = TableShapefile(self.bundle, path2, 'geot2', source_srs=communities.get_srs()) print sfs1.type, sfs2.type for row in communities.query(""" SELECT *, X(Transform(Centroid(geometry), 4326)) AS lon, Y(Transform(Centroid(geometry), 4326)) as lat, AsText(geometry) as wkt, AsBinary(geometry) as wkb FROM communities"""): sfs1.add_feature( {'name':row['cpname'], 'lat': row['lat'], 'lon': row['lon'], 'wkt': row['wkt']}) sfs2.add_feature( {'name':row['cpname'], 'lat': row['lat'], 'lon': row['lon'], 'wkt': row['wkt']}) sfs1.close() sfs2.close()
def test_sfschema(self): from ambry.geo.sfschema import TableShapefile from old.analysisarea import get_analysis_area _, communities = self.bundle.library.dep('communities') csrs = communities.get_srs() gp = self.bundle.partitions.new_geo_partition(table='geot2') with gp.database.inserter(source_srs=csrs) as ins: for row in communities.query(""" SELECT *, X(Transform(Centroid(geometry), 4326)) AS lon, Y(Transform(Centroid(geometry), 4326)) as lat, AsText(geometry) as wkt, AsBinary(geometry) as wkb FROM communities"""): r = {'name':row['cpname'], 'lat': row['lat'], 'lon': row['lon'], 'wkt': row['wkt']} ins.insert(r) return aa = get_analysis_area(self.bundle.library, geoid = 'CG0666000') path1 = '/tmp/geot1.kml' if os.path.exists(path1): os.remove(path1) sfs1 = TableShapefile(self.bundle, path1, 'geot1' ) path2 = '/tmp/geot2.kml' if os.path.exists(path2): os.remove(path2) sfs2 = TableShapefile(self.bundle, path2, 'geot2', source_srs=communities.get_srs()) print sfs1.type, sfs2.type for row in communities.query(""" SELECT *, X(Transform(Centroid(geometry), 4326)) AS lon, Y(Transform(Centroid(geometry), 4326)) as lat, AsText(geometry) as wkt, AsBinary(geometry) as wkb FROM communities"""): sfs1.add_feature( {'name':row['cpname'], 'lat': row['lat'], 'lon': row['lon'], 'wkt': row['wkt']}) sfs2.add_feature( {'name':row['cpname'], 'lat': row['lat'], 'lon': row['lon'], 'wkt': row['wkt']}) sfs1.close() sfs2.close()