Search in sources :

Example 36 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class GeometryImplTest method testEqualsExactForPolygons.

public void testEqualsExactForPolygons() throws Exception {
    final Polygon x = (Polygon) this.geometryFactory.geometry("POLYGON ((0 0, 0 50, 50 50, 50 0, 0 0))");
    final Polygon somethingExactlyEqual = (Polygon) this.geometryFactory.geometry("POLYGON ((0 0, 0 50, 50 50, 50 0, 0 0))");
    final Polygon somethingNotEqualButSameClass = (Polygon) this.geometryFactory.geometry("POLYGON ((50 50, 50 0, 0 0, 0 50, 50 50))");
    final Polygon sameClassButEmpty = (Polygon) this.geometryFactory.geometry("POLYGON EMPTY");
    final Polygon anotherSameClassButEmpty = (Polygon) this.geometryFactory.geometry("POLYGON EMPTY");
    final CollectionFactory collectionFactory = new CollectionFactory() {

        @Override
        public Geometry newCollection(final Geometry... geometries) {
            return GeometryImplTest.this.geometryFactory.polygonal((Object[]) geometries);
        }
    };
    doTestEqualsExact(x, somethingExactlyEqual, somethingNotEqualButSameClass, sameClassButEmpty, anotherSameClassButEmpty, collectionFactory);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Polygon(com.revolsys.geometry.model.Polygon)

Example 37 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class TriangleTest method checkAcute.

public void checkAcute(final String wkt, final boolean expectedValue) throws Exception {
    final Polygon g = (Polygon) this.geometryFactory.geometry(wkt);
    final TriangleImpl t = newTriangle(g);
    final boolean isAcute = t.isAcute();
    // System.out.println("isAcute = " + isAcute);
    assertEquals(expectedValue, isAcute);
}
Also used : TriangleImpl(com.revolsys.geometry.model.util.TriangleImpl) Polygon(com.revolsys.geometry.model.Polygon)

Example 38 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class CascadedPolygonUnionTester method unionIterated.

public Geometry unionIterated(final Collection<? extends Polygon> polygons) {
    Geometry unionAll = null;
    int count = 0;
    for (final Polygon polygon : polygons) {
        if (unionAll == null) {
            unionAll = polygon.clone();
        } else {
            unionAll = unionAll.union(polygon);
        }
        count++;
        if (count % 100 == 0) {
            System.out.print(".");
        }
    }
    return unionAll;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Polygon(com.revolsys.geometry.model.Polygon)

Example 39 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class RayCrossingCounterTest method runPtInRing.

@Override
protected void runPtInRing(final Location expectedLoc, final Point pt, final String wkt) throws Exception {
    final Polygon geom = (Polygon) this.geometryFactory.geometry(wkt);
    assertEquals(expectedLoc, RayCrossingCounter.locatePointInRing(pt, geom.getShell()));
}
Also used : Polygon(com.revolsys.geometry.model.Polygon)

Example 40 with Polygon

use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.

the class ArcSdeStGeometryFieldDefinition method getParts.

public static List<List<Geometry>> getParts(final Geometry geometry) {
    final List<List<Geometry>> partsList = new ArrayList<>();
    if (geometry != null) {
        final ClockDirection expectedRingOrientation = ClockDirection.COUNTER_CLOCKWISE;
        for (final Geometry part : geometry.geometries()) {
            if (!part.isEmpty()) {
                if (part instanceof Point) {
                    final Point point = (Point) part;
                    partsList.add(Collections.<Geometry>singletonList(point));
                } else if (part instanceof LineString) {
                    final LineString line = (LineString) part;
                    partsList.add(Collections.<Geometry>singletonList(line));
                } else if (part instanceof Polygon) {
                    final Polygon polygon = (Polygon) part;
                    final List<Geometry> ringList = new ArrayList<>();
                    ClockDirection partExpectedRingOrientation = expectedRingOrientation;
                    for (LinearRing ring : polygon.rings()) {
                        final ClockDirection ringOrientation = ring.getClockDirection();
                        if (ringOrientation != partExpectedRingOrientation) {
                            ring = ring.reverse();
                        }
                        ringList.add(ring);
                        if (partExpectedRingOrientation == expectedRingOrientation) {
                            partExpectedRingOrientation = expectedRingOrientation.opposite();
                        }
                    }
                    partsList.add(ringList);
                }
            }
        }
    }
    return partsList;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing) ClockDirection(com.revolsys.geometry.model.ClockDirection)

Aggregations

Polygon (com.revolsys.geometry.model.Polygon)147 Point (com.revolsys.geometry.model.Point)66 LinearRing (com.revolsys.geometry.model.LinearRing)54 LineString (com.revolsys.geometry.model.LineString)39 Geometry (com.revolsys.geometry.model.Geometry)34 ArrayList (java.util.ArrayList)30 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)22 Polygonal (com.revolsys.geometry.model.Polygonal)17 BoundingBox (com.revolsys.geometry.model.BoundingBox)14 Punctual (com.revolsys.geometry.model.Punctual)12 Test (org.junit.Test)12 Lineal (com.revolsys.geometry.model.Lineal)11 BaseCloseable (com.revolsys.io.BaseCloseable)7 List (java.util.List)7 PolygonEditor (com.revolsys.geometry.model.editor.PolygonEditor)6 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)6 Vertex (com.revolsys.geometry.model.vertex.Vertex)6 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)3 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)3 Graphics2D (java.awt.Graphics2D)3