Search in sources :

Example 16 with ProjectedCoordinateSystem

use of com.revolsys.geometry.cs.ProjectedCoordinateSystem in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method newCoordinateSystemProjected.

private static ProjectedCoordinateSystem newCoordinateSystemProjected(final int id, final String name, final Area area, final CoordinateSystem sourceCoordinateSystem, final CoordinateOperation operation, final List<Axis> axis, final boolean deprecated) {
    final EpsgAuthority authority = new EpsgAuthority(id);
    final LinearUnit linearUnit = (LinearUnit) axis.get(0).getUnit();
    final CoordinateOperationMethod method = operation.getMethod();
    final Map<ParameterName, ParameterValue> parameterValues = operation.getParameterValues();
    if (sourceCoordinateSystem instanceof GeographicCoordinateSystem) {
        final GeographicCoordinateSystem geographicCoordinateSystem = (GeographicCoordinateSystem) sourceCoordinateSystem;
        return new ProjectedCoordinateSystem(id, name, geographicCoordinateSystem, area, method, parameterValues, linearUnit, axis, authority, deprecated);
    } else if (!Arrays.asList(5819, 5820, 5821).contains(id)) {
        Logs.error(EpsgCoordinateSystems.class, id + " " + name + " has a projected coordinate system");
        return null;
    } else {
        return null;
    }
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ParameterName(com.revolsys.geometry.cs.ParameterName) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Example 17 with ProjectedCoordinateSystem

use of com.revolsys.geometry.cs.ProjectedCoordinateSystem in project com.revolsys.open by revolsys.

the class EsriCoordinateSystems method getProjectedCoordinateSystem.

public static ProjectedCoordinateSystem getProjectedCoordinateSystem(final int id) {
    ProjectedCoordinateSystem coordinateSystem = (ProjectedCoordinateSystem) COORDINATE_SYSTEM_BY_ID.get(id);
    if (coordinateSystem == null) {
        try (final ChannelReader reader = ChannelReader.newChannelReader("classpath:CoordinateSystems/esri/Projected.cs")) {
            while (true) {
                final int coordinateSystemId = reader.getInt();
                final String csName = reader.getStringUtf8ByteCount();
                final int geographicCoordinateSystemId = reader.getInt();
                final String projectionName = reader.getStringUtf8ByteCount();
                final Map<ParameterName, ParameterValue> parameters = readParameters(reader);
                final String unitName = reader.getStringUtf8ByteCount();
                final double conversionFactor = reader.getDouble();
                if (id == coordinateSystemId) {
                    LinearUnit linearUnit = LINEAR_UNITS_BY_NAME.get(unitName);
                    if (linearUnit == null) {
                        linearUnit = new LinearUnit(unitName, conversionFactor);
                        LINEAR_UNITS_BY_NAME.put(unitName, linearUnit);
                    }
                    final Authority authority = new BaseAuthority("ESRI", coordinateSystemId);
                    final GeographicCoordinateSystem geographicCoordinateSystem = getGeographicCoordinateSystem(geographicCoordinateSystemId);
                    coordinateSystem = new ProjectedCoordinateSystem(coordinateSystemId, csName, geographicCoordinateSystem, projectionName, parameters, linearUnit, authority);
                    COORDINATE_SYSTEM_BY_ID.put(id, coordinateSystem);
                    return coordinateSystem;
                }
            }
        } catch (final WrappedException e) {
            if (Exceptions.isException(e, EOFException.class)) {
                return null;
            } else {
                Logs.error("Cannot load coordinate system=" + id, e);
                throw e;
            }
        }
    }
    return coordinateSystem;
}
Also used : BaseAuthority(com.revolsys.geometry.cs.BaseAuthority) WrappedException(com.revolsys.util.WrappedException) LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) Authority(com.revolsys.geometry.cs.Authority) BaseAuthority(com.revolsys.geometry.cs.BaseAuthority) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ParameterName(com.revolsys.geometry.cs.ParameterName) SingleParameterName(com.revolsys.geometry.cs.SingleParameterName) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Example 18 with ProjectedCoordinateSystem

use of com.revolsys.geometry.cs.ProjectedCoordinateSystem in project com.revolsys.open by revolsys.

the class BoundingBox method toPolygon.

