Crates.io | geo-validator |
lib.rs | geo-validator |
version | 0.1.3 |
source | src |
created_at | 2020-04-15 15:02:49.120453 |
updated_at | 2020-04-21 10:41:14.95089 |
description | Functionality to validate geo-types MultiPolygon/Polgon according to the OGC rules |
homepage | https://gitlab.com/bronsonbdevost/rust-geo-svg |
repository | https://gitlab.com/bronsonbdevost/rust-geo-svg |
max_upload_size | |
id | 230533 |
size | 31,217 |
A trait for MultiPolygon/Polygon geo-types to check for validity according to OGC standards. Validation currently conforms only partially to those rules.
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:
The is_valid()
trait will return false at the first error and provides no debugging information.
use geo_types::polygon;
use geo_validator::Validate;
// Polygon self intersects and has intersecting inner/outer rings
let poly = polygon!(
exterior: [
(x: 0., y: 0.),
(x: 0., y: 200.),
(x: 200., y: 0.),
(x: 200., y: 200.),
],
interiors: [
[
(x: 10., y: 20.),
(x: 50., y: 20.),
(x: 20., y: 50.),
(x: 50., y: 50.),
],
],
);
let valid = poly.validate();
assert_eq!(valid, false);
The validate_detailed()
function collects information about where the current MultiPolygon/Polygon is invalid, and returns that information to the caller.
use geo_types::polygon;
use geo_validator::Validate;
// Polygon self intersects and has intersecting inner/outer rings
let poly = polygon!(
exterior: [
(x: 0., y: 0.),
(x: 0., y: 200.),
(x: 200., y: 0.),
(x: 200., y: 200.),
],
interiors: [
[
(x: 10., y: 20.),
(x: 50., y: 20.),
(x: 20., y: 50.),
(x: 50., y: 50.),
],
],
);
let valid = poly.validate_detailed();
assert_eq!(valid.valid, false);
assert_eq!(valid.ring_intersects_other_ring.len(), 3);
assert_eq!(valid.self_intersections.len(), 2);
assert_eq!(valid.point_touching_line.len(), 1);
assert_eq!(valid.ring_intersects_other_ring[0].x, 20_f64);
assert_eq!(valid.ring_intersects_other_ring[0].y, 20_f64);
assert_eq!(valid.ring_intersects_other_ring[1].x, 35_f64);
assert_eq!(valid.ring_intersects_other_ring[1].y, 35_f64);
assert_eq!(valid.ring_intersects_other_ring[2].x, 50_f64);
assert_eq!(valid.ring_intersects_other_ring[2].y, 50_f64);
assert_eq!(valid.self_intersections[0].x, 100_f64);
assert_eq!(valid.self_intersections[0].y, 100_f64);
assert_eq!(valid.self_intersections[1].x, 32.857142857142854_f64);
assert_eq!(valid.self_intersections[1].y, 37.142857142857146_f64);
assert_eq!(valid.point_touching_line[0].x, 50_f64);
assert_eq!(valid.point_touching_line[0].y, 50_f64);