[Gdal-dev] python, multipolygon creation

Didrik Pinte dpinte at itae.be
Wed Feb 8 11:47:49 EST 2006


Hi,

I'm trying to write a function for simplifying polygons.

My input file is a shapefile containing 11 MULTIPOLYGON composed of only
1 LINEARRING.

I can read and simplify the LINEARRINGS but I cannot create add them to
a new MULTIPOLYGON. The AddGeometryDirectly() method seems to be doing
nothing.

Here is the problematic code :
-----------------------------------------------------------
 if geom.GetGeometryCount() > 0:
      print 'Multiple geometries : simplifying %s geometries' %
geom.GetGeometryCount()
      new_geom = []
      # for each LinearRing, simplify it and store it in a list 
      for i in xrange(geom.GetGeometryCount()):
        in_geom = geom.GetGeometryRef(i)
        new_geom.append( SimplifyGeometry( in_geom, tolerance ) )
      # Creating the output new MultiPolygon
      seg = ogr.Geometry( type= ogr.wkbMultiPolygon )
      # Adding the circles into the polygon
      for ng in new_geom:
 	print "Ng points %i" % ng.GetPointCount()
        seg.AddGeometryDirectly(ng)
      seg.CloseRings()
      print "New multipolygon has %i geometries" %
seg.GetGeometryCount()
      return seg
------------------------------------------------------------
Here is the output i always have :
------------------------------------------------------------
Multiple geometries : simplifying 1 geometries
Ng points 1841
New multipolygon has 0 geometries


At the end of the process my seg object does not contain any
geometry ... Is it a problem with the AddGeometryDirectly ?

I think i've missed something. 

Does anybody have an idea about my problem ?

Didrik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Ceci est une partie de message
	=?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e?=
Url : http://lists.osgeo.org/pipermail/gdal-dev/attachments/20060208/7edfacd6/attachment.bin


More information about the Gdal-dev mailing list