default Polygon toPolygon(GeometryFactory geometryFactory, int numX, int numY) {
    if (isEmpty()) {
        return geometryFactory.polygon();
    } else {
        final GeometryFactory factory = getGeometryFactory();
        if (geometryFactory == null) {
            if (factory == null) {
                geometryFactory = GeometryFactory.floating2d(0);
            } else {
                geometryFactory = factory;
            }
        }
        try {
            double minStep = 0.00001;
            final CoordinateSystem coordinateSystem = factory.getCoordinateSystem();
            if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                minStep = 1;
            } else {
                minStep = 0.00001;
            }
            double xStep;
            final double width = getWidth();
            if (!Double.isFinite(width)) {
                return geometryFactory.polygon();
            } else if (numX <= 1) {
                numX = 1;
                xStep = width;
            } else {
                xStep = width / numX;
                if (xStep < minStep) {
                    xStep = minStep;
                }
                numX = Math.max(1, (int) Math.ceil(width / xStep));
            }
            double yStep;
            if (numY <= 1) {
                numY = 1;
                yStep = getHeight();
            } else {
                yStep = getHeight() / numY;
                if (yStep < minStep) {
                    yStep = minStep;
                }
                numY = Math.max(1, (int) Math.ceil(getHeight() / yStep));
            }
            final double minX = getMinX();
            final double maxX = getMaxX();
            final double minY = getMinY();
            final double maxY = getMaxY();
            final int coordinateCount = 1 + 2 * (numX + numY);
            final double[] coordinates = new double[coordinateCount * 2];
            int i = 0;
            coordinates[i++] = maxX;
            coordinates[i++] = minY;
            for (int j = 0; j < numX - 1; j++) {
                final double x = maxX - j * xStep;
                coordinates[i++] = x;
                coordinates[i++] = minY;
            }
            coordinates[i++] = minX;
            coordinates[i++] = minY;
            for (int j = 0; j < numY - 1; j++) {
                final double y = minY + j * yStep;
                coordinates[i++] = minX;
                coordinates[i++] = y;
            }
            coordinates[i++] = minX;
            coordinates[i++] = maxY;
            for (int j = 0; j < numX - 1; j++) {
                final double x = minX + j * xStep;
                coordinates[i++] = x;
                coordinates[i++] = maxY;
            }
            coordinates[i++] = maxX;
            coordinates[i++] = maxY;
            for (int j = 0; j < numY - 1; j++) {
                final double y = minY + (numY - j) * yStep;
                coordinates[i++] = maxX;
                coordinates[i++] = y;
            }
            coordinates[i++] = maxX;
            coordinates[i++] = minY;
            final LinearRing ring = factory.linearRing(2, coordinates);
            final Polygon polygon = factory.polygon(ring);
            if (geometryFactory == null) {
                return polygon;
            } else {
                return (Polygon) polygon.convertGeometry(geometryFactory);
            }
        } catch (final IllegalArgumentException e) {
            Logs.error(this, "Unable to convert to polygon: " + this, e);
            return geometryFactory.polygon();
        }
    }
}
Also used : BoundingBoxDoubleXYGeometryFactory(com.revolsys.geometry.model.impl.BoundingBoxDoubleXYGeometryFactory) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem)

Example 19 with ProjectedCoordinateSystem

use of com.revolsys.geometry.cs.ProjectedCoordinateSystem in project com.revolsys.open by revolsys.

the class LasProjection method setCoordinateSystem.

