Search in sources :

Example 16 with GeographicCoordinateSystem

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

the class EpsgCoordinateSystems method loadCoordinateReferenceSystem.

private static void loadCoordinateReferenceSystem(final IntHashMap<List<Axis>> axisMap) {
    try (ChannelReader reader = newChannelReader("coordinateReferenceSystem")) {
        while (true) {
            final int id = reader.getInt();
            final String name = reader.getStringUtf8ByteCount();
            final Area area = readCode(reader, AREA_BY_ID);
            final int type = reader.getByte();
            final CoordinateSystemType coordinateSystemType = readCode(reader, COORDINATE_SYSTEM_TYPE_BY_ID);
            final Datum datum = readCode(reader, DATUM_BY_ID);
            final CoordinateSystem sourceCoordinateSystem = readCode(reader, COORDINATE_SYSTEM_BY_ID);
            final CoordinateOperation operation = readCode(reader, OPERATION_BY_ID);
            final CoordinateSystem horizontalCoordinateSystem = readCode(reader, COORDINATE_SYSTEM_BY_ID);
            final VerticalCoordinateSystem verticalCoordinateSystem = (VerticalCoordinateSystem) readCode(reader, COORDINATE_SYSTEM_BY_ID);
            final boolean deprecated = readBoolean(reader);
            final List<Axis> axis;
            if (coordinateSystemType == null) {
                axis = null;
            } else {
                axis = axisMap.get(coordinateSystemType.getId());
            }
            CoordinateSystem coordinateSystem = null;
            if (type == 0) {
                // geocentric
                coordinateSystem = newCoordinateSystemGeocentric(id, name, datum, axis, area, deprecated);
            } else if (type == 1) {
                // geographic 3D
                coordinateSystem = new GeographicCoordinateSystem(id, name, (GeodeticDatum) datum, axis, area, sourceCoordinateSystem, operation, deprecated);
            } else if (type == 2) {
                // geographic 2D
                coordinateSystem = new GeographicCoordinateSystem(id, name, (GeodeticDatum) datum, axis, area, sourceCoordinateSystem, operation, deprecated);
            } else if (type == 3) {
                // projected
                coordinateSystem = newCoordinateSystemProjected(id, name, area, sourceCoordinateSystem, operation, axis, deprecated);
            } else if (type == 4) {
                // engineering
                coordinateSystem = new EngineeringCoordinateSystem(id, name, (EngineeringDatum) datum, axis, area, deprecated);
            } else if (type == 5) {
                // vertical
                coordinateSystem = new VerticalCoordinateSystem(id, name, (VerticalDatum) datum, axis, area, deprecated);
            } else if (type == 6) {
                coordinateSystem = new CompoundCoordinateSystem(id, name, horizontalCoordinateSystem, verticalCoordinateSystem, area, deprecated);
            } else {
                coordinateSystem = null;
            }
            addCoordinateSystem(coordinateSystem);
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            throw e;
        }
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) Datum(com.revolsys.geometry.cs.datum.Datum) EngineeringDatum(com.revolsys.geometry.cs.datum.EngineeringDatum) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum) VerticalDatum(com.revolsys.geometry.cs.datum.VerticalDatum) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) GeocentricCoordinateSystem(com.revolsys.geometry.cs.GeocentricCoordinateSystem) CompoundCoordinateSystem(com.revolsys.geometry.cs.CompoundCoordinateSystem) VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) EngineeringCoordinateSystem(com.revolsys.geometry.cs.EngineeringCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) CoordinateSystemType(com.revolsys.geometry.cs.CoordinateSystemType) CompoundCoordinateSystem(com.revolsys.geometry.cs.CompoundCoordinateSystem) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) EngineeringCoordinateSystem(com.revolsys.geometry.cs.EngineeringCoordinateSystem) NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) EngineeringDatum(com.revolsys.geometry.cs.datum.EngineeringDatum) Area(com.revolsys.geometry.cs.Area) ChannelReader(com.revolsys.io.channels.ChannelReader) VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) EOFException(java.io.EOFException) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Axis(com.revolsys.geometry.cs.Axis)

Example 17 with GeographicCoordinateSystem

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

the class EpsgCsWktWriter method write.

