Geometric operation like IsPointIn

Aug 30, 2006 at 11:44 AM
Hello,

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?

Thank's

Detlef
Coordinator
Aug 30, 2006 at 11:55 AM
Hi,

This is possible with a data provider extension.
Look at: http://www.codeplex.com/Wiki/View.aspx?ProjectName=SharpMap&title=NetTopologySuite%20Data%20Provider

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

BR
/Christian

Aug 30, 2006 at 2:13 PM
Hi,

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?

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

I think "Within" is your friend.

BR
/Christian
Aug 31, 2006 at 7:05 AM
Hi,

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"));
oShape.Open();

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")
break;
}


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());

if(oPoly.Within(oPt))
this.Label1.Text = "inside";
else
this.Label1.Text = "outside";

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

Can anybody help me?

Detlef!
Developer
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.
diegoguidiNOSPAM@gmail.com
Coordinator
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.

BR
/Christian

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

thank you very much, now it goes as desired.

Detlef!

PS.: Ja ich komme aus Deutschland, merkt man das an meinem schlechten Englisch? Du auch, wenn ja würde ich gern in Deutsch weitermachen.
Developer
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.
Developer
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)
break;
}

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

How can I make that better?

Detlef!
Developer
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.