[gdal-dev] Creating a simple shapefile with ogr

Discourse Maps discoursemap at live.com
Thu May 27 17:35:49 EDT 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20100527/f120e8fe/attachment.html


More information about the gdal-dev mailing list