Search in sources :

Example 6 with CoordinateOperationMethod

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

the class EsriCsWktWriter method write.

public static void write(final Writer out, final ProjectedCoordinateSystem coordinateSystem, final int indentLevel) throws IOException {
    out.write("PROJCS[");
    write(out, coordinateSystem.getCoordinateSystemName(), incrementIndent(indentLevel));
    final GeographicCoordinateSystem geoCs = coordinateSystem.getGeographicCoordinateSystem();
    if (geoCs != null) {
        out.write(",");
        indent(out, incrementIndent(indentLevel));
        write(out, geoCs, incrementIndent(indentLevel));
    }
    final CoordinateOperationMethod coordinateOperationMethod = coordinateSystem.getCoordinateOperationMethod();
    if (coordinateOperationMethod != null) {
        out.write(",");
        indent(out, incrementIndent(indentLevel));
        write(out, coordinateOperationMethod, incrementIndent(indentLevel));
    }
    for (final Entry<ParameterName, ParameterValue> parameter : coordinateSystem.getParameterValues().entrySet()) {
        final ParameterName name = parameter.getKey();
        final ParameterValue value = parameter.getValue();
        write(out, name, value, incrementIndent(indentLevel));
    }
    final LinearUnit unit = coordinateSystem.getLinearUnit();
    if (unit != null) {
        write(out, unit, incrementIndent(indentLevel));
    }
    indent(out, indentLevel);
    out.write(']');
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValue(com.revolsys.geometry.cs.ParameterValue) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) ParameterName(com.revolsys.geometry.cs.ParameterName) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Example 7 with CoordinateOperationMethod

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

the class ProjectionFactory method newCoordinatesProjection.

public static CoordinatesProjection newCoordinatesProjection(final ProjectedCoordinateSystem coordinateSystem) {
    final CoordinateOperationMethod coordinateOperationMethod = coordinateSystem.getCoordinateOperationMethod();
    final String projectionName = coordinateOperationMethod.getNormalizedName();
    synchronized (projectionClasses) {
        final Class<? extends CoordinatesProjection> projectionClass = projectionClasses.get(projectionName);
        if (projectionClass == null) {
            return null;
        } else {
            try {
                final Constructor<? extends CoordinatesProjection> constructor = projectionClass.getConstructor(ProjectedCoordinateSystem.class);
                final CoordinatesProjection coordinateProjection = constructor.newInstance(coordinateSystem);
                return coordinateProjection;
            } catch (final NoSuchMethodException e) {
                throw new IllegalArgumentException("Constructor " + projectionClass + "(" + ProjectedCoordinateSystem.class.getName() + ") does not exist");
            } catch (final InstantiationException e) {
                throw new IllegalArgumentException(projectionClass + " cannot be instantiated", e);
            } catch (final IllegalAccessException e) {
                throw new IllegalArgumentException(projectionClass + " cannot be instantiated", e);
            } catch (final InvocationTargetException e) {
                final Throwable cause = e.getCause();
                if (cause instanceof RuntimeException) {
                    throw (RuntimeException) cause;
                } else if (cause instanceof Error) {
                    throw (Error) cause;
                } else {
                    throw new IllegalArgumentException(projectionClass + " cannot be instantiated", cause);
                }
            }
        }
    }
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod)

Example 8 with CoordinateOperationMethod

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

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

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

the class EpsgCoordinateSystems method loadCoordOperationParamValue.

private static void loadCoordOperationParamValue(final IntHashMap<CoordinateOperationMethod> methodById, final IntHashMap<Map<ParameterName, ParameterValue>> operationParameters, final IntHashMap<List<Byte>> paramReversal) {
    try (ChannelReader reader = newChannelReader("coordOperationParamValue")) {
        while (true) {
            final int operationId = reader.getInt();
            final CoordinateOperationMethod method = readCode(reader, methodById);
            final ParameterName parameterName = readCode(reader, PARAM_NAME_BY_ID);
            final double value = reader.getDouble();
            final String fileRef = reader.getStringUtf8ByteCount();
            final UnitOfMeasure unit = readCode(reader, UNIT_BY_ID);
            final ParameterValue parameterValue;
            if (Double.isFinite(value)) {
                if (Property.hasValue(fileRef)) {
                    throw new IllegalArgumentException("Cannot have a value and fileRef for coordOperationParamValue=" + operationId + " " + parameterName);
                } else {
                    parameterValue = new ParameterValueNumber(unit, value);
                }
            } else {
                if (Property.hasValue(fileRef)) {
                    parameterValue = new ParameterValueString(fileRef);
                } else {
                    parameterValue = null;
                }
            }
            Map<ParameterName, ParameterValue> parameterValues = operationParameters.get(operationId);
            if (parameterValues == null) {
                parameterValues = Maps.newLinkedHash();
                final List<ParameterName> parameterOrder = method.getParameterNames();
                for (final ParameterName orderParameterName : parameterOrder) {
                    parameterValues.put(orderParameterName, null);
                }
                operationParameters.put(operationId, parameterValues);
            }
            method.setParameter(parameterValues, parameterName, parameterValue);
        }
    } catch (final NoSuchResourceException e) {
    } catch (final WrappedException e) {
        if (Exceptions.isException(e, EOFException.class)) {
        } else {
            Logs.error(EpsgCoordinateSystems.class, "Error loading coordOperationParamValue", e);
        }
    }
}
Also used : WrappedException(com.revolsys.util.WrappedException) ParameterValueNumber(com.revolsys.geometry.cs.ParameterValueNumber) UnitOfMeasure(com.revolsys.geometry.cs.unit.UnitOfMeasure) ParameterValue(com.revolsys.geometry.cs.ParameterValue) ParameterName(com.revolsys.geometry.cs.ParameterName) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) ChannelReader(com.revolsys.io.channels.ChannelReader) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) EOFException(java.io.EOFException)

Aggregations

CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)14 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)8 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)7 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)7 ParameterName (com.revolsys.geometry.cs.ParameterName)6 Map (java.util.Map)6 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)5 IntHashMap (com.revolsys.collection.map.IntHashMap)4 ParameterValue (com.revolsys.geometry.cs.ParameterValue)4 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)4 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)4 ChannelReader (com.revolsys.io.channels.ChannelReader)3 WrappedException (com.revolsys.util.WrappedException)3 EOFException (java.io.EOFException)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 TreeMap (java.util.TreeMap)3 Area (com.revolsys.geometry.cs.Area)2 Authority (com.revolsys.geometry.cs.Authority)2 ParameterValueNumber (com.revolsys.geometry.cs.ParameterValueNumber)2