This project is read-only.

Problem with ClipPolygonWithPolygon

Apr 22, 2014 at 9:19 AM
Hi,
i'm new to dotspatial. I want to use the function Execute from class ClipPolygonWithPolygon.
If i use this function to clip a line shape using a polygon shape the result is ok
but if i use the function to clip a polygon shape always using a polygon shape the result is:

"An unhandled exception of type "System.IndexOutOfRangeException'
occured in DotSpatial.Topology.dll.
Additional information: Index was outside the bounds of the array.


Can anyone help me with this problem?
Thanks, Angela
Apr 23, 2014 at 1:42 PM
I had some trouble with the same command, and I resolved it by using a different command. In my code it was written this way:
        ClipPolygonWithLine.ClipPolygonFeatureSetWithPolygon(featsIN, featCLIP, featsOUT, True)
You find it in dospatial.tools

this command is supposed to do the same as clippolygonwithpolygon, but working on a set of polygons in input.
FeatsIN is a featureset containing the input polygons to be clipped (I made one containing only one polygon)
FeatCLIP is a feature containing a single polygon to be used for clipping
FeatsOUT is a new featureset containing the results of the clipping (in my case, since FeatsIN contains only one polygon, I get only one polygon also in FeatsOUT)

Hope you can make it

Oscar
Apr 24, 2014 at 8:07 AM
Thanks Oscar, i tried with ClipPolygonWithLine.ClipPolygonFeatureSetWithPolygon but the result is the same error.
The shape to be clipped is the result of a processing of a software.
For testing I used an ArcMap and in some cases I had to do a repair geometry,
now I should automate the process using dotspatial.
May be I need to do something similar to repair before using the
ClipPolygonWithLine.ClipPolygonFeatureSetWithPolygon?
Does a similar method to repair geometry exist?
Thanks a lot!
Angela
Apr 24, 2014 at 10:24 AM
Angela77Dir wrote:
but if i use the function to clip a polygon shape always using a polygon shape the result is:

"An unhandled exception of type "System.IndexOutOfRangeException'
occured in DotSpatial.Topology.dll.
Hi Angela,

could you share shape files to reproduce this issue? It maybe a bug in DotSpatial, or maybe something wrong with your data.

Maxim.
Apr 24, 2014 at 12:06 PM
Hi Maxim,
I shared my files in https://drive.google.com/folderview?id=0B4s_M_fE4LAmTHQwc29Xb3FWSVk&usp=sharing
The file cuttoshape.shp is what you need to cut, while the other is what I have to cut.
Thank you very much!
Angela
Apr 30, 2014 at 9:10 AM
Hi Angela,

i checked your files. I've fixed "System.IndexOutOfRangeException" - in Elab_5_Temperaturaaria_KRI_22042014_0730AreePoly there is a one empty MultiPolygon, and DotSpatial fails on it.
But now there is another issue:
4/30/2014 12:07:44 PM: Error: System.ArgumentException: Item has already been added. Key in dictionary: 'LINEARRING (86931.9686044226000000 5038249.0900543100000000, 85845.3643653030000000 5038732.9598065300000000, 85662.2674292891000000 5038249.0900543100000000, 85845.3643653030000000 5038126.5709508600000000, 86931.9686044226000000 5038249.0900543100000000)' Key being added: 'LINEARRING (86931.9686044226000000 5038249.0900543100000000, 85845.3643653030000000 5038732.9598065300000000, 85662.2674292891000000 5038249.0900543100000000, 85845.3643653030000000 5038126.5709508600000000, 86931.9686044226000000 5038249.0900543100000000)'
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at System.Collections.Hashtable.Add(Object key, Object value)
at DotSpatial.Topology.GeometriesGraph.GeometryGraph.AddPolygonRing(IBasicGeometry lr, LocationType cwLeft, LocationType cwRight) in g:\MaxDocs\Projects\ISU_GSL\dotSpatial\Trunk\DotSpatial.Topology\GeometryGraph\GeometryGraph.cs:line 257
at DotSpatial.Topology.GeometriesGraph.GeometryGraph.AddPolygon(Polygon p) in g:\MaxDocs\Projects\ISU_GSL\dotSpatial\Trunk\DotSpatial.Topology\GeometryGraph\GeometryGraph.cs:line 275

I think it is something wrong with your data, but i'm not sure :(
Apr 30, 2014 at 2:03 PM
Hi Maxim,
from the description of the exception it seems that there is in the shape or a repeated feature or a repeated geometric...
probably when I did a test with Arcmap the function of repair geometry "cleaned" the shape...
there is nothing like it in Dotspatial?
I seem to remember that there is a method that, given a list of coordinates, eliminates the repeat... there is also for polygons or features?
Thank you very much!
Angela
May 1, 2014 at 7:30 AM
Yes, there is a method which can remove duplicate coordinates, but i don't know about similar for polygons.