rust-geo-validator
A trait for MultiPolygon/Polygon geo-types to check for validity according to OGC standards. Validation currently conforms only partially to those rules.
Validation Traits
The current geo/geo-types packages contain no support for validation of Geometries other then succeeding/failing to create a Geometry. This package adds a trait to the MultiPolygon and Polygon type to check for validity according to the OGC specifications (currently a work in progress).
The validation function provided here look for violations of the following rules:
- A polygon may not have less than three points
- A polygon may not have any unclosed rings
- A polygon may not be a multi-polygon (all inner rings must be contained by the outer ring)
- No ring in the polygon may intersect another ring
- No ring in the polygon may intersect itself
- No point on a ring may be touching a line in it or any other ring
- No points may be repeated in a ring
- All points must have valid floating point values
validate()
The is_valid()
trait will return false at the first error and provides no debugging information.
Examples
use polygon;
use Validate;
// Polygon self intersects and has intersecting inner/outer rings
let poly = polygon!;
let valid = poly.validate;
assert_eq!;
validate_detailed
The validate_detailed()
function collects information about where the current MultiPolygon/Polygon is invalid, and returns that information to the caller.
Examples
use polygon;
use Validate;
// Polygon self intersects and has intersecting inner/outer rings
let poly = polygon!;
let valid = poly.validate_detailed;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;