Search in sources :

Example 91 with GeometryFactory

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

the class SimpleRecordConveter method convert.

@Override
public Record convert(final Record sourceObject) {
    final Record targetObject = this.factory.newRecord(this.recordDefinition);
    final Geometry sourceGeometry = sourceObject.getGeometry();
    final GeometryFactory geometryFactory = sourceGeometry.getGeometryFactory();
    final Geometry targetGeometry = geometryFactory.geometry(sourceGeometry);
    targetObject.setGeometryValue(targetGeometry);
    for (final SourceToTargetProcess<Record, Record> processor : this.processors) {
        processor.process(sourceObject, targetObject);
    }
    return targetObject;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Record(com.revolsys.record.Record)

Example 92 with GeometryFactory

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

the class CascadedPolygonUnion method restrictToPolygons.

/**
 * Computes a {@link Polygonal} containing only {@link Polygonal} components.
 * Extracts the {@link Polygon}s from the input
 * and returns them as an appropriate {@link Polygonal} geometry.
 * <p>
 * If the input is already <tt>Polygonal</tt>, it is returned unchanged.
 * <p>
 * A particular use case is to filter out non-polygonal components
 * returned from an overlay operation.
 *
 * @param geometry the geometry to filter
 * @return a Polygonal geometry
 */
private static Polygonal restrictToPolygons(final Geometry geometry) {
    if (geometry instanceof Polygonal) {
        return (Polygonal) geometry;
    } else {
        final List<Polygon> polygons = geometry.getGeometries(Polygon.class);
        if (polygons.size() == 1) {
            return polygons.get(0);
        }
        final GeometryFactory geometryFactory = geometry.getGeometryFactory();
        return geometryFactory.polygonal(polygons);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Polygonal(com.revolsys.geometry.model.Polygonal) Polygon(com.revolsys.geometry.model.Polygon)

Example 93 with GeometryFactory

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

the class UnaryUnionOp method union.

public static Geometry union(final Punctual punctual, final Geometry otherGeom) {
    final PointLocator locater = new PointLocator();
    Set<Geometry> exteriorGeometries = null;
    for (final Point point : punctual.points()) {
        final Location loc = locater.locate(otherGeom, point);
        if (loc == Location.EXTERIOR) {
            if (exteriorGeometries == null) {
                exteriorGeometries = new TreeSet<>();
            }
            exteriorGeometries.add(point);
        }
    }
    if (exteriorGeometries == null) {
        return otherGeom;
    } else {
        for (final Geometry geometry : otherGeom.geometries()) {
            exteriorGeometries.add(geometry);
        }
        final GeometryFactory geomFactory = otherGeom.getGeometryFactory();
        return geomFactory.geometry(exteriorGeometries);
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) PointLocator(com.revolsys.geometry.algorithm.PointLocator) Point(com.revolsys.geometry.model.Point) Location(com.revolsys.geometry.model.Location)

Example 94 with GeometryFactory

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

the class MinimumClearance method compute.

private void compute() {
    if (!this.calculated) {
        this.calculated = true;
        this.minClearance = Double.MAX_VALUE;
        if (!this.geometry.isEmpty()) {
            final StrTree<FacetSequence> geomTree = FacetSequenceTreeBuilder.build(this.geometry);
            final Pair<FacetSequence, FacetSequence> nearest = geomTree.nearestNeighbour(new MinClearanceDistance(this.calculateLine));
            final MinClearanceDistance mcd = new MinClearanceDistance(this.calculateLine);
            this.minClearance = mcd.distance(nearest.getValue1(), nearest.getValue2());
            final GeometryFactory geometryFactory = this.geometry.getGeometryFactory();
            if (this.calculateLine) {
                this.minClearancePts = new Point[] { // 
                geometryFactory.point(mcd.getMinX1(), mcd.getMinY1()), geometryFactory.point(mcd.getMinX2(), mcd.getMinY2()) };
            }
        }
    }
}
Also used : FacetSequence(com.revolsys.geometry.operation.distance.FacetSequence) GeometryFactory(com.revolsys.geometry.model.GeometryFactory)

Example 95 with GeometryFactory

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

the class LineStringUtil method isPointOnLine.

/**
 * Check to see if the point is on any of the segments of the line.
 *
 * @param line The line.
 * @param point The point.
 * @return True if the point is on the line, false otherwise.
 * @see LineSegmentUtil#isPointOnLine(GeometryFactory, Coordinates,
 *      Coordinates, Point)
 */
public static boolean isPointOnLine(final LineString line, final Point point) {
    final GeometryFactory factory = line.getGeometryFactory();
    final double x = point.getX();
    final double y = point.getY();
    final int vertexCount = line.getVertexCount();
    if (vertexCount > 0) {
        double x1 = line.getX(0);
        double y1 = line.getY(0);
        if (x == x1 && y == y1) {
            return true;
        }
        for (int vertexIndex = 1; vertexIndex < vertexCount; vertexIndex++) {
            final double x2 = line.getX(vertexIndex);
            final double y2 = line.getY(vertexIndex);
            if (x == x2 && y == y2) {
                return true;
            } else {
                if (LineSegmentUtil.isPointOnLine(factory, x1, y1, x2, y2, x, y)) {
                    return true;
                }
            }
            x1 = x2;
            y1 = y2;
        }
    }
    return false;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point)

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