def prepareSqlite(out,featureClass,fileType,includeGeometry): [shp,shpType]=getShp(featureClass) if shpType == "point": gType = 1 elif shpType == "multipoint": gType = 4 elif shpType == "polyline": gType = 5 elif shpType == "polygon": gType = 6 fields=listFields(featureClass) fieldNames = [] fieldNames.append("OGC_FID INTEGER PRIMARY KEY") if includeGeometry: fieldNames.append("GEOMETRY blob") for field in fields: if (fields[field] != u'OID') and field.lower() !=shp.lower(): fieldNames.append(parseFieldType(field,fields[field])) conn=Connection(out) c=conn.cursor() name = splitext(split(out)[1])[0] c.execute("""CREATE TABLE geometry_columns ( f_table_name VARCHAR, f_geometry_column VARCHAR, geometry_type INTEGER, coord_dimension INTEGER, srid INTEGER, geometry_format VARCHAR )""") c.execute("""insert into geometry_columns( f_table_name, f_geometry_column, geometry_type, coord_dimension, srid, geometry_format) values(?,?,?,?,?,?)""",(name,"GEOMETRY",gType,2,4326,"WKB")) c.execute("""CREATE TABLE spatial_ref_sys ( srid INTEGER UNIQUE, auth_name TEXT, auth_srid TEXT, srtext TEXT)""") c.execute("insert into spatial_ref_sys(srid ,auth_name ,auth_srid ,srtext) values(?,?,?,?)",(4326, u'EPSG', 4326, u'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]')) c.execute("create table {0}({1})".format(name,", ".join(fieldNames))) return [name,c,conn]
def __init__(self,outFile,featureClass,fileType,includeGeometry, first=True, outName=False): self.outFile = outFile self.fileType = fileType #first we set put the local variables we'll need [self.shp,self.shpType]=getShp(featureClass) self.fields=listFields(featureClass) self.oid=getOID(self.fields) sr=SpatialReference() sr.loadFromString(wgs84) #the search cursor self.rows=SearchCursor(featureClass,"",sr) #don't want the shape field showing up as a property del self.fields[self.shp] self.first=first self.status = statusMessage(featureClass) #define the correct geometry function if we're exporting geometry self.parseGeo = getParseFunc(self.shpType,includeGeometry) self.i=0 if fileType=="geojson": self.parse = self.parseGeoJSON_ElasticSearch elif fileType=="csv": self.parse = self.parseCSV elif fileType=="json": self.parse = self.parseJSON elif fileType=="sqlite": self.parse = self.parseSqlite elif fileType=="topojson": self.parse = self.parseTOPOJSON if outName: self.oName=outName else: self.oName = getName(featureClass) self.topo = self.outFile['topo'].object_factory(self.oName)
def __init__(self, outFile, featureClass, fileType, includeGeometry, first=True): self.outFile = outFile self.fileType = fileType #first we set put the local variables we'll need [self.shp, self.shpType] = getShp(featureClass) self.fields = listFields(featureClass) self.oid = getOID(self.fields) sr = SpatialReference() sr.loadFromString(wgs84) #the search cursor self.rows = SearchCursor(featureClass, "", sr) #don't want the shape field showing up as a property del self.fields[self.shp] self.first = first self.status = statusMessage(featureClass) #define the correct geometry function if we're exporting geometry self.parseGeo = getParseFunc(self.shpType, includeGeometry) self.i = 0 if fileType == "geojson": self.parse = self.parseGeoJSON elif fileType == "csv": self.parse = self.parseCSV elif fileType == "json": self.parse = self.parseJSON elif fileType == "sqlite": self.parse = self.parseSqlite
def prepareCSV(outJSON,featureClass,fileType,includeGeometry): shp=getShp(featureClass)[0] fields=listFields(featureClass) fieldNames = [] out = open(outJSON,"wb") for field in fields: if (fields[field] != u'OID') and field.lower() !=shp.lower(): fieldNames.append(field) if includeGeometry!="none": fieldNames.append("geometry") outCSV=DictWriter(out,fieldNames,extrasaction='ignore') fieldObject = {} for fieldName in fieldNames: fieldObject[fieldName]=fieldName outCSV.writerow(fieldObject) return [outCSV,out]
def prepareCSV(outJSON, featureClass, fileType, includeGeometry): shp = getShp(featureClass)[0] fields = listFields(featureClass) fieldNames = [] out = open(outJSON, "wb") for field in fields: if (fields[field] != u'OID') and field.lower() != shp.lower(): fieldNames.append(field) if includeGeometry != "none": fieldNames.append("geometry") outCSV = DictWriter(out, fieldNames, extrasaction='ignore') fieldObject = {} for fieldName in fieldNames: fieldObject[fieldName] = fieldName outCSV.writerow(fieldObject) return [outCSV, out]
def prepareSqlite(out, featureClass, fileType, includeGeometry): [shp, shpType] = getShp(featureClass) if shpType == "point": gType = 1 elif shpType == "multipoint": gType = 4 elif shpType == "polyline": gType = 5 elif shpType == "polygon": gType = 6 fields = listFields(featureClass) fieldNames = [] fieldNames.append("OGC_FID INTEGER PRIMARY KEY") if includeGeometry: fieldNames.append("GEOMETRY blob") for field in fields: if (fields[field] != u'OID') and field.lower() != shp.lower(): fieldNames.append(parseFieldType(field, fields[field])) conn = Connection(out) c = conn.cursor() name = splitext(split(out)[1])[0] c.execute( """CREATE TABLE geometry_columns ( f_table_name VARCHAR, f_geometry_column VARCHAR, geometry_type INTEGER, coord_dimension INTEGER, srid INTEGER, geometry_format VARCHAR )""" ) c.execute( """insert into geometry_columns( f_table_name, f_geometry_column, geometry_type, coord_dimension, srid, geometry_format) values(?,?,?,?,?,?)""", (name, "GEOMETRY", gType, 2, 4326, "WKB")) c.execute( """CREATE TABLE spatial_ref_sys ( srid INTEGER UNIQUE, auth_name TEXT, auth_srid TEXT, srtext TEXT)""" ) c.execute( "insert into spatial_ref_sys(srid ,auth_name ,auth_srid ,srtext) values(?,?,?,?)", (4326, u'EPSG', 4326, u'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]' )) c.execute("create table {0}({1})".format(name, ", ".join(fieldNames))) return [name, c, conn]