Search in sources :

Example 86 with LinearRing

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

the class OracleSdoGeometryJdbcFieldDefinition method addRingSimple.

private int addRingSimple(final List<LinearRing> rings, final int axisCount, final BigDecimal[] elemInfo, final int type, final BigDecimal[] coordinatesArray, final int elemInfoOffset, final int offset, final long interpretation) {
    if (interpretation == 1) {
        int length;
        if (elemInfoOffset + 3 < elemInfo.length) {
            final long nextOffset = elemInfo[elemInfoOffset + 3].longValue();
            length = (int) (nextOffset - offset);
        } else {
            final int coordinateCount = coordinatesArray.length;
            length = coordinateCount + 1 - offset;
        }
        final double[] coordinates = Numbers.toDoubleArray(coordinatesArray, offset - 1, length);
        final LinearRing ring = this.geometryFactory.linearRing(axisCount, coordinates);
        rings.add(ring);
    } else {
        throw new IllegalArgumentException("Unsupported geometry type " + type + " interpretation " + interpretation);
    }
    return elemInfoOffset + 3;
}
Also used : LinearRing(com.revolsys.geometry.model.LinearRing) Point(com.revolsys.geometry.model.Point)

Example 87 with LinearRing

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

the class PointInRingTest method runPtInRing.

@Override
protected void runPtInRing(final Location expectedLoc, final Point pt, final String wkt) throws Exception {
    // isPointInRing is not defined for pts on boundary
    if (expectedLoc == Location.BOUNDARY) {
        return;
    }
    final Polygon geom = (Polygon) this.geometryFactory.geometry(wkt);
    final boolean expected = expectedLoc == Location.INTERIOR;
    final LinearRing shell = geom.getShell();
    assertEquals(expected, shell.isPointInRing(pt));
}
Also used : Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 88 with LinearRing

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

the class GeometryImplTest method testEqualsExactForLinearRings.

// public void testEquals2() throws Exception {
// Geometry lineString =
// reader.read("LINESTRING(0 0, 0 50, 50 50, 50 0, 0 0)");
// Geometry geometryCollection =
// reader.read("GEOMETRYCOLLECTION ( LINESTRING(0 0 , 0 50), "
// + "LINESTRING(0 50 , 50 50), "
// + "LINESTRING(50 50, 50 0 ), "
// + "LINESTRING(50 0 , 0 0 ))");
// assertTrue(lineString.equals(geometryCollection));
// }
public void testEqualsExactForLinearRings() throws Exception {
    final LinearRing x = this.geometryFactory.linearRing(2, 0.0, 0, 100.0, 0, 100.0, 100, 0.0, 0);
    final LinearRing somethingExactlyEqual = this.geometryFactory.linearRing(2, 0.0, 0, 100.0, 0, 100.0, 100, 0.0, 0);
    final LinearRing somethingNotEqualButSameClass = this.geometryFactory.linearRing(2, 0.0, 0, 100.0, 0, 100.0, 555, 0.0, 0);
    final LinearRing sameClassButEmpty = this.geometryFactory.linearRing((LineString) null);
    final LinearRing anotherSameClassButEmpty = this.geometryFactory.linearRing((LineString) null);
    final CollectionFactory collectionFactory = new CollectionFactory() {

        @Override
        public Geometry newCollection(final Geometry... geometries) {
            return GeometryImplTest.this.geometryFactory.lineal(geometries);
        }
    };
    doTestEqualsExact(x, somethingExactlyEqual, somethingNotEqualButSameClass, sameClassButEmpty, anotherSameClassButEmpty, collectionFactory);
// LineString somethingEqualButNotExactly =
// geometryFactory.createLineString(new Point[] {
// new BaseLasPoint((double)0, 0), new PointDouble((double)100, 0), new
// Coordinate((double)100, 100),
// new BaseLasPoint((double)0, 0) });
// 
// doTestEqualsExact(x, somethingExactlyEqual, somethingEqualButNotExactly,
// somethingNotEqualButSameClass);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 89 with LinearRing

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

the class ArcGisRestServerFeatureReader method parseMultiPolygon.

public static Geometry parseMultiPolygon(final GeometryFactory geometryFactory, final MapEx properties) {
    final List<Polygon> polygons = new ArrayList<>();
    final List<LinearRing> rings = new ArrayList<>();
    final List<List<List<Number>>> paths = properties.getValue("rings", Collections.emptyList());
    for (final List<List<Number>> points : paths) {
        final LinearRing ring = geometryFactory.linearRing(points);
        if (ring.isClockwise()) {
            if (!rings.isEmpty()) {
                final Polygon polygon = geometryFactory.polygon(rings);
                polygons.add(polygon);
            }
            rings.clear();
        }
        rings.add(ring);
    }
    if (!rings.isEmpty()) {
        final Polygon polygon = geometryFactory.polygon(rings);
        polygons.add(polygon);
    }
    return geometryFactory.geometry(polygons);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Polygon(com.revolsys.geometry.model.Polygon) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 90 with LinearRing

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

the class AreaPrecisionPerfTest method main.

public static void main(final String[] args) throws Exception {
    final double originX = 1000000;
    final double originY = 5000000;
    final long start = System.currentTimeMillis();
    for (int nrVertices = 4; nrVertices <= 1000000; nrVertices *= 2) {
        final Point[] coordinates = new Point[nrVertices + 1];
        Point vertex;
        for (int i = 0; i <= nrVertices; i++) {
            vertex = new PointDoubleXY(originX + (1 + Math.sin((float) i / (float) nrVertices * 2 * Math.PI)), originY + (1 + Math.cos((float) i / (float) nrVertices * 2 * Math.PI)));
            coordinates[i] = vertex;
        }
        // close ring
        coordinates[nrVertices] = coordinates[0];
        final LinearRing g1 = GeometryFactory.DEFAULT_3D.linearRing(coordinates);
        final Polygon polygon = GeometryFactory.DEFAULT_3D.polygon(g1);
        // System.out.println(polygon);
        final double area = originalSignedArea(coordinates);
        final double area2 = accurateSignedArea(coordinates);
        final double exactArea = 0.5 * nrVertices * Math.sin(2 * Math.PI / nrVertices);
        final double eps = exactArea - area;
        final double eps2 = exactArea - area2;
    // System.out.println(nrVertices + " orig err: " + eps + " acc err: "
    // + eps2);
    }
// System.out.println("Time: " + (System.currentTimeMillis() - start) /
// 1000.0);
}
Also used : Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Aggregations

LinearRing (com.revolsys.geometry.model.LinearRing)95 Polygon (com.revolsys.geometry.model.Polygon)53 Point (com.revolsys.geometry.model.Point)44 ArrayList (java.util.ArrayList)21 LineString (com.revolsys.geometry.model.LineString)19 Geometry (com.revolsys.geometry.model.Geometry)14 Polygonal (com.revolsys.geometry.model.Polygonal)11 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)9 BoundingBox (com.revolsys.geometry.model.BoundingBox)8 Lineal (com.revolsys.geometry.model.Lineal)7 Punctual (com.revolsys.geometry.model.Punctual)6 List (java.util.List)4 NoSuchElementException (java.util.NoSuchElementException)4 IOException (java.io.IOException)3 MCPointInRing (com.revolsys.geometry.algorithm.MCPointInRing)2 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)2 Vertex (com.revolsys.geometry.model.vertex.Vertex)2 BigDecimal (java.math.BigDecimal)2 PointInRing (com.revolsys.geometry.algorithm.PointInRing)1 EdgeRing (com.revolsys.geometry.geomgraph.EdgeRing)1