erik2006
Posts: 13
Joined: Mon Jan 09, 2006 12:18 pm

Shape.IsInside

Fri May 12, 2006 5:40 pm

Hi!

When I use the following code:

GpsShapeNET.Shape shape = new GpsShapeNET.Shape();
GpsToolsNET.Position nodeDatumGrid = new GpsToolsNET.Position();
nodeDatumGrid.Datum = GpsToolsNET.Datum.WGS_84;
shape.DatumGridTemplate = nodeDatumGrid;

GpsToolsNET.Position pos = new GpsToolsNET.Position();
pos.Datum = GpsToolsNET.Datum.WGS_84;
pos.Longitude = 5.0;
pos.Latitude = 5.0;

shape.NewNode(-1);
shape.Position.Longitude = 0.0;
shape.Position.Latitude = 0.0;
shape.NewNode(-1);
shape.Position.Longitude = 10.0;
shape.Position.Latitude = 0.0;
shape.NewNode(-1);
shape.Position.Longitude = 10.0;
shape.Position.Latitude = 10.0;
shape.NewNode(-1);
shape.Position.Longitude = 0.0;
shape.Position.Latitude = 10.0;
shape.NewNode(-1);
shape.Position.Longitude = 0.0;
shape.Position.Latitude = 0.0;

bool b = shape.IsCleanPolygon;
bool b2 = shape.IsInside(pos);


shape.NodeCount is 5,
b is true,
but b2 is false!


what am I doing wrong?

Hoping for help,
erik

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Shape.IsInside

Fri May 12, 2006 6:17 pm

When you add the longitude and latitude coordinates like that you are not really telling the Shape object that it is being changed. Instead you are accessing the Position object and changing it, which will be reflected when you draw the shape, but internally the Shape needs to know when its being changed in order to tell if a Position is inside or not.

If you want to add the coordinates in that way (and not use AddNode or similar) you must write it liks this:

Code: Select all

GpsToolsNET.Position shapePos = new GpsToolsNET.Position();
shapePos.Longitude = 0.0;
shapePos.Latitude = 0.0;
shape.Position = shapePos;
That way the Shape will properly know it's being changed.

With your code this will not be a clean polygon though since you are adding nodes backwards. This means the Shape will have a negative area, and that is not allowed for a clean polygon.

Regards,
Jonas
Franson Support

fdaunis
Posts: 2
Joined: Wed Oct 22, 2008 9:58 pm
Location: Spain

RE: Shape.IsInside

Wed Nov 19, 2008 4:04 pm

I'm testing the sample, but I get an error "[10003] No memory has been reserved to store node. (Probably bad shape header)" when I asign a position to shape!!!

GpsToolsNET.Position shapePos = new GpsToolsNET.Position();
shapePos.Longitude = 0.0;
shapePos.Latitude = 0.0;
shape.Position = shapePos; ----------- ERROR




shape.NewNode(-1);
shape.Position.Longitude = 0.0;
shape.Position.Latitude = 0.0;
shape.NewNode(-1);
shape.Position.Longitude = 10.0;
shape.Position.Latitude = 0.0;
shape.NewNode(-1);
shape.Position.Longitude = 10.0;
shape.Position.Latitude = 10.0;
shape.NewNode(-1);
shape.Position.Longitude = 0.0;
shape.Position.Latitude = 10.0;
shape.NewNode(-1);
shape.Position.Longitude = 0.0;
shape.Position.Latitude = 0.0;


thanks!

Return to “GpsTools”