[gdal-dev] Creating a simple shapefile with ogr
Even Rouault
even.rouault at mines-paris.org
Thu May 27 17:45:45 EDT 2010
You didn't bind the geometry to the feature
Add feature.SetGeometry(polygon) before layer.CreateFeature(feature)
Le Thursday 27 May 2010 23:35:49 Discourse Maps, vous avez écrit :
> 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=PID28
>326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4
More information about the gdal-dev
mailing list