Search in sources :

Example 71 with PointDoubleXY

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

the class RobustLineIntersector method intersectionWithNormalization.

private Point intersectionWithNormalization(final double line1x1, final double line1y1, final double line1x2, final double line1y2, final double line2x1, final double line2y1, final double line2x2, final double line2y2) {
    final double minX0 = line1x1 < line1x2 ? line1x1 : line1x2;
    final double minY0 = line1y1 < line1y2 ? line1y1 : line1y2;
    final double maxX0 = line1x1 > line1x2 ? line1x1 : line1x2;
    final double maxY0 = line1y1 > line1y2 ? line1y1 : line1y2;
    final double minX1 = line2x1 < line2x2 ? line2x1 : line2x2;
    final double minY1 = line2y1 < line2y2 ? line2y1 : line2y2;
    final double maxX1 = line2x1 > line2x2 ? line2x1 : line2x2;
    final double maxY1 = line2y1 > line2y2 ? line2y1 : line2y2;
    final double intMinX = minX0 > minX1 ? minX0 : minX1;
    final double intMaxX = maxX0 < maxX1 ? maxX0 : maxX1;
    final double intMinY = minY0 > minY1 ? minY0 : minY1;
    final double intMaxY = maxY0 < maxY1 ? maxY0 : maxY1;
    final double normX = (intMinX + intMaxX) / 2.0;
    final double normY = (intMinY + intMaxY) / 2.0;
    final Point intPt = safeHCoordinatesIntersection(// 
    line1x1 - normX, // 
    line1y1 - normY, // 
    line1x2 - normX, // 
    line1y2 - normY, // 
    line2x1 - normX, // 
    line2y1 - normY, line2x2 - normX, line2y2 - normY);
    final double x = intPt.getX() + normX;
    final double y = intPt.getY() + normY;
    return new PointDoubleXY(x, y);
}
Also used : Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 72 with PointDoubleXY

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

the class InteriorPointLine method add.

private void add(final double x, final double y) {
    final double dist = MathUtil.distance(this.centroid.getX(), this.centroid.getY(), x, y);
    if (dist < this.minDistance) {
        this.interiorPoint = new PointDoubleXY(x, y);
        this.minDistance = dist;
    }
}
Also used : PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 73 with PointDoubleXY

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

the class Point method convertPoint2d.

default Point convertPoint2d(final GeometryFactory geometryFactory) {
    if (isEmpty()) {
        return this;
    } else {
        final CoordinatesOperation coordinatesOperation = getGeometryFactory().getCoordinatesOperation(geometryFactory);
        if (coordinatesOperation == null) {
            return this;
        } else {
            final double sourceX = getX();
            final double sourceY = getY();
            final double[] targetCoordinates = new double[] { sourceX, sourceY };
            coordinatesOperation.perform(2, targetCoordinates, 2, targetCoordinates);
            final double targetX = targetCoordinates[X];
            final double targetY = targetCoordinates[Y];
            return new PointDoubleXY(targetX, targetY);
        }
    }
}
Also used : PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation)

Example 74 with PointDoubleXY

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

the class CoordinatesUtil method pointNotInList.

/**
 * Return the first point of points1 not in points2
 * @param points1
 * @param points2
 * @return
 */
static Point pointNotInList(final LineString line1, final LineString line2) {
    final int vertexCount = line1.getVertexCount();
    for (int vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
        final double x = line1.getX(vertexIndex);
        final double y = line1.getY(vertexIndex);
        if (!line2.hasVertex(x, y)) {
            return new PointDoubleXY(x, y);
        }
    }
    return null;
}
Also used : PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

Example 75 with PointDoubleXY

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

the class EdgeCleanCloseVerticesVisitor method accept.

// TODO look at the angles with the previous and next segments to decide
// which coordinate to remove. If there is a right angle in a building then
// it should probably not be removed. This would be confirmed by the angles
// of the next and previous segments.
/**
 * Visit the edge performing any required cleanup.
 *
 * @param edge The edge to visit.
 * @return true If further edges should be processed.
 */
