Search in sources :

Example 1 with ParameterValueNumber

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

the class UsgsGriddedElevationReader method readHeader.

private void readHeader() {
    try {
        if (readBuffer()) {
            final String fileName = getString(40);
            final String descriptor = getString(40);
            // Blank 81 - 109
            skip(29);
            final String seGeographic = getString(26);
            final String processCode = getString(1);
            // Blank 137
            skip(1);
            final String sectionIndicator = getString(3);
            final String originCode = getString(4);
            final int demLevelCode = getInteger();
            final int elevationPattern = getInteger();
            final int planimetricReferenceSystem = getInteger();
            final int zone = getInteger();
            final double[] projectionParameters = new double[15];
            for (int i = 0; i < projectionParameters.length; i++) {
                projectionParameters[i] = getDoubleSci();
            }
            final int planimetricUom = getInteger();
            final int verticalUom = getInteger();
            this.polygonBounds = getPolygonCoordinates();
            final double min = getDouble24();
            final double max = getDouble24();
            final double angle = getDouble24();
            if (angle != 0) {
                throw new IllegalArgumentException("Angle=" + angle + " not currently supported for USGS DEM: " + this.resource);
            }
            final int verticalAccuracy = getInteger();
            final double resolutionX = getDouble12();
            final double resolutionY = getDouble12();
            if (resolutionX != resolutionY) {
                throw new IllegalArgumentException("resolutionX " + resolutionX + " != " + resolutionY + " resolutionY for USGS DEM: " + this.resource);
            }
            this.resolutionX = (int) resolutionX;
            this.resolutionY = (int) resolutionY;
            if (resolutionX != this.resolutionX) {
                throw new IllegalArgumentException("resolutionX " + resolutionX + " must currently be an integer for USGS DEM: " + this.resource);
            }
            this.resolutionZ = getDouble12();
            this.rasterRowCount = getInteger();
            this.rasterColCount = getInteger();
            final Short largestContourInterval = getShort();
            final Byte largestContourIntervalUnits = getByte();
            final Short smallestContourInterval = getShort();
            final Byte smallest = getByte();
            final Integer sourceYear = getInteger(4);
            final Integer revisionYear = getInteger(4);
            final String inspectionFlag = getString(1);
            final String dataValidationFlag = getString(1);
            final String suspectAndVoidAreaFlag = getString(1);
            final Integer verticalDatum = getInteger(2);
            final Integer horizontalDatum = getInteger(2);
            final Integer dataEdition = getInteger(4);
            final Integer percentVoid = getInteger(4);
            final Integer edgeMatchWest = getInteger(2);
            final Integer edgeMatchNorth = getInteger(2);
            final Integer edgeMatchEast = getInteger(2);
            final Integer edgeMatchSouth = getInteger(2);
            final Double verticalDatumShift = getDouble(7);
            LinearUnit linearUnit = null;
            if (planimetricUom == 1) {
                linearUnit = EpsgCoordinateSystems.getLinearUnit("foot");
            } else if (planimetricUom == 2) {
                linearUnit = EpsgCoordinateSystems.getLinearUnit("metre");
            }
            GeographicCoordinateSystem geographicCoordinateSystem;
            switch(horizontalDatum) {
                case 0:
                    geographicCoordinateSystem = null;
                    break;
                case 1:
                    geographicCoordinateSystem = (GeographicCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem("NAD27");
                    break;
                case 2:
                    geographicCoordinateSystem = (GeographicCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem("WGS 72");
                    break;
                case 3:
                    geographicCoordinateSystem = (GeographicCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem("WGS 84");
                    break;
                case 4:
                    geographicCoordinateSystem = (GeographicCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem("NAD83");
                    break;
                default:
                    throw new IllegalArgumentException("horizontalDatum=" + horizontalDatum + " not currently supported for USGS DEM: " + this.resource);
            }
            final double scaleZ = 1.0 / this.resolutionZ;
            int coordinateSystemId = 0;
            CoordinateSystem coordinateSystem = null;
            if (0 == planimetricReferenceSystem) {
                coordinateSystemId = geographicCoordinateSystem.getCoordinateSystemId();
            } else if (1 == planimetricReferenceSystem) {
                coordinateSystemId = 26900 + zone;
            } else if (2 == planimetricReferenceSystem) {
                throw new IllegalArgumentException("planimetricReferenceSystem=" + planimetricReferenceSystem + " not currently supported for USGS DEM: " + this.resource);
            } else if (3 == planimetricReferenceSystem) {
                final Map<ParameterName, ParameterValue> parameters = new LinkedHashMap<>();
                parameters.put(ParameterNames.CENTRAL_MERIDIAN, fromDms(projectionParameters[4]));
                parameters.put(ParameterNames.STANDARD_PARALLEL_1, fromDms(projectionParameters[2]));
                parameters.put(ParameterNames.STANDARD_PARALLEL_2, fromDms(projectionParameters[3]));
                parameters.put(ParameterNames.LATITUDE_OF_ORIGIN, fromDms(projectionParameters[5]));
                parameters.put(ParameterNames.FALSE_EASTING, new ParameterValueNumber(projectionParameters[6]));
                parameters.put(ParameterNames.FALSE_NORTHING, new ParameterValueNumber(projectionParameters[7]));
                final CoordinateOperationMethod coordinateOperationMethod = new CoordinateOperationMethod("Albers_Equal_Area");
                final ProjectedCoordinateSystem projectedCoordinateSystem = new ProjectedCoordinateSystem(-1, "", geographicCoordinateSystem, coordinateOperationMethod, parameters, linearUnit);
                final ProjectedCoordinateSystem projectedCoordinateSystem2 = (ProjectedCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem(projectedCoordinateSystem);
                if (projectedCoordinateSystem2 == projectedCoordinateSystem || projectedCoordinateSystem2 == null) {
                    coordinateSystem = projectedCoordinateSystem2;
                } else {
                    coordinateSystemId = projectedCoordinateSystem2.getCoordinateSystemId();
                }
            } else {
                throw new IllegalArgumentException("planimetricReferenceSystem=" + planimetricReferenceSystem + " not currently supported for USGS DEM: " + this.resource);
            }
            if (coordinateSystemId > 0) {
                this.geometryFactory = GeometryFactory.fixed3d(coordinateSystemId, 0, 0, scaleZ);
            } else if (coordinateSystem == null) {
                throw new IllegalArgumentException("No coordinate system found: " + this.resource);
            } else {
                this.geometryFactory = GeometryFactory.fixed3d(coordinateSystem, 0, 0, scaleZ);
            }
            final Polygon polygon = this.geometryFactory.polygon(this.geometryFactory.linearRing(2, this.polygonBounds));
            this.boundingBox = polygon.getBoundingBox();
        }
    } catch (final Exception e) {
        try {
            close();
        } catch (final Exception e1) {
        }
        throw Exceptions.wrap(e);
    }
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) ParameterValueNumber(com.revolsys.geometry.cs.ParameterValueNumber) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) IOException(java.io.IOException) NoSuchResourceException(com.revolsys.spring.resource.NoSuchResourceException) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Polygon(com.revolsys.geometry.model.Polygon) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with ParameterValueNumber

use of com.revolsys.geometry.cs.ParameterValueNumber 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)2 ParameterValueNumber (com.revolsys.geometry.cs.ParameterValueNumber)2 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)2 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)1 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)1 ParameterName (com.revolsys.geometry.cs.ParameterName)1 ParameterValue (com.revolsys.geometry.cs.ParameterValue)1 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)1 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)1 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)1 UnitOfMeasure (com.revolsys.geometry.cs.unit.UnitOfMeasure)1 Polygon (com.revolsys.geometry.model.Polygon)1 ChannelReader (com.revolsys.io.channels.ChannelReader)1 WrappedException (com.revolsys.util.WrappedException)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1