Simple contains question

Topics: SharpMap v0.9 / v1.x
Oct 31, 2012 at 9:41 PM

Given the following basic code:

var point = new Point(-104.0, 41.0);
var square = new Polygon();
square.ExteriorRing = new LinearRing(new List<Point>()
	{
		new Point(-105, 42),
		new Point(-103, 42),
		new Point(-103, 40),
		new Point(-105, 40)
	});

Console.WriteLine(square.Contains(point));
Console.WriteLine(point.Within(square));

I think I'm creating a basic square polygon and that my point should be within it. However, the Contains and Within methods both return false. What am I doing wrong?

Coordinator
Nov 1, 2012 at 8:21 AM

You need to close the polygon

 


square.ExteriorRing = new LinearRing(new List<Point>()
	{
		new Point(-105, 42),
		new Point(-103, 42),
		new Point(-103, 40),
		new Point(-105, 40),
		new Point(-105, 42)
	});
Nov 1, 2012 at 2:00 PM

Thank you for the reply, but this code produces false for the Contain/Within functions as well. I am absolutely new to this, so maybe I'm missing something else obvious.

var point = new Point(-104.0, 41.0);
var square = new Polygon();
square.ExteriorRing = new LinearRing(new List<Point>()
	{
		new Point(-105, 42),
		new Point(-103, 42),
		new Point(-103, 40),
		new Point(-105, 40),
		new Point(-105, 42)
	});

Console.WriteLine(square.Contains(point));
Console.WriteLine(point.Within(square));
Coordinator
Nov 2, 2012 at 1:34 PM

Please do not use the provided binaries.

Grab the source and compile it yourself. You will have much better topology support.

Hth FObermaier