Search in sources :

Example 1 with Vertex

use of com.revolsys.geometry.model.vertex.Vertex in project com.revolsys.open by revolsys.

the class ScaledIntegerGriddedDigitalElevation method setElevationNearest.

@SuppressWarnings("unchecked")
public static <G extends Geometry> G setElevationNearest(final Path baseDirectory, final int coordinateSystemId, final int gridCellSize, final int gridSize, final String fileExtension, final G geometry) {
    final GeometryEditor<?> editor = geometry.newGeometryEditor();
    editor.setAxisCount(3);
    for (final Vertex vertex : geometry.vertices()) {
        final double x = vertex.getX();
        final double y = vertex.getY();
        final double elevation = getElevationNearest(baseDirectory, coordinateSystemId, gridCellSize, gridSize, fileExtension, x, y);
        if (!Double.isNaN(elevation)) {
            final int[] vertexId = vertex.getVertexId();
            editor.setZ(vertexId, elevation);
        }
    }
    return (G) editor.newGeometry();
}
Also used : Vertex(com.revolsys.geometry.model.vertex.Vertex)

Example 2 with Vertex

use of com.revolsys.geometry.model.vertex.Vertex in project com.revolsys.open by revolsys.

the class BufferCurveMaximumDistanceFinder method computeMaxVertexDistance.

private void computeMaxVertexDistance(final Geometry curve) {
    final PointPairDistance maxPtDist = new PointPairDistance();
    final PointPairDistance minPtDist = new PointPairDistance();
    for (final Vertex vertex : curve.vertices()) {
        minPtDist.initialize();
        DistanceToPointFinder.computeDistance(this.inputGeom, vertex, minPtDist);
        maxPtDist.setMaximum(minPtDist);
    }
    this.maxPtDist.setMaximum(maxPtDist);
}
Also used : PointPairDistance(com.revolsys.geometry.algorithm.distance.PointPairDistance) Vertex(com.revolsys.geometry.model.vertex.Vertex)

Example 3 with Vertex

use of com.revolsys.geometry.model.vertex.Vertex in project com.revolsys.open by revolsys.

the class PolygonTest method testVertices.

@Test
public void testVertices() {
    final List<Point> allCoordinates = new ArrayList<>();
    allCoordinates.addAll(EXTERIOR_1);
    allCoordinates.addAll(INTERIOR_2);
    final Polygon polygon = WITH_HOLE;
    int i = 0;
    for (final Vertex vertex : polygon.vertices()) {
        final Point point = allCoordinates.get(i);
        Assert.assertEquals(point, vertex);
        i++;
    }
    Assert.assertEquals(new PointDoubleXY(0.0, 0.0), polygon.getVertex(0, 0));
    Assert.assertNull("VertexIndex out of range", polygon.getVertex(0, 6));
    Assert.assertNull("VertexIndex out of range", polygon.getVertex(1, 6));
    Assert.assertNull("RingIndex Negative", polygon.getVertex(-1, 0));
    Assert.assertNull("RingIndex out of range", polygon.getVertex(2, 0));
}
Also used : Vertex(com.revolsys.geometry.model.vertex.Vertex) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point) Test(org.junit.Test)

Example 4 with Vertex

use of com.revolsys.geometry.model.vertex.Vertex in project com.revolsys.open by revolsys.

the class PackedCoordinateUtil method getPackedBytes.

