Shape.Intersects method no longer returning true

Apr 20, 2012 at 6:29 PM

Around December 2010 I wrote a VB .NET program using the MapWinGIS libraries. One component of this program tests whether two specific shapes intersect using the Shape.Intersects method

I've recently updated to the latest version of the ocx (4.8) to take advantage of some new features and removed all the old references. The Shape.Intersects method is no longer returning true for any points, even when run on the same data that it used to work for. Both shapes are being created/loaded into memory correctly and I've visually verified the intersections.

Both shapes are Polylines. One shape is obtained from a shapefile that I open, and the other shape is created on the fly as below (Intersects method takes too long if I run on the whole shape, and I know intersection will be near the end of this line).

The MapWinGIS references for the project are  AxInterop.MapwinGIS.dll and Interop.MapWinGIS.dll (I've removed MapWinGeoProc and some others since they no longer seem to be needed). Are there any supporting dll that I'm missing? Has something changed that would require me to add something to my code?   Is there a different method I can use?  I just need to know if one line passes through the other line.

Any ideas would be much appreciated, as I've exhausted all of mine

Thanks
Katie

Dim testshape As New MapWinGIS.Shape
            testshape.ShapeType = ShpfileType.SHP_POLYLINE
            testshape.InsertPart(0, 0)
            testshape.InsertPoint(currentshape.Point(currentshape.numPoints - 9), 0)
            testshape.InsertPoint(currentshape.Point(currentshape.numPoints - 8), 1)
            testshape.InsertPoint(currentshape.Point(currentshape.numPoints - 7), 2)
            testshape.InsertPoint(currentshape.Point(currentshape.numPoints - 6), 3)
            testshape.InsertPoint(currentshape.Point(currentshape.numPoints - 5), 4)
            testshape.InsertPoint(currentshape.Point(currentshape.numPoints - 4), 5)
            testshape.InsertPoint(currentshape.Point(currentshape.numPoints - 3), 6)
            testshape.InsertPoint(currentshape.Point(currentshape.numPoints - 2), 7)
            testshape.InsertPoint(currentshape.Point(currentshape.numPoints - 1), 8)

For j = 0 To numboundary - 1

boundaryshape = sfboundary.Shape(j)
                If testshape.Intersects(boundaryshape) Then
                    passage = j
                    passagetype = sfboundary.CellValue(0, j)
                End If
Next

Coordinator
Apr 23, 2012 at 7:45 AM

Can you check if your testshape is valid: testshape.IsValid()
Help: http://www.mapwindow.org/documentation/mapwingis4.8/class_shape.html#a669dd00cefa95bf92334c296e5de20fe

If the shape isn't valid no intersection will be performed and looking quickly at your create shape routing your new shape isn't closed.
Try adding the first point as the last point as well.

--
Paul

Apr 25, 2012 at 9:08 PM

Hi Paul,

Thank you for the response. The shapes are valid; I've tried closing the shape by adding the first point as you suggested but I am still not getting any true returns.

I tried just loading in the two shapefiles directly and cycling through each pair of shapes and still no intersections returning true, however, I think I've found a workaround; hopefully this will help someone out in the future if they have the same problem:

                If testshape.Distance(boundaryshape) = 0 Then
                    passagearray = j
                    passagetypearray = frmMain.sfboundary.CellValue(0, j)
                    Exit For
                End If