Getting polygons that contains a point

Mar 2, 2011 at 7:44 PM

Hello,

I'm developping an asset tracking solution. I have a point feature (lat/long) and I have a FeatureSet with several polygons inside it (each polygon is a geofence). How can I retreive all polygon instances what contains my point using only Core DotSpatial assemblies, i.e. not WinForms or WPF controls.

Thanks
Jean

Coordinator
Mar 3, 2011 at 9:06 AM

The function you need should be found in DotSpatial.topology

- Dan
--------
Daniel P. Ames Ph.D.
Idaho State University Dept. of Geosciences
dan.ames@isu.edu
--------
Sent from my Droid

On Mar 2, 2011 1:45 PM, "JBed007" <notifications@codeplex.com> wrote:
> From: JBed007
>
> Hello,I'm developping an asset tracking solution. I have a point feature (lat/long) and I have a FeatureSet with several polygons inside it (each polygon is a geofence). How can I retreive all polygon instances what contains my point using only Core DotSpatial assemblies, i.e. not WinForms or WPF controls.Thanks
> Jean
>
>
Mar 4, 2011 at 2:03 PM

Can you be a little more specific ? FeatureSet class is not event defined in DotSpatial.Topology, it is defined in DotSpatial.Data assembly. Do you have a class name of method name to point me out ?

Jean

Developer
Mar 4, 2011 at 4:48 PM

You need to reference the DotSpatial.Data and DotSpatial.Topology namespaces.

For PointInPolygon, you can use the DotSpatial.Data.IFeature.Intersects method. The following example tests if any of the polygons contain the point:

private static bool TestPointInPolygons ( Coordinate coord, IList<IFeature> polygons )
		{
			DotSpatial.Topology.Point pt = new DotSpatial.Topology.Point ( coord );
			foreach ( IFeature poly in polygons )
			{
				if ( poly.Intersects ( pt ) )
				{
					return true;
				}
			}
			return false;
		}


Regards,

Jiri