public static byte[] getPackedBytes(final Double xOffset, final Double yOffset, final Double xyScale, final boolean hasZ, final Double zOffset, final Double zScale, final boolean hasM, final Double mScale, final Double mOffset, final List<List<Geometry>> parts) {
    final int packedByteLength = 0;
    byte dimensionFlag = 0;
    final byte annotationDimension = 0;
    final byte shapeFlags = 0;
    if (hasZ) {
        dimensionFlag |= 1;
    }
    if (hasM) {
        dimensionFlag |= 2;
    }
    final PackedIntegerOutputStream out = new PackedIntegerOutputStream();
    out.writeLong5(packedByteLength);
    out.writeLong(dimensionFlag);
    out.writeLong(annotationDimension);
    out.writeLong(shapeFlags);
    // Write x,y for all parts
    long previousX = Math.round(xOffset * xyScale);
    long previousY = Math.round(yOffset * xyScale);
    boolean first = true;
    for (final List<Geometry> part : parts) {
        if (first) {
            first = false;
        } else {
            out.writeLong(-1 - previousX);
            out.writeLong(-previousY);
            previousX = -1;
            previousY = 0;
        }
        for (final Geometry component : part) {
            for (final Vertex vertex : component.vertices()) {
                previousX = writeCoordinate(out, vertex, previousX, xyScale, 0);
                previousY = writeCoordinate(out, vertex, previousY, xyScale, 1);
            }
        }
    }
    // Write z for all parts
    if (hasZ) {
        writeMultiCoordinates(out, parts, 2, zOffset, zScale);
    }
    // Write m for all parts
    if (hasM) {
        writeMultiCoordinates(out, parts, 3, mOffset, mScale);
    }
    return out.toByteArray();
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Vertex(com.revolsys.geometry.model.vertex.Vertex) Point(com.revolsys.geometry.model.Point)

Example 5 with Vertex

use of com.revolsys.geometry.model.vertex.Vertex in project com.revolsys.open by revolsys.

the class OgrRecordWriter method toOgrGeometry.

protected org.gdal.ogr.Geometry toOgrGeometry(final Geometry geometry, final int geometryType, final int axisCount) {
    final org.gdal.ogr.Geometry ogrGeometry = new org.gdal.ogr.Geometry(geometryType);
    if (!geometry.isEmpty()) {
        switch(geometryType) {
            case 1:
            case 0x80000000 + 1:
                {
                    final Point point = (Point) geometry;
                    final double x = point.getX();
                    final double y = point.getY();
                    if (axisCount == 2) {
                        ogrGeometry.AddPoint(x, y);
                    } else {
                        final double z = point.getZ();
                        ogrGeometry.AddPoint(x, y, z);
                    }
                }
                break;
            case 2:
            case 0x80000000 + 2:
                final LineString line = (LineString) geometry;
                final int vertexCount = line.getVertexCount();
                for (int vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
                    final double x = line.getX(vertexIndex);
                    final double y = line.getY(vertexIndex);
                    if (axisCount == 2) {
                        ogrGeometry.AddPoint(x, y);
                    } else {
                        final double z = line.getZ(vertexIndex);
                        ogrGeometry.AddPoint(x, y, z);
                    }
                }
                break;
            case 3:
            case 0x80000000 + 3:
                for (final LinearRing ring : ((Polygon) geometry).rings()) {
                    final org.gdal.ogr.Geometry ogrRing = toOgrGeometry(ring, 101, axisCount);
                    ogrGeometry.AddGeometry(ogrRing);
                }
                break;
            case 4:
                addParts(ogrGeometry, geometry, 1, axisCount);
                break;
            case 0x80000000 + 4:
                addParts(ogrGeometry, geometry, 0x80000000 + 1, axisCount);
                break;
            case 5:
                addParts(ogrGeometry, geometry, 2, axisCount);
                break;
            case 0x80000000 + 5:
                addParts(ogrGeometry, geometry, 0x80000000 + 2, axisCount);
                break;
            case 6:
                addParts(ogrGeometry, geometry, 3, axisCount);
                break;
            case 0x80000000 + 6:
                addParts(ogrGeometry, geometry, 0x80000000 + 3, axisCount);
                break;
            // return this.geometryFactory.geometry(parts);
            case 101:
                for (final Vertex vertex : geometry.vertices()) {
                    final double x = vertex.getX();
                    final double y = vertex.getY();
                    if (axisCount == 2) {
                        ogrGeometry.AddPoint(x, y);
                    } else {
                        final double z = vertex.getZ();
                        ogrGeometry.AddPoint(x, y, z);
                    }
                }
                break;
            default:
                return null;
        }
    }
    if (axisCount == 2) {
        ogrGeometry.FlattenTo2D();
    }
    return ogrGeometry;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Vertex(com.revolsys.geometry.model.vertex.Vertex) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Aggregations

Vertex (com.revolsys.geometry.model.vertex.Vertex)42 Point (com.revolsys.geometry.model.Point)18 Geometry (com.revolsys.geometry.model.Geometry)16 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)14 LineString (com.revolsys.geometry.model.LineString)10 Polygon (com.revolsys.geometry.model.Polygon)6 Segment (com.revolsys.geometry.model.segment.Segment)6 ArrayList (java.util.ArrayList)6 GeometryEditor (com.revolsys.geometry.model.editor.GeometryEditor)4 AbstractVertex (com.revolsys.geometry.model.vertex.AbstractVertex)4 LineStringVertex (com.revolsys.geometry.model.vertex.LineStringVertex)4 BaseCloseable (com.revolsys.io.BaseCloseable)4 CloseLocation (com.revolsys.swing.map.overlay.CloseLocation)4 DataType (com.revolsys.datatype.DataType)3 LinearRing (com.revolsys.geometry.model.LinearRing)3 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)3 LineSegment (com.revolsys.geometry.model.segment.LineSegment)3 MapPanel (com.revolsys.swing.map.MapPanel)3 WebColors (com.revolsys.awt.WebColors)2 Maps (com.revolsys.collection.map.Maps)2