Search in sources :

Example 6 with Authority

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

the class EsriCoordinateSystems method getVerticalCoordinateSystem.

public static VerticalCoordinateSystem getVerticalCoordinateSystem(final int id) {
    VerticalCoordinateSystem coordinateSystem = (VerticalCoordinateSystem) COORDINATE_SYSTEM_BY_ID.get(id);
    if (coordinateSystem == null) {
        try (final ChannelReader reader = ChannelReader.newChannelReader("classpath:CoordinateSystems/esri/Vertical.cs")) {
            while (true) {
                final int coordinateSystemId = reader.getInt();
                final String csName = reader.getStringUtf8ByteCount();
                final String datumName = reader.getStringUtf8ByteCount();
                final Map<ParameterName, ParameterValue> parameters = readParameters(reader);
                final String linearUnitName = reader.getStringUtf8ByteCount();
                final double conversionFactor = reader.getDouble();
                if (id == coordinateSystemId) {
                    final VerticalDatum verticalDatum = new VerticalDatum(null, datumName, 0);
                    LinearUnit linearUnit = LINEAR_UNITS_BY_NAME.get(linearUnitName);
                    if (linearUnit == null) {
                        linearUnit = new LinearUnit(linearUnitName, conversionFactor, null);
                        LINEAR_UNITS_BY_NAME.put(linearUnitName, linearUnit);
                    }
                    final Authority authority = new BaseAuthority("ESRI", coordinateSystemId);
                    coordinateSystem = new VerticalCoordinateSystem(authority, csName, verticalDatum, parameters, linearUnit, Collections.emptyList());
                    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) ParameterName(com.revolsys.geometry.cs.ParameterName) SingleParameterName(com.revolsys.geometry.cs.SingleParameterName) VerticalDatum(com.revolsys.geometry.cs.datum.VerticalDatum) ChannelReader(com.revolsys.io.channels.ChannelReader) VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) EOFException(java.io.EOFException)

Example 7 with Authority

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

the class EpsgCoordinateSystems method getCoordinateSystem.

public static synchronized CoordinateSystem getCoordinateSystem(final CoordinateSystem coordinateSystem) {
    initialize();
    if (coordinateSystem == null) {
        return null;
    } else {
        int srid = coordinateSystem.getCoordinateSystemId();
        CoordinateSystem matchedCoordinateSystem = coordinateSystemsById.get(srid);
        if (matchedCoordinateSystem == null) {
            matchedCoordinateSystem = coordinateSystemsByName.get(coordinateSystem.getCoordinateSystemName());
            if (matchedCoordinateSystem == null) {
                final int hashCode = coordinateSystem.hashCode();
                int matchCoordinateSystemId = 0;
                final List<CoordinateSystem> coordinateSystems = coordinateSystemsByCoordinateSystem.get(hashCode);
                if (coordinateSystems != null) {
                    for (final CoordinateSystem coordinateSystem3 : coordinateSystems) {
                        if (coordinateSystem3.equals(coordinateSystem)) {
                            final int srid3 = coordinateSystem3.getCoordinateSystemId();
                            if (matchedCoordinateSystem == null) {
                                matchedCoordinateSystem = coordinateSystem3;
                                matchCoordinateSystemId = srid3;
                            } else if (srid3 < matchCoordinateSystemId) {
                                if (!coordinateSystem3.isDeprecated() || matchedCoordinateSystem.isDeprecated()) {
                                    matchedCoordinateSystem = coordinateSystem3;
                                    matchCoordinateSystemId = srid3;
                                }
                            }
                        }
                    }
                }
                if (matchedCoordinateSystem == null) {
                    if (srid <= 0) {
                        srid = nextSrid++;
                    }
                    final String name = coordinateSystem.getCoordinateSystemName();
                    final List<Axis> axis = coordinateSystem.getAxis();
                    final Area area = coordinateSystem.getArea();
                    final Authority authority = coordinateSystem.getAuthority();
                    final boolean deprecated = coordinateSystem.isDeprecated();
                    if (coordinateSystem instanceof GeographicCoordinateSystem) {
                        final GeographicCoordinateSystem geographicCs = (GeographicCoordinateSystem) coordinateSystem;
                        final GeodeticDatum geodeticDatum = geographicCs.getDatum();
                        final PrimeMeridian primeMeridian = geographicCs.getPrimeMeridian();
                        final CoordinateSystem sourceCoordinateSystem = geographicCs.getSourceCoordinateSystem();
                        final CoordinateOperation coordinateOperation = geographicCs.getCoordinateOperation();
                        final GeographicCoordinateSystem newCs = new GeographicCoordinateSystem(srid, name, geodeticDatum, primeMeridian, axis, area, sourceCoordinateSystem, coordinateOperation, deprecated);
                        addCoordinateSystem(newCs);
                        return newCs;
                    } else if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                        final ProjectedCoordinateSystem projectedCs = (ProjectedCoordinateSystem) coordinateSystem;
                        GeographicCoordinateSystem geographicCs = projectedCs.getGeographicCoordinateSystem();
                        geographicCs = (GeographicCoordinateSystem) getCoordinateSystem(geographicCs);
                        final CoordinateOperationMethod coordinateOperationMethod = projectedCs.getCoordinateOperationMethod();
                        final Map<ParameterName, ParameterValue> parameters = projectedCs.getParameterValues();
                        final LinearUnit linearUnit = projectedCs.getLinearUnit();
                        final ProjectedCoordinateSystem newCs = new ProjectedCoordinateSystem(srid, name, geographicCs, area, coordinateOperationMethod, parameters, linearUnit, axis, authority, deprecated);
                        addCoordinateSystem(newCs);
                        return newCs;
                    }
                    return coordinateSystem;
                }
            }
        }
        return matchedCoordinateSystem;
    }
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) Authority(com.revolsys.geometry.cs.Authority) 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) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) PrimeMeridian(com.revolsys.geometry.cs.PrimeMeridian) Area(com.revolsys.geometry.cs.Area) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Map(java.util.Map) IntHashMap(com.revolsys.collection.map.IntHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Axis(com.revolsys.geometry.cs.Axis)

Example 8 with Authority

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

the class EpsgCsWktWriter method write.

public static void write(final PrintWriter out, final AngularUnit unit) {
    if (unit != null) {
        out.print(",UNIT[");
        write(out, unit.getName());
        out.write(',');
        out.print(unit.getConversionFactor());
        final Authority authority = unit.getAuthority();
        write(out, authority);
        out.write(']');
    }
}
Also used : Authority(com.revolsys.geometry.cs.Authority)

Example 9 with Authority

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

the class EpsgCsWktWriter method write.

public static void write(final PrintWriter out, final LinearUnit unit) {
    if (unit != null) {
        out.print(",UNIT[");
        write(out, unit.getName());
        out.write(',');
        write(out, unit.getConversionFactor());
        final Authority authority = unit.getAuthority();
        write(out, authority);
        out.write(']');
    }
}
Also used : Authority(com.revolsys.geometry.cs.Authority)

Example 10 with Authority

use of com.revolsys.geometry.cs.Authority 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)

Aggregations

Authority (com.revolsys.geometry.cs.Authority)14 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)4 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)4 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)4 ChannelReader (com.revolsys.io.channels.ChannelReader)4 WrappedException (com.revolsys.util.WrappedException)4 EOFException (java.io.EOFException)4 BaseAuthority (com.revolsys.geometry.cs.BaseAuthority)3 ParameterName (com.revolsys.geometry.cs.ParameterName)3 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)3 GeodeticDatum (com.revolsys.geometry.cs.datum.GeodeticDatum)3 Area (com.revolsys.geometry.cs.Area)2 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)2 Ellipsoid (com.revolsys.geometry.cs.Ellipsoid)2 ParameterValue (com.revolsys.geometry.cs.ParameterValue)2 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)2 SingleParameterName (com.revolsys.geometry.cs.SingleParameterName)2 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)2 AngularUnit (com.revolsys.geometry.cs.unit.AngularUnit)2 IntHashMap (com.revolsys.collection.map.IntHashMap)1