ThinkGeo.com    |     Documentation    |     Premium Support

Polygon with 3 vertices

Dear support,


I'm facing a new problem today.


I'm building a polygon shape from a text file using this code:



l.Open();
l.EditTools.BeginTransaction();
PolygonShape pg = new PolygonShape();
foreach xxx
{
  pg.OuterRing.Vertices.Add(new Vertex(p.x, p.y));
}
l.EditTools.Add(pg, xxx);
l.EditTools.CommitTransaction();
l.Close();


When I try to build a triangle (3 vertices) polygone, I get an exception : "a Polygon needs more than 4 vertices"


Is there something wrong in my code and if yes, how to build a 3 vertices polygon ?


Regards,


Patrick



Patrick, 
  
   In the well known binary and text standard the first and last point need to be the same.  So for a three point polygon you really need a fourth point at the end which is the same point as the first point.  Below is a link to the Wikipedia for more information on the well known standards.  Sorry for the confusion.  In our error message we will modify it to include that the last point should be the first point. 
  
 en.wikipedia.org/wiki/Well-known_text 
  
 David

David, 
  
 I’m very confused with that for many reasons (I do not used WKT but shapefiles) 
  
 - Creating a 3 vertices polygones is working with MS2, MapInfo and autocad 
 - When my user clicks on a feature, I’m displaying the vertice count, will I display 4 for a triangle ? 
  
 Thank you for your help 
 Patrick. 


David, 
  
 I just found that MS3 is adding a vertice to close polygons … 
  
 eg : if I create a 4 vertices square then I’ll get p.vertices.count = 5 … funny. 
 so I think that you’re adding a closing vertice but not for triangle and this sounds as a bug on your side. 
  
 BTW, I’ll add the closing vertice to my triangle and display count-1 to the user. 
  
 Patrick.

Patrick, 



The polygons in Map Suite 3 were modeled off of the open standards that WKB and WKT are based on.  The PolygonShape and Feature classes are abstracted away from the fact you are using a shape file.  For example is shape files specification use three points and Oracle uses four points then when we load them into our specification we will add the fourth point for a shape file.  If you modify that polygon and have it back to the shape file we will remove the extra point when writing to the actual shape file.  In this was all system regardless of how they represent polygons are consistent to the end user and we, inside of the specific layers and feature sources, ensure that in the end we write the appropriate type of polygon structure to the data source. 



In your case knowing that all of our polygons use the WKB open specification then you can subtract one from the result.  The question of how many points does a polygon have all depends on the definition of a polygon.  The point is that out standard goes in line with the open one that is very widely accepted.  You can subtract one from the vertex result if you like to show your user what they expect. 



David





Patrick, 
  
   You may be right that we are adding a point to close it off.  When you load a polygon we defiantly will make sure it is to the specs.  I think we add the code to add the extra point to be nice to the users.  We could have thrown an exception and said that it had to be closed.  Of course when we added the extra close code we might have introduced a bug there.  Thanks for reporting it.  In some ways I wish we didn’t add the extra code but we wanted to help. :-)  The only thing is I wonder when we add the extra point.  Hmm, we will have to look at the code and see what is going on there. 
  
 David