Search in sources :

Example 6 with CoordinatesOperation

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

the class Point method convertCoordinates.

default double[] convertCoordinates(GeometryFactory geometryFactory) {
    final GeometryFactory sourceGeometryFactory = getGeometryFactory();
    final double[] coordinates = getCoordinates();
    if (isEmpty()) {
        return coordinates;
    } else {
        geometryFactory = getNonZeroGeometryFactory(geometryFactory);
        double[] targetCoordinates;
        final CoordinatesOperation coordinatesOperation = sourceGeometryFactory.getCoordinatesOperation(geometryFactory);
        if (coordinatesOperation == null) {
            return coordinates;
        } else {
            final int sourceAxisCount = getAxisCount();
            targetCoordinates = new double[sourceAxisCount * getVertexCount()];
            coordinatesOperation.perform(sourceAxisCount, coordinates, sourceAxisCount, targetCoordinates);
            return targetCoordinates;
        }
    }
}
Also used : CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation)

Example 7 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 int axisCount, final Consumer<double[]> action) {
    if (!isEmpty()) {
        final double[] coordinates = new double[axisCount];
        Arrays.fill(coordinates, Double.NaN);
        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 8 with CoordinatesOperation

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

the class ProjectionImageFilter method filterPixels.

@Override
protected int[] filterPixels(final int imageWidth, final int imageHeight, final int[] inPixels, final Rectangle transformedSpace) {
    final int[] outPixels = new int[transformedSpace.width * transformedSpace.height];
    final double minX = this.sourceBoundingBox.getMinX();
    final double minY = this.sourceBoundingBox.getMinY();
    final double width = this.sourceBoundingBox.getWidth();
    final double height = this.sourceBoundingBox.getHeight();
    final double pixelWidth = width / imageWidth;
    final double pixelHeight = height / imageHeight;
    final double newMinX = this.destBoundingBox.getMinX();
    final double newMaxY = this.destBoundingBox.getMaxY();
    final int newImageWidth = transformedSpace.width;
    final int newImageHeight = transformedSpace.height;
    final GeometryFactory sourceGeometryFactory = this.sourceBoundingBox.getGeometryFactory();
    final GeometryFactory destGeometryFactory = this.destBoundingBox.getGeometryFactory();
    final CoordinatesOperation operation = destGeometryFactory.getCoordinatesOperation(sourceGeometryFactory);
    if (operation == null) {
        return inPixels;
    }
    final double[] source = new double[2];
    final double[] dest = new double[2];
    for (int i = 0; i < newImageWidth; i++) {
        final double newImageX = newMinX + i * this.destPixelSize;
        dest[0] = newImageX;
        for (int j = 0; j < newImageHeight; j++) {
            final double newImageY = newMaxY - j * this.destPixelSize;
            dest[1] = newImageY;
            operation.perform(2, dest, 2, source);
            final double imageX = source[0];
            final double imageY = source[1];
            final int imageI = (int) ((imageX - minX) / pixelWidth);
            final int imageJ = imageHeight - (int) ((imageY - minY) / pixelHeight);
            if (imageI > -1 && imageI < imageWidth) {
                if (imageJ > -1 && imageJ < imageHeight) {
                    final int rgb = inPixels[imageJ * imageWidth + imageI];
                    if (rgb != -1) {
                        outPixels[j * newImageWidth + i] = rgb;
                    // // TODO better interpolation
                    }
                }
            }
        }
    }
    return outPixels;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation)

Example 9 with CoordinatesOperation

use of com.revolsys.geometry.cs.projection.CoordinatesOperation 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 10 with CoordinatesOperation

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

the class LineString method convertCoordinates.

default double[] convertCoordinates(GeometryFactory geometryFactory, final int axisCount) {
    final GeometryFactory sourceGeometryFactory = getGeometryFactory();
    final double[] coordinates = getCoordinates(axisCount);
    if (isEmpty()) {
        return coordinates;
    } else {
        geometryFactory = getNonZeroGeometryFactory(geometryFactory);
        double[] targetCoordinates;
        final CoordinatesOperation coordinatesOperation = sourceGeometryFactory.getCoordinatesOperation(geometryFactory);
        if (coordinatesOperation == null) {
            return coordinates;
        } else {
            final int sourceAxisCount = getAxisCount();
            targetCoordinates = new double[sourceAxisCount * getVertexCount()];
            coordinatesOperation.perform(sourceAxisCount, coordinates, sourceAxisCount, targetCoordinates);
            return targetCoordinates;
        }
    }
}
Also used : CoordinatesOperation(com.revolsys.geometry.cs.projection.CoordinatesOperation)

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