[gdal-dev] unable to write a shapefile using ogr

Beau Taylor purelyamethyst at gmail.com
Wed Sep 10 06:30:54 PDT 2014


The following program successfully creates a shape file I am requiring.

from osgeo import ogr
from osgeo import osr

def myRing(coords):
    ring = ogr.Geometry(ogr.wkbLinearRing)
    for xy in coords:
        ring.AddPoint(xy[0],xy[1])
    return ring

coords = [(-23.378906,68.974164), (-23.378906,34.307144),
(31.464844,34.307144), (31.464844,68.974164), (-23.378906,68.974164)]

ring = myRing(coords)
poly = ogr.Geometry(ogr.wkbPolygon)
poly.AddGeometry(ring)

outDriver = ogr.GetDriverByName('ESRI Shapefile')
data_source = outDriver.CreateDataSource('test.shp')
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326)
layer = data_source.CreateLayer('test.shp', srs, ogr.wkbPolygon)

feature = ogr.Feature(layer.GetLayerDefn())
feature.SetGeometry(poly)
layer.CreateFeature(feature)

feature.Destroy
data_source.Destroy()

However, I did not know how to do the followings:

-set the color of outer ring as blue,
-do not fill the polygen
-name the feature as 'test'

I hope someone can help me.

Thanks in the advance.
Beau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20140910/3f47f787/attachment.html>


More information about the gdal-dev mailing list