Doug,<br><br>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.<br><br><div class="gmail_quote">On Wed, Aug 22, 2012 at 10:41 PM, <span dir="ltr"><<a href="mailto:Doug_Newcomb@fws.gov" target="_blank">Doug_Newcomb@fws.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><tt><font>Oliver,</font></tt>
<br>
<br><tt><font>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? </font></tt>
<br>
<br>
<br><tt><font>Doug</font></tt>
<br><div class="im">
<br><tt><font><br>
<br>
>The problem with your rings isn't that they are not closed, it is that<br>
>they are degenerate.<br>
<br>
>For instance:<br>
>(559560.19 142169.94,559550.64 142173.43,559560.19 142169.94)<br>
<br>
>This goes from PointA to PointB back to PointA. It is closed,
it just<br>
>is degenerate. It has no area. I'm not aware of a super
easy way of<br>
>cleaning out such junk rings - you might need to explicitly test them<br>
>and remove them if they are degenerate.<br>
<br>
>Best regards,<br>
</font></tt>
<br>
<br>
<br>
<br></div><font face="sans-serif">Doug Newcomb
<br>
USFWS<br>
Raleigh, NC<br>
919-856-4520 ext. 14 <a href="mailto:doug_newcomb@fws.gov" target="_blank">doug_newcomb@fws.gov</a><br>
---------------------------------------------------------------------------------------------------------<br>
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.</font>
<br>
<br>
<br>
<p></p><table width="100%">
<tbody><tr valign="top">
<td width="40%"><font face="sans-serif" size="1"><b>Frank Warmerdam <<a href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</a>></b>
</font>
<br><font face="sans-serif" size="1">Sent by: <a href="mailto:gdal-dev-bounces@lists.osgeo.org" target="_blank">gdal-dev-bounces@lists.osgeo.org</a></font>
<p><font face="sans-serif" size="1">08/22/2012 12:49 PM</font>
</p></td><td width="59%">
<table width="100%">
<tbody><tr valign="top">
<td>
<div align="right"><font face="sans-serif" size="1">To</font></div>
</td><td><font face="sans-serif" size="1">Oliver Christen <<a href="mailto:oliver.christen@camptocamp.com" target="_blank">oliver.christen@camptocamp.com</a>></font>
</td></tr><tr valign="top">
<td>
<div align="right"><font face="sans-serif" size="1">cc</font></div>
</td><td><font face="sans-serif" size="1"><a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a></font>
</td></tr><tr valign="top">
<td>
<div align="right"><font face="sans-serif" size="1">Subject</font></div>
</td><td><font face="sans-serif" size="1">Re: [gdal-dev] problem with CloseRings</font></td></tr></tbody></table>
<br>
<table>
<tbody><tr valign="top">
<td>
</td><td></td></tr></tbody></table>
<br></td></tr></tbody></table><div class="HOEnZb"><div class="h5">
<br>
<br>
<br><tt><font>Oliver,<br>
<br>
The problem with your rings isn't that they are not closed, it is that<br>
they are degenerate.<br>
<br>
For instance:<br>
(559560.19 142169.94,559550.64 142173.43,559560.19 142169.94)<br>
<br>
This goes from PointA to PointB back to PointA. It is closed, it
just<br>
is degenerate. It has no area. I'm not aware of a super easy
way of<br>
cleaning out such junk rings - you might need to explicitly test them<br>
and remove them if they are degenerate.<br>
<br>
Best regards,<br>
<br>
On Wed, Aug 22, 2012 at 9:13 AM, Oliver Christen<br>
<<a href="mailto:oliver.christen@camptocamp.com" target="_blank">oliver.christen@camptocamp.com</a>> wrote:<br>
> dear community<br>
><br>
> first of all please accept my apologies if this is not the correct<br>
> place to ask about such question.<br>
><br>
> I am trying to manipulate some geometric data using the gdal/ogr<br>
> python lib and Im facing a problem when trying to transform invalid<br>
> ring into valid ring.<br>
><br>
> I have polygons with unclosed holes and I expected the CloseRings<br>
> function to solve this for me, but unfortunately, that functions<br>
> doesnt seem to do anything (in my case).<br>
><br>
> see below for a simply python testcase,<br>
><br>
> if you could tell me if I am possibly not using that function<br>
> correctly or if there is a more correct way to do that, you would
be<br>
> very welcome<br>
><br>
> using python version 2.6.6<br>
> osgeo ogr lib version 1.3.40<br>
><br>
> thank you very much for your attention<br>
> best regards<br>
> Oliver<br>
><br>
> from osgeo import ogr<br>
><br>
> wkt = "POLYGON ((559577.81 142165.04,559577.67 142161.79,559577.66<br>
> 142161.16,559577.18 142139.0,559564.07 142140.84,559562.99<br>
> 142132.4,559556.42 142134.85,559556.47 142134.96,559541.39<br>
> 142140.58,559549.54 142162.4,559547.0200406529475<br>
> 142163.310114102292573,559550.570425555342808<br>
> 142173.455536680703517,559577.81 142165.04),(559559.95600777247455<br>
> 142169.280249390256358,559550.996165407239459<br>
> 142172.552877245907439,559550.996165407355875<br>
> 142172.552877245907439,559547.909677243907936<br>
> 142163.733065433305455,559550.443360350676812<br>
> 142162.817994827404618,559542.290859716595151<br>
> 142140.991299878398422,559557.417905980604701<br>
> 142135.353766721702414,559557.367843619547784<br>
> 142135.243629527511075,559562.407678314950317<br>
> 142133.364239115995588,559563.465598454349674<br>
> 142141.631689094298054,559576.497222575126216<br>
> 142139.80268921770039,559576.960120304953307<br>
> 142161.173134415294044,559576.970239149406552<br>
> 142161.810621617711149,559577.084823867655359<br>
> 142164.470624003995908,559577.084823867655359<br>
> 142164.470624004025012,559570.876975534367375<br>
> 142165.896950183814624,559564.754505693446845<br>
> 142167.653979024267755,559564.75450569356326<br>
> 142167.653979024296859,559559.956007772590965<br>
> 142169.280249390256358,559559.95600777247455<br>
> 142169.280249390256358),(559560.19 142169.94,559550.64<br>
> 142173.43,559560.19 142169.94),(559564.97 142168.32,559560.19<br>
> 142169.94,559564.97 142168.32),(559577.810000000172295<br>
> 142165.04,559571.34395208011847 142166.499739240010967,559564.97<br>
> 142168.32,559577.810000000172295 142165.04))"<br>
><br>
> poly = ogr.CreateGeometryFromWkt(wkt)<br>
><br>
> poly.IsValid()<br>
> ERROR 1: IllegalArgumentException: Invalid number of points in<br>
> LinearRing found 3 - must be 0 or >= 4<br>
> False<br>
><br>
> poly.CloseRings()<br>
><br>
> poly.IsValid()<br>
> ERROR 1: IllegalArgumentException: Invalid number of points in<br>
> LinearRing found 3 - must be 0 or >= 4<br>
> False<br>
> _______________________________________________<br>
> gdal-dev mailing list<br>
> <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
> </font></tt><a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank"><tt><font>http://lists.osgeo.org/mailman/listinfo/gdal-dev<br>
<br>
<br>
<br>
-- <br>
---------------------------------------+--------------------------------------<br>
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam@pobox.com<br>
light and sound - activate the windows | </font></tt></a><a href="http://pobox.com/%7Ewarmerdam" target="_blank"><tt><font>http://pobox.com/~warmerdam<br>
and watch the world go round - Rush | Geospatial Software
Developer<br>
_______________________________________________<br>
gdal-dev mailing list<br>
gdal-dev@lists.osgeo.org<br>
</font></tt></a><a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank"><tt><font>http://lists.osgeo.org/mailman/listinfo/gdal-dev<br>
</font></tt></a>
<br></div></div><br>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br></blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Chaitanya kumar CH.<br>
<br>+91-9494447584<br>17.2416N 80.1426E<br>