protected static void setCoordinateSystem(final LasPointCloudHeader header, final CoordinateSystem coordinateSystem) {
    if (coordinateSystem != null) {
        header.removeLasProperties(LASF_PROJECTION);
        final LasPointFormat pointFormat = header.getPointFormat();
        if (pointFormat.getId() <= 5) {
            final int coordinateSystemId = coordinateSystem.getCoordinateSystemId();
            int keyId;
            if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                keyId = TiffImage.PROJECTED_COORDINATE_SYSTEM_ID;
            } else {
                keyId = TiffImage.GEOGRAPHIC_COORDINATE_SYSTEM_ID;
            }
            final ByteArrayOutputStream byteOut = new ByteArrayOutputStream(1024);
            try (final EndianOutput out = new EndianOutputStream(byteOut)) {
                out.writeLEUnsignedShort(1);
                out.writeLEUnsignedShort(1);
                out.writeLEUnsignedShort(0);
                out.writeLEUnsignedShort(1);
                {
                    out.writeLEUnsignedShort(keyId);
                    out.writeLEUnsignedShort(0);
                    out.writeLEUnsignedShort(1);
                    out.writeLEUnsignedShort(coordinateSystemId);
                }
            }
            final byte[] bytes = byteOut.toByteArray();
            final LasVariableLengthRecord property = new LasVariableLengthRecord(LASF_PROJECTION, LASF_PROJECTION_TIFF_GEO_KEY_DIRECTORY_TAG, "TIFF GeoKeyDirectoryTag", bytes, coordinateSystem);
            header.addProperty(property);
        } else {
            final String wkt = EpsgCoordinateSystems.toWkt(coordinateSystem);
            final byte[] stringBytes = wkt.getBytes(StandardCharsets.UTF_8);
            final byte[] bytes = new byte[stringBytes.length + 1];
            System.arraycopy(stringBytes, 0, bytes, 0, stringBytes.length);
            final LasVariableLengthRecord property = new LasVariableLengthRecord(LASF_PROJECTION, LASF_PROJECTION_WKT_COORDINATE_SYSTEM, "WKT", bytes, coordinateSystem);
            header.addProperty(property);
        }
    }
}
Also used : EndianOutput(com.revolsys.io.endian.EndianOutput) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) EndianOutputStream(com.revolsys.io.endian.EndianOutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) LasPointFormat(com.revolsys.elevation.cloud.las.pointformat.LasPointFormat)

Example 20 with ProjectedCoordinateSystem

use of com.revolsys.geometry.cs.ProjectedCoordinateSystem in project com.revolsys.open by revolsys.

the class FactorZoomMode method getBoundingBox.

/**
 * Get the best bounding box matching the zoom mode policy
 *
 * @param viewport The viewport.
 * @param boundingBox The bounding box.
 * @return The bounding box.
 */
@Override
public BoundingBox getBoundingBox(final ComponentViewport2D viewport, final BoundingBox boundingBox) {
    final GeometryFactory geometryFactory = viewport.getGeometryFactory();
    final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
    final GeometryFactory bboxGeometryFactory = boundingBox.getGeometryFactory();
    BoundingBox newBoundingBox = boundingBox;
    if (bboxGeometryFactory == null) {
        newBoundingBox = boundingBox.convert(geometryFactory);
    } else {
        if (bboxGeometryFactory.equals(geometryFactory)) {
            newBoundingBox = boundingBox;
        } else {
            newBoundingBox = boundingBox.convert(geometryFactory);
        }
        if (coordinateSystem instanceof ProjectedCoordinateSystem) {
            final BoundingBox areaBoundingBox = coordinateSystem.getAreaBoundingBox();
            newBoundingBox = boundingBox.intersection(areaBoundingBox);
        }
    }
    final double viewAspectRatio = viewport.getViewAspectRatio();
    final double modelAspectRatio = newBoundingBox.getAspectRatio();
    if (viewAspectRatio != modelAspectRatio) {
        final double width = newBoundingBox.getWidth();
        final double height = newBoundingBox.getHeight();
        if (viewAspectRatio > modelAspectRatio) {
            final double newWidth = height * viewAspectRatio;
            final double deltaX = (newWidth - width) / 2;
            newBoundingBox = newBoundingBox.expand(deltaX, 0);
        } else if (viewAspectRatio < modelAspectRatio) {
            final double newHeight = width / viewAspectRatio;
            final double deltaY = (newHeight - height) / 2;
            newBoundingBox = newBoundingBox.expand(0, deltaY);
        }
    }
    return newBoundingBox;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) BoundingBox(com.revolsys.geometry.model.BoundingBox) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem)

Aggregations

ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)25 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)18 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)15 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)7 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)7 Map (java.util.Map)7 BoundingBox (com.revolsys.geometry.model.BoundingBox)4 Point (com.revolsys.geometry.model.Point)4 Record (com.revolsys.record.Record)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 IntHashMap (com.revolsys.collection.map.IntHashMap)3 ParameterName (com.revolsys.geometry.cs.ParameterName)3 ParameterValue (com.revolsys.geometry.cs.ParameterValue)3 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TreeMap (java.util.TreeMap)3