Error: java.lang.IllegalArgumentException error with a new triangular feature
When a polygon feature with three vertices is added to a shapefile, the following error message may occur:
However, the same code works if the feature to be added has four or more vertices.
The polygon boundary is not closed. The boundary is closed automatically if the number of vertices is 4 or more.
Solution or Workaround
Close a polygon boundary with these steps:
- Set the number of points to number of vertices + 1.
- Get x, y coordinates for each vertex and set them to the polygon at respective indices.
- Set the first point again at index = "number of vertices".
//get the vertices
//number of vertices
int num = 3;
//read shapefile and get shape field
ShpFile shpfile=new ShpFile("D:/temp/testpoly.shp");
PolygonShp polyshp= (PolygonShp)shpfile.getField();
//set number of points as number+1
//add first point at index=number of vertices
The example code uses classes from MapObjects Java 1.0.1. For MapObjects Java 2.0, use corresponding classes from this version.
Last Published: 5/5/2016
Article ID: 000005610
Software: MapObjects-Java 2.0.1, 2.0, 1.0.1, 1.0