Search in sources :

Example 1 with LineStringDouble

use of com.revolsys.geometry.model.impl.LineStringDouble in project com.revolsys.open by revolsys.

the class EdgeIntersectionList method newSplitEdge.

/**
 * Construct a new new "split edge" with the section of points between
 * (and including) the two intersections.
 * The label for the new edge is the same as the label for the parent edge.
 */
Edge newSplitEdge(final EdgeIntersection ei0, final EdgeIntersection ei1) {
    final int fromIndex = ei0.segmentIndex;
    final int toIndex = ei1.segmentIndex;
    int pointCount = toIndex - fromIndex + 2;
    // if the last intersection point is not equal to the its segment start pt,
    // add it to the points list as well.
    // (This check is needed because the distance metric is not totally
    // reliable!)
    // The check for point equality is 2D only - Z values are ignored
    final double xEnd = ei1.getX();
    final double yEnd = ei1.getY();
    final Edge edge = this.edge;
    final boolean useIntPt1 = ei1.dist > 0.0 || !edge.equalsVertex(toIndex, xEnd, yEnd);
    if (!useIntPt1) {
        pointCount--;
    }
    final double[] coordinates = new double[pointCount * 2];
    int coordinateIndex = 0;
    coordinates[coordinateIndex++] = ei0.getX();
    coordinates[coordinateIndex++] = ei0.getY();
    for (int i = fromIndex + 1; i <= toIndex; i++) {
        final double x = edge.getX(i);
        final double y = edge.getY(i);
        coordinates[coordinateIndex++] = x;
        coordinates[coordinateIndex++] = y;
    }
    if (useIntPt1) {
        coordinates[coordinateIndex++] = xEnd;
        coordinates[coordinateIndex++] = yEnd;
    }
    final LineString line = new LineStringDouble(2, coordinates);
    return new Edge(line, new Label(edge.label));
}
Also used : LineString(com.revolsys.geometry.model.LineString) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Example 2 with LineStringDouble

use of com.revolsys.geometry.model.impl.LineStringDouble in project com.revolsys.open by revolsys.

the class ShapefileGeometryHandler method readMultipointZ.

public Punctual readMultipointZ(final GeometryFactory geometryFactory, final ByteBuffer buffer, final int recordLength) {
    buffer.getDouble();
    buffer.getDouble();
    buffer.getDouble();
    buffer.getDouble();
    final int vertexCount = buffer.getInt();
    final double[] coordinates = readXYCoordinates(buffer, vertexCount, 3);
    buffer.getDouble();
    buffer.getDouble();
    readCoordinates(buffer, vertexCount, 3, coordinates, 2);
    return geometryFactory.punctual(new LineStringDouble(3, coordinates));
}
Also used : Point(com.revolsys.geometry.model.Point) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Example 3 with LineStringDouble

use of com.revolsys.geometry.model.impl.LineStringDouble in project com.revolsys.open by revolsys.

the class ShapefileGeometryUtil method readMultipointM.

public Punctual readMultipointM(final GeometryFactory geometryFactory, final EndianInput in, final int recordLength) throws IOException {
    in.skipBytes(4 * MathUtil.BYTES_IN_DOUBLE);
    final int vertexCount = in.readLEInt();
    final int axisCount = 4;
    final double[] coordinates = readXYCoordinates(in, vertexCount, axisCount);
    in.skipBytes(2 * MathUtil.BYTES_IN_DOUBLE);
    setCoordinatesNaN(coordinates, vertexCount, axisCount, 2);
    readCoordinates(in, vertexCount, axisCount, coordinates, 3);
    return geometryFactory.punctual(new LineStringDouble(axisCount, coordinates));
}
Also used : Point(com.revolsys.geometry.model.Point) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Example 4 with LineStringDouble

use of com.revolsys.geometry.model.impl.LineStringDouble in project com.revolsys.open by revolsys.

the class ShapefileGeometryHandler method readMultipointM.

public Punctual readMultipointM(final GeometryFactory geometryFactory, final ByteBuffer buffer, final int recordLength) {
    buffer.getDouble();
    buffer.getDouble();
    buffer.getDouble();
    buffer.getDouble();
    final int vertexCount = buffer.getInt();
    final int axisCount = 4;
    final double[] coordinates = readXYCoordinates(buffer, vertexCount, axisCount);
    buffer.getDouble();
    buffer.getDouble();
    setCoordinatesNaN(coordinates, vertexCount, axisCount, 2);
    readCoordinates(buffer, vertexCount, axisCount, coordinates, 3);
    return geometryFactory.punctual(new LineStringDouble(axisCount, coordinates));
}
Also used : Point(com.revolsys.geometry.model.Point) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Example 5 with LineStringDouble

use of com.revolsys.geometry.model.impl.LineStringDouble in project com.revolsys.open by revolsys.

the class PackedCoordinateUtil method getPointsMultiPart.

@SuppressWarnings("unused")
private static List<LineString> getPointsMultiPart(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;
            if (previousX == -1 && previousY == 0) {
                final double[] subCoordinates = new double[j * axisCount];
                System.arraycopy(coordinates, 0, subCoordinates, 0, subCoordinates.length);
                pointsList.add(subCoordinates);
                j = 0;
            } else {
                final int xIndex = j * axisCount;
                coordinates[xIndex] = x;
                coordinates[xIndex + 1] = y;
                j++;
            }
        }
        if (coordinates.length == axisCount * j) {
            pointsList.add(coordinates);
        } else {
            final double[] subCoordinates = new double[j * axisCount];
            System.arraycopy(coordinates, 0, subCoordinates, 0, subCoordinates.length);
            pointsList.add(subCoordinates);
        }
        if (hasZ) {
            getPointsMultiPartZorM(in, pointsList, axisCount, 2, zOffset, zScale);
        }
        if (hasM) {
            getPointsMultiPartZorM(in, pointsList, axisCount, 3, mOffset, mScale);
        }
        final List<LineString> lists = new ArrayList<>();
        for (final double[] partCoordinates : pointsList) {
            lists.add(new LineStringDouble(axisCount, partCoordinates));
        }
        return lists;
    } 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) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Aggregations

LineStringDouble (com.revolsys.geometry.model.impl.LineStringDouble)22 Point (com.revolsys.geometry.model.Point)17 LineString (com.revolsys.geometry.model.LineString)10 ArrayList (java.util.ArrayList)7 CoordinatesDistanceComparator (com.revolsys.geometry.model.coordinates.comparator.CoordinatesDistanceComparator)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 BPlusTreeMap (com.revolsys.collection.bplus.BPlusTreeMap)1 IntHashMap (com.revolsys.collection.map.IntHashMap)1 MonotoneChainEdge (com.revolsys.geometry.geomgraph.index.MonotoneChainEdge)1 Edge (com.revolsys.geometry.graph.Edge)1 Node (com.revolsys.geometry.graph.Node)1 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)1 DelegatingLineString (com.revolsys.geometry.model.DelegatingLineString)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Lineal (com.revolsys.geometry.model.Lineal)1 LinearRing (com.revolsys.geometry.model.LinearRing)1 Polygon (com.revolsys.geometry.model.Polygon)1