def saveToShape(self,array,srs,outShapeFile):
# Parse a delimited text file of volcano data and create a shapefile
# use a dictionary reader so we can access by field name
# set up the shapefile driver
outDriver = ogr.GetDriverByName( 'ESRI Shapefile' )
# create the data source
if os.path.exists(outShapeFile):
outDriver.DeleteDataSource(outShapeFile)
# Remove output shapefile if it already exists
ds = outDriver.CreateDataSource(outShapeFile) #options = ['SPATIALITE=YES'])
# create the spatial reference, WGS84
lyrout = ds.CreateLayer('randomSubset',srs)
fields = [array[1].GetFieldDefnRef(i).GetName() for i in range(array[1].GetFieldCount())]
for f in fields:
field_name = ogr.FieldDefn(f, ogr.OFTString)
field_name.SetWidth(24)
lyrout.CreateField(field_name)
for k in array:
lyrout.CreateFeature(k)
# Save and close the data source
ds = None
评论列表
文章目录