Search in sources :

Example 46 with LineString

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

the class NodingValidator method checkCollapses.

private void checkCollapses(final NodedSegmentString ss) {
    final LineString points = ss.getLineString();
    for (int i = 0; i < points.getVertexCount() - 2; i++) {
        final double x1 = points.getX(i);
        final double y1 = points.getY(i);
        final double x2 = points.getX(i + 1);
        final double y2 = points.getY(i + 1);
        final double x3 = points.getX(i + 2);
        final double y3 = points.getY(i + 2);
        checkCollapse(x1, y1, x2, y2, x3, y3);
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point)

Example 47 with LineString

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

the class OrientedCoordinateArray method compareTo.

/**
 * Compares two {@link OrientedCoordinateArray}s for their relative order
 *
 * @return -1 this one is smaller;
 * 0 the two objects are equal;
 * 1 this one is greater
 */
@Override
public int compareTo(final OrientedCoordinateArray oca) {
    final LineString points1 = getPoints();
    final LineString points2 = oca.getPoints();
    final boolean orientation2 = oca.getOrientation();
    final int dir1 = this.orientation ? 1 : -1;
    final int dir2 = orientation2 ? 1 : -1;
    final int vertexCount1 = points1.getVertexCount();
    final int vertexCount2 = points2.getVertexCount();
    final int limit1 = this.orientation ? vertexCount1 : -1;
    final int limit2 = orientation2 ? vertexCount2 : -1;
    int i1 = this.orientation ? 0 : vertexCount1 - 1;
    int i2 = orientation2 ? 0 : vertexCount2 - 1;
    while (true) {
        final int compPt = points1.compareVertex(i1, points2, i2);
        if (compPt != 0) {
            return compPt;
        } else {
            i1 += dir1;
            i2 += dir2;
            final boolean done1 = i1 == limit1;
            final boolean done2 = i2 == limit2;
            if (done1 && !done2) {
                return -1;
            } else if (!done1 && done2) {
                return 1;
            } else if (done1 && done2) {
                return 0;
            }
        }
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString)

Example 48 with LineString

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

the class ScaledNoder method scale.

private Collection<NodedSegmentString> scale(final Collection<NodedSegmentString> segments) {
    final List<NodedSegmentString> result = new ArrayList<>();
    for (final NodedSegmentString segment : segments) {
        final Object data = segment.getData();
        final LineString scale = scale(segment);
        final NodedSegmentString nodedSegmentString = new NodedSegmentString(scale, data);
        result.add(nodedSegmentString);
    }
    return result;
}
Also used : LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList)

Example 49 with LineString

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

the class ShapefileGeometryUtil method writeMCoordinatesRange.

public void writeMCoordinatesRange(final EndianOutput out, final List<LineString> coordinatesList) throws IOException {
    double minM = Double.MAX_VALUE;
    double maxM = -Double.MAX_VALUE;
    for (final LineString ring : coordinatesList) {
        for (int i = 0; i < ring.getVertexCount(); i++) {
            double m = ring.getCoordinate(i, 2);
            if (Double.isNaN(m)) {
                m = 0;
            }
            minM = Math.min(m, minM);
            maxM = Math.max(m, maxM);
        }
    }
    if (minM == Double.MAX_VALUE && maxM == -Double.MAX_VALUE) {
        out.writeLEDouble(0);
        out.writeLEDouble(0);
    } else {
        out.writeLEDouble(minM);
        out.writeLEDouble(maxM);
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point)

Example 50 with LineString

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

the class ShapefileGeometryUtil method readPolylineZM.

public Geometry readPolylineZM(GeometryFactory geometryFactory, final EndianInput in, final int recordLength) throws IOException {
    in.skipBytes(4 * MathUtil.BYTES_IN_DOUBLE);
    final int geometryCount = in.readLEInt();
    final int vertexCount = in.readLEInt();
    if (22 + geometryCount * 2 + vertexCount * 12 == recordLength) {
        geometryFactory = geometryFactory.convertAxisCount(3);
        return readPolylineZ(geometryFactory, in, geometryCount, vertexCount, 3);
    } else {
        final int axisCount = 4;
        if (geometryCount == 1) {
            in.readLEInt();
            final double[] coordinates = readXYCoordinates(in, vertexCount, axisCount);
            in.skipBytes(2 * MathUtil.BYTES_IN_DOUBLE);
            readCoordinates(in, vertexCount, axisCount, coordinates, 2);
            in.skipBytes(2 * MathUtil.BYTES_IN_DOUBLE);
            readCoordinates(in, vertexCount, axisCount, coordinates, 3);
            return geometryFactory.lineString(axisCount, coordinates);
        } else {
            final int[] partIndex = new int[geometryCount + 1];
            partIndex[geometryCount] = vertexCount;
            for (int i = 0; i < partIndex.length - 1; i++) {
                partIndex[i] = in.readLEInt();
            }
            final List<double[]> coordinatesList = new ArrayList<>();
            for (int i = 0; i < partIndex.length - 1; i++) {
                final int startIndex = partIndex[i];
                final int endIndex = partIndex[i + 1];
                final int numCoords = endIndex - startIndex;
                final double[] coordinates = readXYCoordinates(in, numCoords, axisCount);
                coordinatesList.add(coordinates);
            }
            in.skipBytes(2 * MathUtil.BYTES_IN_DOUBLE);
            for (int i = 0; i < partIndex.length - 1; i++) {
                final double[] coordinates = coordinatesList.get(i);
                readCoordinates(in, coordinates.length / 4, axisCount, coordinates, 2);
            }
            in.skipBytes(2 * MathUtil.BYTES_IN_DOUBLE);
            for (int i = 0; i < partIndex.length - 1; i++) {
                final double[] coordinates = coordinatesList.get(i);
                readCoordinates(in, coordinates.length / 4, axisCount, coordinates, 3);
            }
            final List<LineString> lines = new ArrayList<>();
            for (final double[] coordinates : coordinatesList) {
                lines.add(geometryFactory.lineString(axisCount, coordinates));
            }
            return geometryFactory.lineal(lines);
        }
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point)

Aggregations

LineString (com.revolsys.geometry.model.LineString)380 Point (com.revolsys.geometry.model.Point)184 Geometry (com.revolsys.geometry.model.Geometry)65 ArrayList (java.util.ArrayList)62 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)51 Polygon (com.revolsys.geometry.model.Polygon)37 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)24 Edge (com.revolsys.geometry.graph.Edge)22 List (java.util.List)22 BoundingBox (com.revolsys.geometry.model.BoundingBox)20 Lineal (com.revolsys.geometry.model.Lineal)20 Test (org.junit.Test)20 LinearRing (com.revolsys.geometry.model.LinearRing)19 Record (com.revolsys.record.Record)17 Iterator (java.util.Iterator)14 LineStringEditor (com.revolsys.geometry.model.editor.LineStringEditor)13 Punctual (com.revolsys.geometry.model.Punctual)12 LineStringDouble (com.revolsys.geometry.model.impl.LineStringDouble)12 LineSegment (com.revolsys.geometry.model.segment.LineSegment)10 Polygonal (com.revolsys.geometry.model.Polygonal)9