This project has moved and is read-only. For the latest updates, please go here.

Geometric operation like IsPointIn

Aug 30, 2006 at 11:44 AM

I'm very impressed about SharpMap. But I need same geometric operation. For example, I must test whether one point lies in a polygone. Is this possible with SharpMap?


Aug 30, 2006 at 11:55 AM

This is possible with a data provider extension.
Look at:

There you can apply real spatial operations to geometries.
Thanks to Diego Guidi for providing the very good library


Aug 30, 2006 at 2:13 PM

thank you for the tip. But I cannot find a method, with which I can test whether point lies in the polygon?

Can you help me again?

Aug 30, 2006 at 2:26 PM
Hi Detlef!

I think "Within" is your friend.

Aug 31, 2006 at 7:05 AM

I wrote the following code, but anything is wrong.

SharpMap.Data.Providers.ShapeFile oShape = new SharpMap.Data.Providers.ShapeFile(Server.MapPath(@"~/App_Data/Gemeinden.Shp"));

uint i = 0;
uint iFeature = (uint)oShape.GetFeatureCount();
// find a record
for (i = 0; i < iFeature; i++ )
if (oShape.GetFeature(i)"GEM_SCHL".ToString().TrimEnd() == "12068477")

SharpMap.Geometries.Point oPoint = new SharpMap.Geometries.Point( 3737150.0, 5870277.0 );
GisSharpBlog.NetTopologySuite.Geometries.Geometry oPt =
SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry( oPoint, new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory());

GisSharpBlog.NetTopologySuite.Geometries.Geometry oPoly =
SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(oShape.GetFeature(i).Geometry, new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory());

this.Label1.Text = "inside";
this.Label1.Text = "outside";

The defined point is inside the selected polygon, but the test is allways false.

Can anybody help me?

Aug 31, 2006 at 9:30 AM
Please send me the source code (or a sample of the source) and the data you use, so i could test and verify if is a NTS problem.
Aug 31, 2006 at 10:11 AM
Hi Detlef,

Please change the following part of your code

if(oPoly.Within(oPt)) --> if(oPt.Within(oPoly))

Because you want to test if point is within the polygon.


PS: Kommst du aus Deutschland?
Aug 31, 2006 at 1:13 PM
Hi Volleyknaller,

thank you very much, now it goes as desired.


PS.: Ja ich komme aus Deutschland, merkt man das an meinem schlechten Englisch? Du auch, wenn ja würde ich gern in Deutsch weitermachen.
Aug 31, 2006 at 10:22 PM
No your english is not that bad ;-) So please continue using english in the forums. Although I do understand german, many others don't and the forum is also a good knowledgebase for others to use as well.
Aug 31, 2006 at 10:26 PM
So NTS works well :)
Maybe also NTS rocks, a little bit respect to SharpMap, but rocks!
Sep 1, 2006 at 7:57 AM

I search in my shape-file for one geoobject by using a for-next

for (i = 0; i < iFeature; i++)
if (oShape.GetFeature(i)"Area".ToString().TrimEnd() == cArea)

In my opinion, that's a very wrong way.

How can I make that better?

Sep 1, 2006 at 8:17 AM
Currently the DBF reader in SharpMap doesn't utilize any data-index for searching (except a spatial index for shapedata), so locating data can only be done by looping it. There are DBF drivers out there which can help you but you will then need to build an index for each of the columns you would like to query.
If you want this more efficient upload your data to a SQL database. Here you get full set of DB feature.