public static void write(final PrintWriter out, final ProjectedCoordinateSystem coordinateSystem) {
    if (coordinateSystem != null) {
        out.print("PROJCS[");
        write(out, coordinateSystem.getCoordinateSystemName());
        final GeographicCoordinateSystem geoCs = coordinateSystem.getGeographicCoordinateSystem();
        out.print(",");
        write(out, geoCs);
        final CoordinateOperationMethod coordinateOperationMethod = coordinateSystem.getCoordinateOperationMethod();
        write(out, coordinateOperationMethod);
        for (final Entry<ParameterName, Object> parameter : coordinateSystem.getParameters().entrySet()) {
            final ParameterName name = parameter.getKey();
            final Object value = parameter.getValue();
            write(out, name, value);
        }
        final LinearUnit unit = coordinateSystem.getLinearUnit();
        if (unit != null) {
            write(out, unit);
        }
        final Authority authority = coordinateSystem.getAuthority();
        write(out, authority);
        out.write(']');
    }
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) Authority(com.revolsys.geometry.cs.Authority) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) ParameterName(com.revolsys.geometry.cs.ParameterName) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Example 18 with GeographicCoordinateSystem

use of com.revolsys.geometry.cs.GeographicCoordinateSystem 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 19 with GeographicCoordinateSystem

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

the class EsriCoordinateSystems method getGeographicCoordinateSystem.

public static GeographicCoordinateSystem getGeographicCoordinateSystem(final int id) {
    GeographicCoordinateSystem coordinateSystem = (GeographicCoordinateSystem) COORDINATE_SYSTEM_BY_ID.get(id);
    if (coordinateSystem == null) {
        try (final ChannelReader reader = ChannelReader.newChannelReader("classpath:CoordinateSystems/esri/Geographic.cs")) {
            while (true) {
                final int coordinateSystemId = reader.getInt();
                final String csName = reader.getStringUtf8ByteCount();
                final String datumName = reader.getStringUtf8ByteCount();
                final String spheroidName = reader.getStringUtf8ByteCount();
                final double semiMajorAxis = reader.getDouble();
                final double inverseFlattening = reader.getDouble();
                final String primeMeridianName = reader.getStringUtf8ByteCount();
                final double longitude = reader.getDouble();
                final String angularUnitName = reader.getStringUtf8ByteCount();
                final double conversionFactor = reader.getDouble();
                if (id == coordinateSystemId) {
                    final Ellipsoid ellipsoid = new Ellipsoid(spheroidName, semiMajorAxis, inverseFlattening, null);
                    final PrimeMeridian primeMeridian = new PrimeMeridian(primeMeridianName, longitude, null);
                    final GeodeticDatum geodeticDatum = new GeodeticDatum(null, datumName, null, false, ellipsoid, primeMeridian);
                    AngularUnit angularUnit = ANGULAR_UNITS_BY_NAME.get(angularUnitName);
                    if (angularUnit == null) {
                        angularUnit = new AngularUnit(angularUnitName, conversionFactor, null);
                        ANGULAR_UNITS_BY_NAME.put(angularUnitName, angularUnit);
                    }
                    final Authority authority = new BaseAuthority("ESRI", coordinateSystemId);
                    coordinateSystem = new GeographicCoordinateSystem(coordinateSystemId, csName, geodeticDatum, primeMeridian, angularUnit, null, 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) Authority(com.revolsys.geometry.cs.Authority) BaseAuthority(com.revolsys.geometry.cs.BaseAuthority) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum) PrimeMeridian(com.revolsys.geometry.cs.PrimeMeridian) AngularUnit(com.revolsys.geometry.cs.unit.AngularUnit) ChannelReader(com.revolsys.io.channels.ChannelReader) EOFException(java.io.EOFException) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Ellipsoid(com.revolsys.geometry.cs.Ellipsoid)

Example 20 with GeographicCoordinateSystem

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

the class BoundingBox method clipToCoordinateSystem.

/**
 * If the coordinate system is a projected coordinate system then clip to the {@link CoordinateSystem#getAreaBoundingBox()}.
 */
default BoundingBox clipToCoordinateSystem() {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
    if (coordinateSystem == null || coordinateSystem instanceof GeographicCoordinateSystem) {
        return this;
    } else {
        final BoundingBox areaBoundingBox = coordinateSystem.getAreaBoundingBox();
        return intersection(areaBoundingBox);
    }
}
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) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Aggregations

GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)28 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)19 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)13 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)9 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)8 Map (java.util.Map)7 ParameterName (com.revolsys.geometry.cs.ParameterName)5 BoundingBox (com.revolsys.geometry.model.BoundingBox)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 Authority (com.revolsys.geometry.cs.Authority)4 ParameterValue (com.revolsys.geometry.cs.ParameterValue)4 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)4 GeodeticDatum (com.revolsys.geometry.cs.datum.GeodeticDatum)4 IOException (java.io.IOException)4 CompoundCoordinateSystem (com.revolsys.geometry.cs.CompoundCoordinateSystem)3 EngineeringCoordinateSystem (com.revolsys.geometry.cs.EngineeringCoordinateSystem)3 GeocentricCoordinateSystem (com.revolsys.geometry.cs.GeocentricCoordinateSystem)3 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)3