Search in sources :

Example 21 with GeometryFactory

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

the class LineSegment method distance.

default double distance(final LineSegment line) {
    final double[] coordinates = new double[2];
    final GeometryFactory geometryFactory = getGeometryFactory();
    line.convertVertexCoordinates2d(0, geometryFactory, coordinates);
    final double x1 = coordinates[X];
    final double y1 = coordinates[Y];
    line.convertVertexCoordinates2d(1, geometryFactory, coordinates);
    final double x2 = coordinates[X];
    final double y2 = coordinates[Y];
    return distance(x1, y1, x2, y2);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory)

Example 22 with GeometryFactory

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

the class LineSegment method convertGeometry.

@Override
@SuppressWarnings("unchecked")
default <V extends Geometry> V convertGeometry(final GeometryFactory geometryFactory) {
    final GeometryFactory factory = getGeometryFactory();
    if (geometryFactory == factory) {
        return (V) this;
    } else {
        final Point point1 = ProjectionFactory.convert(getPoint(0), factory, geometryFactory);
        final Point point2 = ProjectionFactory.convert(getPoint(1), factory, geometryFactory);
        return (V) new LineSegmentDoubleGF(geometryFactory, point1, point2);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point)

Example 23 with GeometryFactory

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

the class LineSegment method pointAlong.

/**
 * Computes the {@link Coordinates} that lies a given
 * fraction along the line defined by this segment.
 * A fraction of <code>0.0</code> returns the start point of the segment;
 * a fraction of <code>1.0</code> returns the end point of the segment.
 * If the fraction is < 0.0 or > 1.0 the point returned
 * will lie before the start or beyond the end of the segment.
 *
 * @param projectionFactor the fraction of the segment length along the line
 * @return the point at that distance
 */
default Point pointAlong(final double projectionFactor) {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final int axisCount = getAxisCount();
    final double[] coordinates = new double[axisCount];
    for (int i = 0; i < axisCount; i++) {
        final double value1 = getCoordinate(0, i);
        final double value2 = getCoordinate(1, i);
        final double delta = value2 - value1;
        double newValue = value1 + delta * projectionFactor;
        newValue = geometryFactory.makePrecise(i, newValue);
        coordinates[i] = newValue;
    }
    return newPoint(coordinates);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point)

Example 24 with GeometryFactory

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

the class LineSegment method isPerpendicularTo.

default boolean isPerpendicularTo(Point point) {
    if (Property.hasValuesAll(point, this)) {
        final GeometryFactory geometryFactory = getGeometryFactory();
        point = point.convertGeometry(geometryFactory, 2);
        final double x = point.getX();
        final double y = point.getY();
        final double projectionFactor = projectionFactor(x, y);
        if (projectionFactor >= 0.0 && projectionFactor <= 1.0) {
            return true;
        }
    }
    return false;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory)

Example 25 with GeometryFactory

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

the class LineSegment method isPointOnLineMiddle.

default boolean isPointOnLineMiddle(Point point, final double maxDistance) {
    if (point == null || point.isEmpty()) {
        return false;
    } else {
        final GeometryFactory geometryFactory = getGeometryFactory();
        point = point.convertGeometry(geometryFactory, 2);
        final double x = point.getX();
        final double y = point.getY();
        return isPointOnLineMiddle(x, y, maxDistance);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory)

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