Search in sources :

Example 11 with Punctual

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

the class MultiPointEditorTest method testSetZ.

@Test
public void testSetZ() {
    final PunctualEditor editor = PUNCTUAL.newGeometryEditor(3);
    editor.setZ(0, 10);
    final Punctual newMultiPoint = editor.newGeometry();
    Assert.assertNotSame(PUNCTUAL, newMultiPoint);
    Assert.assertEquals(10.0, newMultiPoint.getZ(0), 0.0);
}
Also used : Punctual(com.revolsys.geometry.model.Punctual) PunctualEditor(com.revolsys.geometry.model.editor.PunctualEditor) Test(org.junit.Test)

Example 12 with Punctual

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

the class MultiPointEditorTest method testSetY.

@Test
public void testSetY() {
    final PunctualEditor editor = PUNCTUAL.newGeometryEditor(3);
    editor.setY(0, 10);
    final Punctual newMultiPoint = editor.newGeometry();
    Assert.assertNotSame(PUNCTUAL, newMultiPoint);
    Assert.assertEquals(10.0, newMultiPoint.getY(0), 0.0);
}
Also used : Punctual(com.revolsys.geometry.model.Punctual) PunctualEditor(com.revolsys.geometry.model.editor.PunctualEditor) Test(org.junit.Test)

Example 13 with Punctual

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

the class GeometryFactoryTest method testCreateGeometry.

private static void testCreateGeometry() {
    final LineString pointPoints = new LineStringDouble(2, 0.0, 0);
    final LineString point2Points = new LineStringDouble(2, 20.0, 20);
    final LineString ringPoints = new LineStringDouble(2, 0.0, 0, 0, 100, 100, 100, 100, 0, 0, 0);
    final LineString ring2Points = new LineStringDouble(2, 20.0, 20, 20, 80, 80, 80, 80, 20, 20, 20);
    final LineString ring3Points = new LineStringDouble(2, 120.0, 120, 120, 180, 180, 180, 180, 120, 120, 120);
    final Point point = GEOMETRY_FACTORY.point(2, 0.0, 0);
    assertCopyGeometry(point, pointPoints);
    final LineString line = GEOMETRY_FACTORY.lineString(ringPoints);
    assertCopyGeometry(line, ringPoints);
    final LinearRing linearRing = GEOMETRY_FACTORY.linearRing(ringPoints);
    assertCopyGeometry(linearRing, ringPoints);
    final Polygon polygon = GEOMETRY_FACTORY.polygon(ringPoints);
    assertCopyGeometry(polygon, ringPoints);
    final Polygon polygon2 = GEOMETRY_FACTORY.polygon(ringPoints, ring2Points);
    assertCopyGeometry(polygon2, ringPoints, ring2Points);
    final Punctual multiPoint = GEOMETRY_FACTORY.punctual(pointPoints);
    assertCopyGeometry(multiPoint, pointPoints);
    final Punctual multiPoint2 = GEOMETRY_FACTORY.punctual(pointPoints, point2Points);
    assertCopyGeometry(multiPoint2, pointPoints, point2Points);
    final Lineal multiLineString = GEOMETRY_FACTORY.lineal(ringPoints);
    assertCopyGeometry(multiLineString, ringPoints);
    final Lineal multiLineString2 = GEOMETRY_FACTORY.lineal(ringPoints, ring2Points);
    assertCopyGeometry(multiLineString2, ringPoints, ring2Points);
    final Polygonal multiPolygon = GEOMETRY_FACTORY.polygonal(ringPoints);
    assertCopyGeometry(multiPolygon, ringPoints);
    final Polygonal multiPolygon2 = GEOMETRY_FACTORY.polygonal(ringPoints, ring3Points);
    assertCopyGeometry(multiPolygon2, ringPoints, ring3Points);
}
Also used : Punctual(com.revolsys.geometry.model.Punctual) Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) Polygonal(com.revolsys.geometry.model.Polygonal) Point(com.revolsys.geometry.model.Point) LinearRing(com.revolsys.geometry.model.LinearRing) Polygon(com.revolsys.geometry.model.Polygon) LineStringDouble(com.revolsys.geometry.model.impl.LineStringDouble)

Example 14 with Punctual

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

the class GeometryGraph method getBoundaryIntersection.

/**
 * Get the intersection between the line and the boundary of this geometry.
 *
 * @param line
 * @return
 */
