Shapefile tests: createholeexamples.py

Bernhard Reiter bernhard at intevation.de
Tue Dec 7 12:27:51 CET 2004


It occurred to me that we should have a set of test shapefiles
with the various cases with holes for Thuban.
They should only display one difficulty at a time.

Probably some test shapefile compilations already exist, 
but I did not have the time to search for existing sets yet.
(Does anybody know some?)

Together with Silke I just created a small script using python ogr.
It is attached, also a screenshot with Thuban showing the output.
Where would be put this in Thuban's cvs?

	Bernhard
-------------- next part --------------
""" Create example shapefiles with ogr. 

Thanks to Silke Reimer.
"""

import ogr
driver = ogr.GetDriverByName("ESRI Shapefile")
ds = driver.CreateDataSource('holetest')

# A polygone with a hole
layer = ds.CreateLayer( 'rect_in_rect' )
feature = ogr.Feature( layer.GetLayerDefn() ) 
geom = 'POLYGON((0 0,0 2, 2 2, 2 0, 0 0),(1 1, 0.5 1, 0.5 0.5, 1 0.5, 1 1))'
geometry = ogr.CreateGeometryFromWkt(geom)
feature.SetGeometry(geometry)
layer.CreateFeature(feature)

# A polygone with a hole and an island in the hole
layer = ds.CreateLayer( 'rect_in_rect_in_rect' )
feature = ogr.Feature( layer.GetLayerDefn() ) 
geom = ('POLYGON((10 0,10 2, 12 2, 12 0, 10 0)'
        ',(11 1, 10.5 1, 10.5 0.5, 11 0.5, 11 1)'
        ',(10.75 0.75,  10.75 0.85, 10.85 0.85 , 10.85 0.75, 10.75 0.75) '
               ')')
geometry = ogr.CreateGeometryFromWkt(geom)
feature.SetGeometry(geometry)
layer.CreateFeature(feature)

# A polygone with two holes and one island in the first hole
layer = ds.CreateLayer( 'two_holes_one_with_island' )
feature = ogr.Feature( layer.GetLayerDefn() ) 
geom = ('POLYGON((0 10,0 12, 2 12, 2 10, 0 10)'
        ',(1 11, 0.5 11, 0.5 10.5, 1 10.5, 1 11)'
        ',(0.75 10.75,  0.75 10.85, 0.85 10.85 , 0.85 10.75, 0.75 10.75)' 
        ',(1.25 11.25, 1.25 11.35, 1.35 11.35, 1.35 11.25, 1.25 11.25)'
              ' )')
geometry = ogr.CreateGeometryFromWkt(geom)
feature.SetGeometry(geometry)
layer.CreateFeature(feature)


ds.Destroy()

-------------- next part --------------
A non-text attachment was scrubbed...
Name: thuban-shapeholeexamples-20041207.png
Type: image/png
Size: 13805 bytes
Desc: not available
Url : http://www.intevation.de/pipermail/thuban-devel/attachments/20041207/587eca0e/thuban-shapeholeexamples-20041207.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.intevation.de/pipermail/thuban-devel/attachments/20041207/587eca0e/attachment.bin


More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)