Search in sources :

Example 26 with GeometryFactory

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

the class BoundingBoxDoubleXY method toRectangle.

@Override
public RectangleXY toRectangle() {
    final double width = getWidth();
    final double height = getHeight();
    final GeometryFactory geometryFactory = getGeometryFactory();
    return geometryFactory.newRectangle(this.minX, this.minY, width, height);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory)

Example 27 with GeometryFactory

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

the class PolygonEditor method newGeometry.

@Override
public Polygon newGeometry() {
    final int ringCount = this.editors.size();
    final LinearRing[] rings = new LinearRing[ringCount];
    int ringIndex = 0;
    for (final LinearRingEditor editor : this.editors) {
        rings[ringIndex++] = editor.newGeometry();
    }
    final GeometryFactory geometryFactory = getGeometryFactory();
    if (this.polygon == null) {
        return geometryFactory.polygon(rings);
    } else {
        return this.polygon.newPolygon(geometryFactory, rings);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LinearRing(com.revolsys.geometry.model.LinearRing) Point(com.revolsys.geometry.model.Point)

Example 28 with GeometryFactory

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

the class PolygonEditor method getCurrentGeometry.

@Override
public Geometry getCurrentGeometry() {
    final GeometryFactory geometryFactory = getGeometryFactory();
    if (isEmpty()) {
        return geometryFactory.polygon();
    }
    final List<LinearRing> rings = new ArrayList<>();
    final List<Geometry> geometries = new ArrayList<>();
    boolean shell = true;
    for (final LinearRingEditor editor : this.editors) {
        final Geometry ringGeometry = editor.getCurrentGeometry();
        if (ringGeometry instanceof LinearRing) {
            final LinearRing ring = (LinearRing) ringGeometry;
            if (shell || !rings.isEmpty()) {
                rings.add(ring);
            } else {
                geometries.add(ringGeometry);
            }
        } else {
            geometries.add(ringGeometry);
        }
        shell = false;
    }
    if (!rings.isEmpty()) {
        final Polygon polygon = geometryFactory.polygon(rings);
        if (geometries.isEmpty()) {
            return polygon;
        } else {
            geometries.add(polygon);
        }
    }
    return geometryFactory.geometry(geometries);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ArrayList(java.util.ArrayList) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon)

Example 29 with GeometryFactory

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

the class Buffer method buffer.

private static Geometry buffer(final Noder noder, final GeometryFactory precisionModel, final Geometry geometry, final double distance, final BufferParameters parameters) {
    final GeometryFactory geometryFactory = geometry.getGeometryFactory();
    final OffsetCurveSetBuilder curveSetBuilder = new OffsetCurveSetBuilder(geometry, distance, precisionModel, parameters);
    final List<NodedSegmentString> curves = curveSetBuilder.getCurves();
    if (curves.size() == 0) {
        return geometryFactory.polygon();
    } else {
        final EdgeList edgeList = new EdgeList();
        computeNodedEdges(noder, edgeList, curves);
        final PlanarGraph graph = new PlanarGraph(new OverlayNodeFactory());
        final List<Edge> edges = edgeList.getEdges();
        graph.addEdges(edges);
        final List<BufferSubgraph> subgraphList = newSubgraphs(graph);
        final PolygonBuilder polyBuilder = new PolygonBuilder(geometryFactory);
        buildSubgraphs(subgraphList, polyBuilder);
        final List<Polygon> polygons = polyBuilder.getPolygons();
        if (polygons.size() == 0) {
            return geometryFactory.polygon();
        } else {
            final Geometry resultGeom = geometryFactory.buildGeometry(polygons);
            return resultGeom;
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) OverlayNodeFactory(com.revolsys.geometry.operation.overlay.OverlayNodeFactory) EdgeList(com.revolsys.geometry.geomgraph.EdgeList) Geometry(com.revolsys.geometry.model.Geometry) PlanarGraph(com.revolsys.geometry.geomgraph.PlanarGraph) NodedSegmentString(com.revolsys.geometry.noding.NodedSegmentString) Polygon(com.revolsys.geometry.model.Polygon) Edge(com.revolsys.geometry.geomgraph.Edge) DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) PolygonBuilder(com.revolsys.geometry.operation.overlay.PolygonBuilder)

Example 30 with GeometryFactory

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

the class Buffer method buffer.

/**
 * Comutes the buffer for a geometry for a given buffer distance
 * and accuracy of approximation.
 *
 * @param g the geometry to buffer
 * @param distance the buffer distance
 * @param parameters the buffer parameters to use
 * @return the buffer of the input geometry
 */
@SuppressWarnings("unchecked")
public static <G extends Geometry> G buffer(final Geometry geometry, final double distance, final BufferParameters parameters) {
    final GeometryFactory geometryFactory = geometry.getGeometryFactory();
    try {
        final MCIndexNoder noder = new MCIndexNoder();
        final LineIntersector li = new RobustLineIntersector(geometryFactory.getScaleXY());
        noder.setSegmentIntersector(new IntersectionAdder(li));
        return (G) buffer(noder, geometryFactory, geometry, distance, parameters);
    } catch (final RuntimeException e) {
        if (geometryFactory.isFloating()) {
            return (G) bufferReducedPrecision(geometry, distance, parameters);
        } else {
            return (G) bufferFixedPrecision(geometryFactory, geometry, distance, parameters);
        }
    }
}
Also used : LineIntersector(com.revolsys.geometry.algorithm.LineIntersector) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) MCIndexNoder(com.revolsys.geometry.noding.MCIndexNoder) RobustLineIntersector(com.revolsys.geometry.algorithm.RobustLineIntersector) IntersectionAdder(com.revolsys.geometry.noding.IntersectionAdder)

Aggregations

GeometryFactory (com.revolsys.geometry.model.GeometryFactory)360 Point (com.revolsys.geometry.model.Point)142 Geometry (com.revolsys.geometry.model.Geometry)72 BoundingBox (com.revolsys.geometry.model.BoundingBox)70 LineString (com.revolsys.geometry.model.LineString)61 ArrayList (java.util.ArrayList)45 DataType (com.revolsys.datatype.DataType)25 FieldDefinition (com.revolsys.record.schema.FieldDefinition)24 Polygon (com.revolsys.geometry.model.Polygon)22 List (java.util.List)18 RecordDefinition (com.revolsys.record.schema.RecordDefinition)17 Test (org.junit.Test)16 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)15 Vertex (com.revolsys.geometry.model.vertex.Vertex)14 Record (com.revolsys.record.Record)14 IOException (java.io.IOException)13 PathName (com.revolsys.io.PathName)12 LinearRing (com.revolsys.geometry.model.LinearRing)10 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)10 QuadEdgeDelaunayTinBuilder (com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder)8