public Geometry getBoundaryIntersection(final LineString line) {
    final List<Point> pointIntersections = new ArrayList<>();
    final List<LineString> lineIntersections = new ArrayList<>();
    final GeometryFactory geometryFactory = getGeometryFactory();
    final BoundingBox boundingBox = getBoundingBox(line);
    if (boundingBox.intersects(this.boundingBox)) {
        final LineString points = line;
        final int vertexCount = points.getVertexCount();
        final Point fromPoint = points.getPoint(0);
        final Point toPoint = points.getPoint(vertexCount - 1);
        Point previousPoint = fromPoint;
        for (int vertexIndex = 1; vertexIndex < vertexCount; vertexIndex++) {
            final Point nextPoint = points.getPoint(vertexIndex);
            final LineSegment line1 = new LineSegmentDoubleGF(getGeometryFactory(), previousPoint, nextPoint);
            final List<Edge<LineSegment>> edges = EdgeLessThanDistance.getEdges(this, line1, this.maxDistance);
            for (final Edge<LineSegment> edge2 : edges) {
                final LineSegment line2 = edge2.getObject();
                final Geometry segmentIntersection = line1.getIntersection(line2);
                if (segmentIntersection instanceof Point) {
                    final Point intersection = (Point) segmentIntersection;
                    if (intersection.equals(fromPoint) || intersection.equals(toPoint)) {
                        // Point intersection, make sure it's not at the start
                        final Node<LineSegment> node = findNode(intersection);
                        if (node == null) {
                            pointIntersections.add(geometryFactory.point(intersection));
                        } else {
                            final int degree = node.getDegree();
                            if (isStartPoint(node)) {
                                if (degree > 2) {
                                    // Intersection not at the start/end of the other line,
                                    // taking
                                    // into account loops
                                    pointIntersections.add(geometryFactory.point(intersection));
                                }
                            } else if (degree > 1) {
                                // Intersection not at the start/end of the other line
                                pointIntersections.add(geometryFactory.point(intersection));
                            }
                        }
                    } else {
                        // Intersection not at the start/end of the line
                        pointIntersections.add(geometryFactory.point(intersection));
                    }
                } else if (segmentIntersection instanceof LineSegment) {
                    lineIntersections.add((LineSegment) segmentIntersection);
                }
                for (final Point point : line1.vertices()) {
                    if (line2.distancePoint(point) < this.maxDistance) {
                        if (point.equals(fromPoint) || point.equals(toPoint)) {
                            // Point intersection, make sure it's not at the start
                            final double maxDistance1 = this.maxDistance;
                            for (final Node<LineSegment> node : this.getNodes(point, maxDistance1)) {
                                final int degree = node.getDegree();
                                if (isStartPoint(node)) {
                                    if (degree > 2) {
                                        // Intersection not at the start/end of the other line,
                                        // taking
                                        // into account loops
                                        pointIntersections.add(geometryFactory.point(point));
                                    }
                                } else if (degree > 1) {
                                    // Intersection not at the start/end of the other line
                                    pointIntersections.add(geometryFactory.point(point));
                                }
                            }
                        } else {
                            // Intersection not at the start/end of the line
                            pointIntersections.add(geometryFactory.point(point));
                        }
                    }
                }
            }
            previousPoint = nextPoint;
        }
    }
    if (lineIntersections.isEmpty()) {
        return geometryFactory.punctual(pointIntersections);
    } else {
        final List<LineString> mergedLines = LineMerger.merge(lineIntersections);
        final Lineal multiLine = geometryFactory.lineal(mergedLines);
        if (pointIntersections.isEmpty()) {
            return multiLine;
        } else {
            final Punctual multiPoint = geometryFactory.punctual(pointIntersections);
            return multiPoint.union(multiLine);
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) Geometry(com.revolsys.geometry.model.Geometry) Punctual(com.revolsys.geometry.model.Punctual) Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 15 with Punctual

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

the class UnaryUnionOp method union.

/**
 * Gets the union of the input geometries.
 * If no input geometries were provided but a {@link GeometryFactory} was provided,
 * an empty {@link Geometry} is returned.
 * Otherwise, the return value is <code>null</code>.
 *
 * @return a Geometry containing the union,
 * or an empty GEOMETRYCOLLECTION if no geometries were provided in the input,
 * or <code>null</code> if no GeometryFactory was provided
 */
private static Geometry union(final GeometryFactory geometryFactory, final List<Point> points, final List<LineString> lines, final List<Polygon> polygons) {
    if (geometryFactory == null) {
        return null;
    } else {
        /**
         * For points and lines, only a single union operation is
         * required, since the OGC model allowing self-intersecting
         * MultiPoint and MultiLineStrings.
         * This is not the case for polygons, so Cascaded Union is required.
         */
        Punctual unionPoints = null;
        if (points.size() > 0) {
            final Punctual punctual = geometryFactory.punctual(points);
            unionPoints = punctual.union();
        }
        Geometry unionLines = null;
        if (lines.size() > 0) {
            final Geometry lineal = geometryFactory.geometry(lines);
            unionLines = unionNoOpt(geometryFactory, lineal);
        }
        Geometry unionPolygons = null;
        if (polygons.size() > 0) {
            unionPolygons = CascadedPolygonUnion.union(polygons);
        }
        /**
         * Performing two unions is somewhat inefficient,
         * but is mitigated by unioning lines and points first
         */
        Geometry union = null;
        if (unionLines == null) {
            union = unionPolygons;
        } else if (unionPolygons == null) {
            union = unionLines;
        } else {
            union = unionPolygons.union(unionLines);
        }
        if (unionPoints != null) {
            if (union == null) {
                union = unionPoints;
            } else {
                union = union(unionPoints, union);
            }
        }
        if (union == null) {
            return geometryFactory.geometryCollection();
        } else {
            return union;
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Punctual(com.revolsys.geometry.model.Punctual)

Aggregations

Punctual (com.revolsys.geometry.model.Punctual)31 Point (com.revolsys.geometry.model.Point)17 LineString (com.revolsys.geometry.model.LineString)11 Lineal (com.revolsys.geometry.model.Lineal)11 Polygon (com.revolsys.geometry.model.Polygon)11 Polygonal (com.revolsys.geometry.model.Polygonal)9 Geometry (com.revolsys.geometry.model.Geometry)8 Test (org.junit.Test)7 BoundingBox (com.revolsys.geometry.model.BoundingBox)6 LinearRing (com.revolsys.geometry.model.LinearRing)6 PunctualEditor (com.revolsys.geometry.model.editor.PunctualEditor)6 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)4 ArrayList (java.util.ArrayList)2 DataType (com.revolsys.datatype.DataType)1 Edge (com.revolsys.geometry.graph.Edge)1 LineStringDouble (com.revolsys.geometry.model.impl.LineStringDouble)1 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)1 LineSegment (com.revolsys.geometry.model.segment.LineSegment)1 LineSegmentDoubleGF (com.revolsys.geometry.model.segment.LineSegmentDoubleGF)1 BaseCloseable (com.revolsys.io.BaseCloseable)1