Thomas,
Thanks for your post and questions.
Yes, as you already have noticed, the validation will still pass even though the last vertex was removed from the ring of the polygon, like the following code snippet shows:
RingShape ringShape = new RingShape();
ringShape.Vertices.Add(new Vertex(0, 0));
ringShape.Vertices.Add(new Vertex(1, 0));
ringShape.Vertices.Add(new Vertex(1, 1));
ringShape.Vertices.Add(new Vertex(0, 1));
PolygonShape polygonShape = new PolygonShape();
polygonShape.OuterRing = ringShape;
double area = polygonShape.GetArea(GeographyUnit.Meter, AreaUnit.SquareMeters);
ShapeValidationResult result = polygonShape.Validate(ShapeValidationMode.Simple);
The reason for this is that we only did very simple validation on the shapes, for the lineshape, we only check the vertex number exceeds 2 and for the RingShape we only check the vertex number is greater than 3. We reverse the complex logic to advanced validation mode. For now, we can need to write the validate logic as we want, following is some code snippet which add the vertex checking for the out ring of the polgyonshape.
ShapeValidationResult newResult = ValidatePolygon(polygonShape);
private static ShapeValidationResult ValidatePolygon(PolygonShape polygonShape)
{
ShapeValidationResult result = polygonShape.Validate(ShapeValidationMode.Simple);
int ourRingVertexCount = polygonShape.OuterRing.Vertices.Count;
if (polygonShape.OuterRing.Vertices[0] != polygonShape.OuterRing.Vertices[ourRingVertexCount - 1])
{
result = new ShapeValidationResult(false, "The first vertex is not the last vertex");
}
return result;
}
Any more questions just feel free to let me know.
Thanks.
Yale