This project has moved. For the latest updates, please go here.

Spatial query -Intersection point to polygon

Topics: SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, WinForms Controls
Sep 27, 2013 at 11:06 AM
Edited Sep 30, 2013 at 5:27 AM

I need to create an app like by passing the lat,long values it has to check the whether its intersecting a polygon shapefile and return true or false. Can anyone help me in this.

Arun Mohan
Nov 11, 2013 at 2:47 PM
Hi Arun,

i ran into similar problems. i'm exploring the GeoAPI, the way i found to solve the intersecting / containing is first to declare and initialize a IGeometryFactory
            Dim GFact As GeoAPI.Geometries.IGeometryFactory
            GFact = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(0)  'Instead of 0 better use SRID
Then create a point
            Dim PointGeom As GeoAPI.Geometries.IPoint
            PointGeom = GFact.CreatePoint(New GeoAPI.Geometries.Coordinate(1, 2))
Then create a polygon (there are different ways, i don't know how to do it out of a shapefile. If you solve that, let us all know;-)
            Dim coords(3) As GeoAPI.Geometries.Coordinate
            coords(0) = New GeoAPI.Geometries.Coordinate(0, 0)
            coords(1) = New GeoAPI.Geometries.Coordinate(1, 3)
            coords(2) = New GeoAPI.Geometries.Coordinate(2, 1)
            coords(3) = New GeoAPI.Geometries.Coordinate(0, 0)

            Dim PolygonGeom As GeoAPI.Geometries.IPolygon
            PolygonGeom = GFact.CreatePolygon(coords)
Then you can find out
            If PolygonGeom.Contains(PointGeom) Then
                MsgBox("Not contained")
            End If
Other methods beside "Contains" are "Intersects" or "Touches". Quite powerfull, the GeoAPI...

Hope you can live with my VB-code, i was to lazy to translate it to C++