[gdal-dev] problem with CloseRings

Oliver Christen oliver.christen at camptocamp.com
Thu Aug 23 23:09:26 PDT 2012


Thank you Frank, Doug, Chaitanya

I effectively didnt notice the "degenerate" state of the ring :(
Now I understand why CloseRings didnt help in some cases.
It seems I will have to toy a bit with the geometries.

thanks again
best regards
Oliver


 > Doug,
 >
 > You could rebuild individual polygons by attempting to close the
 > constituent rings one-by-one while discarding those that give an 
error with
 > the CloseRings() method.
 >
 > On Wed, Aug 22, 2012 at 10:41 PM, <Doug_Newcomb at fws.gov> wrote:
 >
 > >
 > > Oliver,
 > >
 > > Would it just be a matter of counting the vertices of each polygon,
 > > selecting the polygons with 3 vertices, and comparing the value of the
 > > first and last vertex  as you are building wkt value string below?
 > >
 > >
 > > Doug
 > >
 > >
 > >
 > > >The problem with your rings isn't that they are not closed, it is that
 > > >they are degenerate.
 > >
 > > >For instance:
 > > >(559560.19 142169.94,559550.64 142173.43,559560.19 142169.94)
 > >
 > > >This goes from PointA to PointB back to PointA.  It is closed, it just
 > > >is degenerate.  It has no area.  I'm not aware of a super easy way of
 > > >cleaning out such junk rings - you might need to explicitly test them
 > > >and remove them if they are degenerate.
 > >
 > > >Best regards,
 > >
 > >
 > >
 > >
 > > Doug Newcomb
 > > USFWS
 > > Raleigh, NC
 > > 919-856-4520 ext. 14 doug_newcomb at fws.gov
 > >
 > > 
---------------------------------------------------------------------------------------------------------
 > > The opinions I express are my own and are not representative of the
 > > official policy of the U.S.Fish and Wildlife Service or Dept. of the
 > > Interior.   Life is too short for undocumented, proprietary data 
formats.
 > >
 > >
 > >  *Frank Warmerdam <warmerdam at pobox.com>*
 > > Sent by: gdal-dev-bounces at lists.osgeo.org
 > >
 > > 08/22/2012 12:49 PM
 > >   To
 > > Oliver Christen <oliver.christen at camptocamp.com>
 > > cc
 > > gdal-dev at lists.osgeo.org
 > > Subject
 > > Re: [gdal-dev] problem with CloseRings
 > >
 > >
 > >
 > >
 > > Oliver,
 > >
 > > The problem with your rings isn't that they are not closed, it is that
 > > they are degenerate.
 > >
 > > For instance:
 > > (559560.19 142169.94,559550.64 142173.43,559560.19 142169.94)
 > >
 > > This goes from PointA to PointB back to PointA.  It is closed, it just
 > > is degenerate.  It has no area.  I'm not aware of a super easy way of
 > > cleaning out such junk rings - you might need to explicitly test them
 > > and remove them if they are degenerate.
 > >
 > > Best regards,
 > >
 > > On Wed, Aug 22, 2012 at 9:13 AM, Oliver Christen
 > > <oliver.christen at camptocamp.com> wrote:
 > > > dear community
 > > >
 > > > first of all please accept my apologies if this is not the correct
 > > > place to ask about such question.
 > > >
 > > > I am trying to manipulate some geometric data using the gdal/ogr
 > > > python lib and Im facing a problem when trying to transform invalid
 > > > ring into valid ring.
 > > >
 > > > I have polygons with unclosed holes and I expected the CloseRings
 > > > function to solve this for me, but unfortunately, that functions
 > > > doesnt seem to do anything (in my case).
 > > >
 > > > see below for a simply python testcase,
 > > >
 > > > if you could tell me if I am possibly not using that function
 > > > correctly or if there is a more correct way to do that, you would be
 > > > very welcome
 > > >
 > > > using python version 2.6.6
 > > > osgeo ogr lib version 1.3.40
 > > >
 > > > thank you very much for your attention
 > > > best regards
 > > > Oliver
 > > >
 > > > from osgeo import ogr
 > > >
 > > > wkt = "POLYGON ((559577.81 142165.04,559577.67 142161.79,559577.66
 > > > 142161.16,559577.18 142139.0,559564.07 142140.84,559562.99
 > > > 142132.4,559556.42 142134.85,559556.47 142134.96,559541.39
 > > > 142140.58,559549.54 142162.4,559547.0200406529475
 > > > 142163.310114102292573,559550.570425555342808
 > > > 142173.455536680703517,559577.81 142165.04),(559559.95600777247455
 > > > 142169.280249390256358,559550.996165407239459
 > > > 142172.552877245907439,559550.996165407355875
 > > > 142172.552877245907439,559547.909677243907936
 > > > 142163.733065433305455,559550.443360350676812
 > > > 142162.817994827404618,559542.290859716595151
 > > > 142140.991299878398422,559557.417905980604701
 > > > 142135.353766721702414,559557.367843619547784
 > > > 142135.243629527511075,559562.407678314950317
 > > > 142133.364239115995588,559563.465598454349674
 > > > 142141.631689094298054,559576.497222575126216
 > > > 142139.80268921770039,559576.960120304953307
 > > > 142161.173134415294044,559576.970239149406552
 > > > 142161.810621617711149,559577.084823867655359
 > > > 142164.470624003995908,559577.084823867655359
 > > > 142164.470624004025012,559570.876975534367375
 > > > 142165.896950183814624,559564.754505693446845
 > > > 142167.653979024267755,559564.75450569356326
 > > > 142167.653979024296859,559559.956007772590965
 > > > 142169.280249390256358,559559.95600777247455
 > > > 142169.280249390256358),(559560.19 142169.94,559550.64
 > > > 142173.43,559560.19 142169.94),(559564.97 142168.32,559560.19
 > > > 142169.94,559564.97 142168.32),(559577.810000000172295
 > > > 142165.04,559571.34395208011847 142166.499739240010967,559564.97
 > > > 142168.32,559577.810000000172295 142165.04))"
 > > >
 > > > poly = ogr.CreateGeometryFromWkt(wkt)
 > > >
 > > > poly.IsValid()
 > > > ERROR 1: IllegalArgumentException: Invalid number of points in
 > > > LinearRing found 3 - must be 0 or >= 4
 > > > False
 > > >
 > > > poly.CloseRings()
 > > >
 > > > poly.IsValid()
 > > > ERROR 1: IllegalArgumentException: Invalid number of points in
 > > > LinearRing found 3 - must be 0 or >= 4
 > > > False
 > > > _______________________________________________
 > > > gdal-dev mailing list
 > > > gdal-dev at lists.osgeo.org
 > > > http://lists.osgeo.org/mailman/listinfo/gdal-dev
 > >
 > >
 > >
 > > --
 > >
 > > 
---------------------------------------+--------------------------------------
 > > I set the clouds in motion - turn up   | Frank Warmerdam,
 > > warmerdam at pobox.com
 > > light and sound - activate the windows |
 > > <http://lists.osgeo.org/mailman/listinfo/gdal-dev>
 > > http://pobox.com/~warmerdam
 > > and watch the world go round - Rush    | Geospatial Software Developer
 > > _______________________________________________
 > > gdal-dev mailing list
 > > gdal-dev at lists.osgeo.org
 > >  <http://pobox.com/%7Ewarmerdam>
 > > http://lists.osgeo.org/mailman/listinfo/gdal-dev
 > >
 > >
 > > _______________________________________________
 > > gdal-dev mailing list
 > > gdal-dev at lists.osgeo.org
 > > http://lists.osgeo.org/mailman/listinfo/gdal-dev
 > >
 >
 >
 >
 > --
 > Best regards,
 > Chaitanya kumar CH.
 >
 > +91-9494447584
 > 17.2416N 80.1426E


More information about the gdal-dev mailing list