@Override
public void accept(final Edge<T> edge) {
    final String typePath = edge.getTypeName();
    final LineString line = edge.getLineString();
    final int vertexCount = line.getVertexCount();
    if (vertexCount > 2) {
        final GeometryFactory geometryFactory = line.getGeometryFactory();
        final LinkedHashSet<Integer> removeIndicies = new LinkedHashSet<>();
        double x1 = line.getX(0);
        double y1 = line.getY(0);
        for (int i = 1; i < vertexCount; i++) {
            final double x2 = line.getX(i);
            final double y2 = line.getY(i);
            final double distance = MathUtil.distance(x1, y1, x2, y2);
            if (distance < this.minDistance) {
                final double previousAngle = getAngle(edge, line, i - 1);
                final double angle = getAngle(edge, line, i);
                final double nextAngle = getAngle(edge, line, i + 1);
                boolean fixed = false;
                if (angle > previousAngle) {
                    if (angle > nextAngle) {
                        if (angle > Math.toRadians(160)) {
                            fixed = true;
                        }
                    }
                } else if (previousAngle > nextAngle) {
                }
                if (fixed) {
                    this.coordinateListeners.coordinateEvent(new PointDoubleXY(x2, y2), typePath, "Short Segment", "Fixed", distance + " " + Math.toDegrees(previousAngle) + " " + Math.toDegrees(angle) + " " + Math.toDegrees(nextAngle));
                } else {
                    this.coordinateListeners.coordinateEvent(new PointDoubleXY(x2, y2), typePath, "Short Segment", "Review", distance + " " + Math.toDegrees(previousAngle) + " " + Math.toDegrees(angle) + " " + Math.toDegrees(nextAngle));
                }
            }
            x1 = x2;
            y1 = y2;
        }
        if (!removeIndicies.isEmpty()) {
            final int axisCount = line.getAxisCount();
            final double[] newCoordinates = new double[(vertexCount - removeIndicies.size()) * axisCount];
            int k = 0;
            for (int j = 0; j < vertexCount; j++) {
                if (!removeIndicies.contains(j)) {
                    CoordinatesListUtil.setCoordinates(newCoordinates, axisCount, k, line, j);
                    k++;
                }
            }
            final LineString newLine = geometryFactory.lineString(axisCount, newCoordinates);
            final Edge<T> newEdge = this.graph.replaceEdge(edge, newLine);
            this.edgeListeners.edgeEvent(newEdge, "Edge close indicies", EdgeEvent.EDGE_CHANGED, null);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineString(com.revolsys.geometry.model.LineString) LineString(com.revolsys.geometry.model.LineString) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Aggregations

PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)138 Point (com.revolsys.geometry.model.Point)91 Geometry (com.revolsys.geometry.model.Geometry)36 ArrayList (java.util.ArrayList)19 BoundingBox (com.revolsys.geometry.model.BoundingBox)10 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)10 List (java.util.List)9 LineString (com.revolsys.geometry.model.LineString)8 Polygon (com.revolsys.geometry.model.Polygon)6 RobustLineIntersector (com.revolsys.geometry.algorithm.RobustLineIntersector)5 LengthIndexedLine (com.revolsys.geometry.linearref.LengthIndexedLine)5 LinearLocation (com.revolsys.geometry.linearref.LinearLocation)5 LocationIndexedLine (com.revolsys.geometry.linearref.LocationIndexedLine)5 LineSegmentDouble (com.revolsys.geometry.model.segment.LineSegmentDouble)5 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)4 LineSegment (com.revolsys.geometry.model.segment.LineSegment)4 AffineTransformation (com.revolsys.geometry.model.util.AffineTransformation)4 GeometricShapeFactory (com.revolsys.geometry.util.GeometricShapeFactory)4 Vertex (com.revolsys.geometry.model.vertex.Vertex)3 KdNode (com.revolsys.geometry.index.kdtree.KdNode)2