Hi,
I am trying to create a basic polygon shapefile using OGR in Python.
Any help with fixing my code is appreciated. Currently, it creates a
shapefile, but nothing shows up in ArcGIS.
# GDAL
from osgeo import ogr, gdal
from osgeo.gdalconst import *
# sample data
data = [[3333317.0,5684892.0],[3333417.0,5684892.0],\
[3333317.0,5684992.0],[3333417.0,5684992.0]]
# Create Shapefile named "polygon.shp" for output
driver = ogr.GetDriverByName('ESRI Shapefile')
output = "polygon.shp"
datasource = driver.CreateDataSource(output)
layer = datasource.CreateLayer(output, geom_type=ogr.wkbPolygon)
feature = ogr.Feature(layer.GetLayerDefn())
wkt = "POLYGON(" + str(data[0][0]) + " " + str(data[0][1]) + "," +
str(data[1][0]) + " " + str(data[1][1]) + "," + str(data[2][0]) + " " +
str(data[2][1]) + "," + str(data[3][0]) + " " + str(data[3][1]) + ")"
polygon = ogr.CreateGeometryFromWkt(wkt)
layer.CreateFeature(feature)
# Clean up
feature.Destroy()
datasource.Destroy()
print "Feature <" + str(output) + "> successfully created."
del output
_________________________________________________________________
The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev