Search in sources :

Example 1 with LinearUnit

use of com.revolsys.geometry.cs.unit.LinearUnit 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 LinearUnit

use of com.revolsys.geometry.cs.unit.LinearUnit in project com.revolsys.open by revolsys.

the class LasProjection method convertGeoTiffProjection.

@SuppressWarnings("unused")
private static Object convertGeoTiffProjection(final LasPointCloudHeader header, final byte[] bytes) {
    try {
        final List<Double> doubleParams = new ArrayList<>();
        {
            final LasVariableLengthRecord doubleParamsProperty = header.getLasProperty(new Pair<>(LASF_PROJECTION, LASF_PROJECTION_TIFF_GEO_DOUBLE_PARAMS));
            if (doubleParamsProperty != null) {
                final byte[] doubleParamBytes = doubleParamsProperty.getBytes();
                final ByteBuffer buffer = ByteBuffer.wrap(doubleParamBytes);
                buffer.order(ByteOrder.LITTLE_ENDIAN);
                for (int i = 0; i < doubleParamBytes.length / 8; i++) {
                    final double value = buffer.getDouble();
                    doubleParams.add(value);
                }
            }
        }
        byte[] asciiParamsBytes;
        {
            final LasVariableLengthRecord asciiParamsProperty = header.getLasProperty(new Pair<>(LASF_PROJECTION, LASF_PROJECTION_TIFF_GEO_ASCII_PARAMS));
            if (asciiParamsProperty == null) {
                asciiParamsBytes = new byte[0];
            } else {
                asciiParamsBytes = asciiParamsProperty.getBytes();
            }
        }
        final Map<Integer, Object> properties = new LinkedHashMap<>();
        final ByteBuffer buffer = ByteBuffer.wrap(bytes);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        final int keyDirectoryVersion = Buffers.getLEUnsignedShort(buffer);
        final int keyRevision = Buffers.getLEUnsignedShort(buffer);
        final int minorRevision = Buffers.getLEUnsignedShort(buffer);
        final int numberOfKeys = Buffers.getLEUnsignedShort(buffer);
        for (int i = 0; i < numberOfKeys; i++) {
            final int keyId = Buffers.getLEUnsignedShort(buffer);
            final int tagLocation = Buffers.getLEUnsignedShort(buffer);
            final int count = Buffers.getLEUnsignedShort(buffer);
            final int offset = Buffers.getLEUnsignedShort(buffer);
            if (tagLocation == 0) {
                properties.put(keyId, offset);
            } else if (tagLocation == LASF_PROJECTION_TIFF_GEO_DOUBLE_PARAMS) {
                final double value = doubleParams.get(offset);
                properties.put(keyId, value);
            } else if (tagLocation == LASF_PROJECTION_TIFF_GEO_ASCII_PARAMS) {
                final String value = new String(asciiParamsBytes, offset, count, StandardCharsets.US_ASCII);
                properties.put(keyId, value);
            }
        }
        CoordinateSystem coordinateSystem = null;
        int coordinateSystemId = Maps.getInteger(properties, TiffImage.PROJECTED_COORDINATE_SYSTEM_ID, 0);
        if (coordinateSystemId == 0) {
            coordinateSystemId = Maps.getInteger(properties, TiffImage.GEOGRAPHIC_COORDINATE_SYSTEM_ID, 0);
            if (coordinateSystemId != 0) {
                coordinateSystem = EpsgCoordinateSystems.getCoordinateSystem(coordinateSystemId);
            }
        } else if (coordinateSystemId <= 0 || coordinateSystemId == 32767) {
            final int geoSrid = Maps.getInteger(properties, TiffImage.GEOGRAPHIC_COORDINATE_SYSTEM_ID, 0);
            if (geoSrid != 0) {
                if (geoSrid > 0 && geoSrid < 32767) {
                    final GeographicCoordinateSystem geographicCoordinateSystem = EpsgCoordinateSystems.getCoordinateSystem(geoSrid);
                    final String name = "unknown";
                    final CoordinateOperationMethod coordinateOperationMethod = TiffImage.getProjection(properties);
                    final Map<ParameterName, ParameterValue> parameters = new LinkedHashMap<>();
                    TiffImage.addDoubleParameter(parameters, ParameterNames.STANDARD_PARALLEL_1, properties, TiffImage.STANDARD_PARALLEL_1_KEY);
                    TiffImage.addDoubleParameter(parameters, ParameterNames.STANDARD_PARALLEL_2, properties, TiffImage.STANDARD_PARALLEL_2_KEY);
                    TiffImage.addDoubleParameter(parameters, ParameterNames.CENTRAL_MERIDIAN, properties, TiffImage.LONGITUDE_OF_CENTER_2_KEY);
                    TiffImage.addDoubleParameter(parameters, ParameterNames.LATITUDE_OF_ORIGIN, properties, TiffImage.LATITUDE_OF_CENTER_2_KEY);
                    TiffImage.addDoubleParameter(parameters, ParameterNames.FALSE_EASTING, properties, TiffImage.FALSE_EASTING_KEY);
                    TiffImage.addDoubleParameter(parameters, ParameterNames.FALSE_NORTHING, properties, TiffImage.FALSE_NORTHING_KEY);
                    final LinearUnit linearUnit = TiffImage.getLinearUnit(properties);
                    final ProjectedCoordinateSystem projectedCoordinateSystem = new ProjectedCoordinateSystem(coordinateSystemId, name, geographicCoordinateSystem, coordinateOperationMethod, parameters, linearUnit);
                    coordinateSystem = EpsgCoordinateSystems.getCoordinateSystem(projectedCoordinateSystem);
                }
            }
        } else {
            coordinateSystem = EpsgCoordinateSystems.getCoordinateSystem(coordinateSystemId);
        }
        header.setCoordinateSystemInternal(coordinateSystem);
        return coordinateSystem;
    } catch (final IOException e) {
        throw Exceptions.wrap(e);
    }
}
Also used : LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) ArrayList(java.util.ArrayList) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) LinkedHashMap(java.util.LinkedHashMap) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Pair(com.revolsys.util.Pair)

