Search in sources :

Example 11 with CoordinatesOperation

use of com.revolsys.geometry.cs.projection.CoordinatesOperation in project com.revolsys.open by revolsys.

the class BoundingBox method convert.

default BoundingBox convert(final GeometryFactory geometryFactory) {
    final GeometryFactory factory = getGeometryFactory();
    if (isEmpty()) {
        return geometryFactory.newBoundingBoxEmpty();
    } else if (geometryFactory == null) {
        return this;
    } else if (factory == geometryFactory) {
        return this;
    } else {
        if (factory == null || factory.getCoordinateSystem() == null) {
            final int axisCount = Math.min(geometryFactory.getAxisCount(), getAxisCount());
            final double[] minMaxValues = getMinMaxValues(axisCount);
            return geometryFactory.newBoundingBox(axisCount, minMaxValues);
        } else if (isEmpty()) {
            return newBoundingBoxEmpty();
        } else {
            final CoordinatesOperation operation = factory.getCoordinatesOperation(geometryFactory);
            if (operation != null) {
                double xStep = getWidth() / 10;
                double yStep = getHeight() / 10;
                final double scaleXY = geometryFactory.getScaleXY();
                if (scaleXY > 0) {
                    if (xStep < 1 / scaleXY) {
                        xStep = 1 / scaleXY;
                    }
                    if (yStep < 1 / scaleXY) {
                        yStep = 1 / scaleXY;
                    }
                }
                final double minX = getMinX();
                final double maxX = getMaxX();
                final double minY = getMinY();
                final double maxY = getMaxY();
                final double[] bounds = getMinMaxValues(2);
                bounds[0] = Double.NaN;
                bounds[1] = Double.NaN;
                bounds[2] = Double.NaN;
                bounds[3] = Double.NaN;
                final double[] to = new double[2];
                expand(geometryFactory, bounds, operation, to, minX, minY);
                expand(geometryFactory, bounds, operation, to, minX, maxY);
                expand(geometryFactory, bounds, operation, to, minX, minY);
                expand(geometryFactory, bounds, operation, to, maxX, minY);
                if (xStep != 0) {
                    for (double x = minX + xStep; x < maxX; x += xStep) {
                        expand(geometryFactory, bounds, operation, to, x, minY);
                        expand(geometryFactory, bounds, operation, to, x, maxY);
                    }
                }
                if (yStep != 0) {
                    for (double y = minY + yStep; y < maxY; y += yStep) {
                        expand(geometryFactory, bounds, operation, to, minX, y);
                        expand(geometryFactory, bounds, operation, to, maxX, y);
                    }
                }
                return geometryFactory.newBoundingBox(2, bounds);
            } else {
                return this;
            }
        }
    }
}
Also used : BoundingBoxDoubleXYGeometryFactory(com.revolsys.geometry.model.impl.BoundingBoxDoubleXYGeometryFactory) CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation)

Example 12 with CoordinatesOperation

use of com.revolsys.geometry.cs.projection.CoordinatesOperation in project com.revolsys.open by revolsys.

the class Geometry method forEachVertex.

default void forEachVertex(final GeometryFactory geometryFactory, final Consumer<double[]> action) {
    if (!isEmpty()) {
        int axisCount = getAxisCount();
        final int axisCount2 = geometryFactory.getAxisCount();
        if (axisCount2 < axisCount) {
            axisCount = axisCount2;
        }
        final double[] coordinates = new double[axisCount];
        if (isProjectionRequired(geometryFactory)) {
            final CoordinatesOperation coordinatesOperation = getCoordinatesOperation(geometryFactory);
            forEachVertex(coordinatesOperation, coordinates, action);
        } else {
            forEachVertex(coordinates, action);
        }
    }
}
Also used : CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation)

Example 13 with CoordinatesOperation

use of com.revolsys.geometry.cs.projection.CoordinatesOperation in project com.revolsys.open by revolsys.

the class LineStringDouble method convertCoordinates.

@Override
public double[] convertCoordinates(GeometryFactory geometryFactory, final int axisCount) {
    final GeometryFactory sourceGeometryFactory = getGeometryFactory();
    final double[] sourceCoordinates = this.coordinates;
    if (isEmpty()) {
        return sourceCoordinates;
    } else {
        final int sourceAxisCount = this.axisCount;
        final int vertexCount = this.vertexCount;
        geometryFactory = getNonZeroGeometryFactory(geometryFactory);
        final int targetAxisCount = axisCount;
        double[] targetCoordinates;
        final CoordinatesOperation coordinatesOperation = sourceGeometryFactory.getCoordinatesOperation(geometryFactory);
        if (coordinatesOperation == null) {
            if (sourceAxisCount == geometryFactory.getAxisCount()) {
                return sourceCoordinates;
            } else {
                final double[] coordinates = new double[targetAxisCount * vertexCount];
                int i = 0;
                for (int vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
                    for (int axisIndex = 0; axisIndex < targetAxisCount; axisIndex++) {
                        final double coordinate;
                        if (axisIndex < sourceAxisCount) {
                            coordinate = sourceCoordinates[vertexIndex * sourceAxisCount + axisIndex];
                        } else {
                            coordinate = Double.NaN;
                        }
                        coordinates[i++] = coordinate;
                    }
                }
                return coordinates;
            }
        } else {
            targetCoordinates = new double[targetAxisCount * vertexCount];
            coordinatesOperation.perform(sourceAxisCount, sourceCoordinates, targetAxisCount, targetCoordinates);
            return targetCoordinates;
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation) Point(com.revolsys.geometry.model.Point)

Aggregations

CoordinatesOperation (com.revolsys.geometry.cs.projection.CoordinatesOperation)13 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)3 ChainedCoordinatesOperation (com.revolsys.geometry.cs.projection.ChainedCoordinatesOperation)2 UnitConverstionOperation (com.revolsys.geometry.cs.projection.UnitConverstionOperation)2 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)2 Point (com.revolsys.geometry.model.Point)2 ArrayList (java.util.ArrayList)2 Unit (javax.measure.Unit)2 Length (javax.measure.quantity.Length)2 AngularUnit (com.revolsys.geometry.cs.unit.AngularUnit)1 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 BoundingBoxDoubleXYGeometryFactory (com.revolsys.geometry.model.impl.BoundingBoxDoubleXYGeometryFactory)1 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)1 Angle (javax.measure.quantity.Angle)1