[][src]Trait geo_validator::Validate

pub trait Validate<T> where
    T: Float
{ fn validate(&self) -> bool;
fn validate_detailed(&self) -> ValidationErrors<T>; }

Required methods

fn validate(&self) -> bool

Validate a Multipolygon/Polygon Geometry according to the OGC rules

This function is non-trivial from a computational perspective. It returns false at the first point it hits a violation of the OCG rules for a polygon.

  • 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

Examples

use geo_types::polygon;
use geo_validator::Validate;

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);

fn validate_detailed(&self) -> ValidationErrors<T>

Validate a Multipolygon/Polygon Geometry according to the OGC rules with a detailed report of errors

This function is non-trivial from a computational perspective. It returns a large struct detailing all errors found in the submitted Geometry.

  • A polygon may not have less than three points
  • A polygon may not have any unclosed rings
  • 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

Examples

use geo_types::polygon;
use geo_validator::Validate;

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);
Loading content...

Implementations on Foreign Types

impl<T> Validate<T> for MultiPolygon<T> where
    T: Float
[src]

Polygons

impl<T> Validate<T> for Polygon<T> where
    T: Float
[src]

Loading content...

Implementors

Loading content...