Example 3 with LinearUnit

use of com.revolsys.geometry.cs.unit.LinearUnit in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystems method newCoordinateSystemGeocentric.

private static GeocentricCoordinateSystem newCoordinateSystemGeocentric(final int id, final String name, final Datum datum, final List<Axis> axis, final Area area, final boolean deprecated) {
    final EpsgAuthority authority = new EpsgAuthority(id);
    final LinearUnit linearUnit = (LinearUnit) axis.get(0).getUnit();
    final GeodeticDatum geodeticDatum = (GeodeticDatum) datum;
    return new GeocentricCoordinateSystem(id, name, geodeticDatum, linearUnit, axis, area, authority, deprecated);
}
Also used : GeocentricCoordinateSystem(com.revolsys.geometry.cs.GeocentricCoordinateSystem) LinearUnit(com.revolsys.geometry.cs.unit.LinearUnit) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum)

Example 4 with LinearUnit

use of com.revolsys.geometry.cs.unit.LinearUnit 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 5 with LinearUnit

use of com.revolsys.geometry.cs.unit.LinearUnit in project com.revolsys.open by revolsys.

the class EsriCsWktWriter method write.

public static void write(final Writer out, final VerticalCoordinateSystem coordinateSystem, final int indentLevel) throws IOException {
    out.write("VERTCS[");
    write(out, coordinateSystem.getCoordinateSystemName(), incrementIndent(indentLevel));
    final VerticalDatum datum = coordinateSystem.getDatum();
    if (datum != null) {
        out.write(",");
        indent(out, incrementIndent(indentLevel));
        write(out, datum, 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) VerticalDatum(com.revolsys.geometry.cs.datum.VerticalDatum) ParameterName(com.revolsys.geometry.cs.ParameterName)

Aggregations

LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)17 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)9 ParameterName (com.revolsys.geometry.cs.ParameterName)8 Map (java.util.Map)8 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)7 ParameterValue (com.revolsys.geometry.cs.ParameterValue)7 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)7 LinkedHashMap (java.util.LinkedHashMap)7 Authority (com.revolsys.geometry.cs.Authority)4 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 VerticalDatum (com.revolsys.geometry.cs.datum.VerticalDatum)4 ChannelReader (com.revolsys.io.channels.ChannelReader)4 WrappedException (com.revolsys.util.WrappedException)4 EOFException (java.io.EOFException)4 IntHashMap (com.revolsys.collection.map.IntHashMap)3 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)3 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)3 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)3 HashMap (java.util.HashMap)3 Maps (com.revolsys.collection.map.Maps)2