| Total # points | # points in shell | # holes |
| 598,093 | 150,781 | 6,937 |
The WKT file for this polygon is over 20 Meg in size!
This image is taken from a popular GIS application. The application loaded and displayed the polygon without displaying any error messages, even though (as we discovered) this polygon in fact contains a topology error.
isValid() function to validate the correctness of
Geometries. In the case of validating polygons, several potentially expensive
tests are performed to check for line segment intersections and to test that
holes are inside the polygon shell. If done using naive algorithms these tests
are O(n2
), which results in extremely long processing times for large inputs. JTS uses
spatial indexing techniques to greatly increase the speed of the intersection
and point-in-polygon algorithms.
The Java code to read the WKT datafiles and perform the validation with JTS is quite simple:
FileReader fRdr = new FileReader("largeIntersectPoly.wkt.txt");
Geometry geom = wktRdr.read(fRdr);
fRdr.close();
IsValidOp validOp = new IsValidOp(geom);
TopologyValidationError err = validOp.getValidationError();
if (err != null) System.out.println(err);
|
We used a series of large polygons to test the performance of the JTS isValid()
function. Statistics on the polygons used and their processing times are shown
below:
One immediate observation is WKT is not the ideal format for storing large amounts of spatial data! The validation processing times themselves are very respectable.
| Self-intersection at or near point (1228528.7382695903, 1589070.7373000782, NaN) |
Because this polygon is so large, it is not possible to load it directly into the JTS TestBuilder. However, by cutting out the portion containing the error into an extract file it is possible to use the TestBuilder to validate the extracted polygon and display the location of the self-intersection.
Downloadable Files