Search in sources :

Example 21 with LinearRing

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

the class GeometryTestFactory method newSineStar.

public static Polygon newSineStar(final GeometryFactory fact, final double basex, final double basey, final double size, final double armLen, final int nArms, final int nPts) {
    final Point[] pts = newSineStar(basex, basey, size, armLen, nArms, nPts);
    final LinearRing ring = fact.linearRing(pts);
    final Polygon poly = fact.polygon(ring);
    return poly;
}
Also used : Point(com.revolsys.geometry.model.Point) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon)

Example 22 with LinearRing

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

the class GeometryTestFactory method newBox.

public static Polygon newBox(final GeometryFactory fact, final double minx, final double miny, final int nSide, final double segLen) {
    final double[] coordinates = newBox(minx, minx, nSide, segLen);
    final LinearRing ring = fact.linearRing(2, coordinates);
    final Polygon poly = fact.polygon(ring);
    return poly;
}
Also used : LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon)

Example 23 with LinearRing

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

the class LineStringImplTest method testIsClosed.

public void testIsClosed() throws Exception {
    final LineString l = (LineString) this.geometryFactory.geometry("LINESTRING EMPTY");
    assertTrue(l.isEmpty());
    assertTrue(!l.isClosed());
    final LinearRing r = this.geometryFactory.linearRing();
    assertTrue(r.isEmpty());
    assertTrue(r.isClosed());
    final Lineal m = this.geometryFactory.lineal(l, r);
    assertTrue(!m.isClosed());
    final Lineal m2 = this.geometryFactory.lineal(r);
    assertTrue(m2.isClosed());
}
Also used : Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) LinearRing(com.revolsys.geometry.model.LinearRing)

Example 24 with LinearRing

use of com.revolsys.geometry.model.LinearRing 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)

Example 25 with LinearRing

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

the class PackedCoordinateUtil method getPolygonRings.

@SuppressWarnings("unused")
private static List<LinearRing> getPolygonRings(final GeometryFactory geometryFactory, final int vertexCount, final Double xOffset, final Double yOffset, final Double xyScale, final Double zOffset, final Double zScale, final Double mOffset, final Double mScale, final InputStream inputStream) {
    try (final PackedIntegerInputStream in = new PackedIntegerInputStream(inputStream)) {
        final List<double[]> pointsList = new ArrayList<>();
        final long packedByteLength = in.readLong5();
        final long dimensionFlag = in.readLong();
        final int annotationDimension = in.read();
        final int shapeFlags = in.read();
        final boolean hasZ = (dimensionFlag & 0x01) == 0x01;
        final boolean hasM = (dimensionFlag & 0x02) == 0x02;
        int axisCount;
        if (hasM) {
            axisCount = 4;
        } else if (hasZ) {
            axisCount = 3;
        } else {
            axisCount = 2;
        }
        final double[] coordinates = new double[vertexCount * axisCount];
        long previousX = Math.round(xOffset * xyScale);
        long previousY = Math.round(yOffset * xyScale);
        int j = 0;
        for (int i = 0; i < vertexCount; i++) {
            final long deltaX = in.readLong();
            final long deltaY = in.readLong();
            previousX = previousX + deltaX;
            previousY = previousY + deltaY;
            final double x = previousX / xyScale;
            final double y = previousY / xyScale;
            final int xIndex = j * axisCount;
            coordinates[xIndex] = x;
            coordinates[xIndex + 1] = y;
            if (j > 0 && i < vertexCount - 1) {
                if (coordinates[0] == x && coordinates[1] == y) {
                    if (j > 2) {
                        final double[] subCoordinates = new double[xIndex + axisCount];
                        System.arraycopy(coordinates, 0, subCoordinates, 0, subCoordinates.length);
                        pointsList.add(subCoordinates);
                    }
                    j = 0;
                } else {
                    j++;
                }
            } else {
                j++;
            }
        }
        if (j > 2) {
            final int numCoordinates = j * axisCount;
            if (numCoordinates == coordinates.length) {
                pointsList.add(coordinates);
            } else {
                final double[] subCoordinates = new double[numCoordinates];
                System.arraycopy(coordinates, 0, subCoordinates, 0, subCoordinates.length);
                pointsList.add(subCoordinates);
            }
        }
        if (hasZ) {
            getPolygonPointsZorM(in, pointsList, axisCount, 2, zOffset, zScale);
        }
        if (hasM) {
            getPolygonPointsZorM(in, pointsList, axisCount, 3, mOffset, mScale);
        }
        final List<LinearRing> rings = new ArrayList<>();
        for (final double[] partCoordinates : pointsList) {
            rings.add(geometryFactory.linearRing(axisCount, partCoordinates));
        }
        return rings;
    } catch (final IOException e) {
        throw new RuntimeException("Error reading coordinates", e);
    } finally {
        FileUtil.closeSilent(inputStream);
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) LinearRing(com.revolsys.geometry.model.LinearRing) 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