Search in sources :

Example 1 with Ellipsoid

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

the class EpsgCoordinateSystems method loadDatum.

private static void loadDatum() {
    final IntHashMap<Ellipsoid> ellipsoids = loadEllipsoid();
    try (ChannelReader reader = newChannelReader("datum")) {
        while (true) {
            final int id = reader.getInt();
            final String name = reader.getStringUtf8ByteCount();
            final int datumType = reader.getByte();
            final Ellipsoid ellipsoid = readCode(reader, ellipsoids);
            final PrimeMeridian primeMeridian = readCode(reader, PRIME_MERIDIAN_BY_ID);
            final Area area = readCode(reader, AREA_BY_ID);
            final boolean deprecated = readBoolean(reader);
            final EpsgAuthority authority = new EpsgAuthority(id);
            Datum datum;
            if (datumType == 0) {
                datum = new GeodeticDatum(authority, name, area, deprecated, ellipsoid, primeMeridian);
            } else if (datumType == 1) {
                datum = new VerticalDatum(authority, name, area, deprecated);
            } else if (datumType == 2) {
                datum = new EngineeringDatum(authority, name, area, deprecated);
            } else {
                throw new IllegalArgumentException("Unknown datumType=" + datumType);
            }
            DATUM_BY_ID.put(id, datum);
        }
    } 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) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum) VerticalDatum(com.revolsys.geometry.cs.datum.VerticalDatum) ParameterValueString(com.revolsys.geometry.cs.ParameterValueString) PrimeMeridian(com.revolsys.geometry.cs.PrimeMeridian) 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) EOFException(java.io.EOFException) Ellipsoid(com.revolsys.geometry.cs.Ellipsoid)

Example 2 with Ellipsoid

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

the class EsriCsWktWriter method write.

public static void write(final Writer out, final GeodeticDatum geodeticDatum, final int indentLevel) throws IOException {
    out.write("DATUM[");
    write(out, geodeticDatum.getName(), incrementIndent(indentLevel));
    final Ellipsoid ellipsoid = geodeticDatum.getEllipsoid();
    if (ellipsoid != null) {
        out.write(",");
        indent(out, incrementIndent(indentLevel));
        write(out, ellipsoid, incrementIndent(indentLevel));
    }
    indent(out, indentLevel);
    out.write(']');
}
Also used : Ellipsoid(com.revolsys.geometry.cs.Ellipsoid)

Example 3 with Ellipsoid

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

the class TransverseMercatorTest method testMascotThomas.

// @Test
// public void testMascotJhs() {
// testUtmMascot(TransverseMercatorJhs::newUtm);
// }
@Test
public void testMascotThomas() {
    final Map<Integer, CoordinatesProjection> projectionById = new HashMap<>();
    try (RecordReader recordReader = RecordReader.newRecordReader("../../com.revolsys.open-testdata/cs/transverseMercator/mascot.csv")) {
        for (final Record record : recordReader) {
            final String monumentId = record.getValue("monumentId");
            final int longitudeDegrees = record.getInteger("longitudeDegrees");
            final int longitudeMinutes = record.getInteger("longitudeMinutes");
            final double longitudeSeconds = record.getDouble("longitudeSeconds");
            final int latitudeDegrees = record.getInteger("latitudeDegrees");
            final int latitudeMinutes = record.getInteger("latitudeMinutes");
            final double latitudeSeconds = record.getDouble("latitudeSeconds");
            final double lon = record.getDouble("lon");
            final double lat = record.getDouble("lat");
            final double lonCalc = Angle.toDecimalDegrees(longitudeDegrees, longitudeMinutes, longitudeSeconds);
            final double latCalc = Angle.toDecimalDegrees(latitudeDegrees, latitudeMinutes, latitudeSeconds);
            final String lonStringCalc = Angle.toDegreesMinutesSecondsLon(lon, 5);
            final String latStringCalc = Angle.toDegreesMinutesSecondsLat(lat, 5);
            Assert.assertEquals(monumentId + "\tlon", lon, lonCalc, 1e-12);
            Assert.assertEquals(monumentId + "\tlat", lat, latCalc, 1e-12);
            final double x = record.getDouble("x");
            final double y = record.getDouble("y");
            final int utmReferenceMeridian = record.getInteger("utmReferenceMeridian");
            CoordinatesProjection mercator = projectionById.get(utmReferenceMeridian);
            if (mercator == null) {
                final Ellipsoid ellipsoid = new Ellipsoid("NAD83", 6378137, 298.257222101);
                mercator = new TransverseMercatorThomas("", ellipsoid, utmReferenceMeridian, 0, 0.9996, 500000, 0);
                projectionById.put(utmReferenceMeridian, mercator);
            }
            final double[] coordinates = new double[2];
            mercator.project(lon, lat, coordinates, 0);
            final double xActual = coordinates[0];
            final double yActual = coordinates[1];
            Assert.assertEquals(monumentId + "\tproj x", x, xActual, 1e-3);
            Assert.assertEquals(monumentId + "\tproj y", y, yActual, 2e-3);
            mercator.inverse(x, y, coordinates, 0);
            final double lonActual = coordinates[0];
            final double latActual = coordinates[1];
            assertDms(monumentId + "\tlon", longitudeDegrees, longitudeMinutes, longitudeSeconds, lonActual, DP_5);
            assertDms(monumentId + "\tlat", latitudeDegrees, latitudeMinutes, latitudeSeconds, latActual, DP_5);
            final String lonStringActual = Angle.toDegreesMinutesSecondsLon(lonActual, 5);
            final String latStringActual = Angle.toDegreesMinutesSecondsLat(latActual, 5);
            if (!equalDms(lonStringCalc, lonStringActual, 0.00005)) {
                Assert.assertEquals(monumentId + "\tlon dms", lonStringCalc, lonStringActual);
            }
            if (!equalDms(latStringCalc, latStringActual, 0.00005)) {
                Assert.assertEquals(monumentId + "\tlat dms", latStringCalc, latStringActual);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) RecordReader(com.revolsys.record.io.RecordReader) Record(com.revolsys.record.Record) Ellipsoid(com.revolsys.geometry.cs.Ellipsoid) Test(org.junit.Test)

Example 4 with Ellipsoid

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

the class TransverseMercatorTest method testUtmMascot.

private void testUtmMascot(final BiFunction<Ellipsoid, Double, TransverseMercator> projectionFactory) {
    final Map<Integer, CoordinatesProjection> projectionById = new HashMap<>();
    try (RecordReader recordReader = RecordReader.newRecordReader("../../com.revolsys.open-testdata/cs/transverseMercator/mascot.csv")) {
        for (final Record record : recordReader) {
            final String monumentId = record.getValue("monumentId");
            final int longitudeDegrees = record.getInteger("longitudeDegrees");
            final int longitudeMinutes = record.getInteger("longitudeMinutes");
            final double longitudeSeconds = record.getDouble("longitudeSeconds");
            final int latitudeDegrees = record.getInteger("latitudeDegrees");
            final int latitudeMinutes = record.getInteger("latitudeMinutes");
            final double latitudeSeconds = record.getDouble("latitudeSeconds");
            final double lon = record.getDouble("lon");
            final double lat = record.getDouble("lat");
            final double lonCalc = Angle.toDecimalDegrees(longitudeDegrees, longitudeMinutes, longitudeSeconds);
            final double latCalc = Angle.toDecimalDegrees(latitudeDegrees, latitudeMinutes, latitudeSeconds);
            Assert.assertEquals(monumentId + "\tlon", lon, lonCalc, 1e-12);
            Assert.assertEquals(monumentId + "\tlat", lat, latCalc, 1e-12);
            final double x = record.getDouble("x");
            final double y = record.getDouble("y");
            final int utmReferenceMeridian = record.getInteger("utmReferenceMeridian");
            CoordinatesProjection mercator = projectionById.get(utmReferenceMeridian);
            if (mercator == null) {
                final Ellipsoid ellipsoid = new Ellipsoid("NAD83", 6378137, 298.257222101);
                mercator = projectionFactory.apply(ellipsoid, (double) utmReferenceMeridian);
                projectionById.put(utmReferenceMeridian, mercator);
            }
            final double[] coordinates = new double[2];
            mercator.project(lon, lat, coordinates, 0);
            final double xActual = coordinates[0];
            final double yActual = coordinates[1];
            Assert.assertEquals(monumentId + "\tproj x", x, xActual, 1e-3);
            Assert.assertEquals(monumentId + "\tproj y", y, yActual, 2e-3);
            mercator.inverse(x, y, coordinates, 0);
            final double lonActual = coordinates[0];
            final double latActual = coordinates[1];
            assertDms(monumentId + "\tlon", longitudeDegrees, longitudeMinutes, longitudeSeconds, lonActual, DP_4);
            assertDms(monumentId + "\tlat", latitudeDegrees, latitudeMinutes, latitudeSeconds, latActual, DP_4);
        }
    }
}
Also used : HashMap(java.util.HashMap) RecordReader(com.revolsys.record.io.RecordReader) Record(com.revolsys.record.Record) Ellipsoid(com.revolsys.geometry.cs.Ellipsoid)

Example 5 with Ellipsoid

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

the class EsriCoordinateSystemsLoader method geographic.

private void geographic() {
    final Map<ByteArray, Map<Integer, GeographicCoordinateSystem>> csBymd5 = new LinkedHashMap<>();
    try (RecordReader reader = RecordReader.newRecordReader(this.mainPath + "data/esri/esriGeographicCs.tsv");
        final ChannelWriter writer = ChannelWriter.newChannelWriter(this.mainPath + "resources/CoordinateSystems/esri/Geographic.cs")) {
        for (final Record record : reader) {
            final int id = record.getInteger("ID");
            final String wkt = record.getString("WKT");
            final GeographicCoordinateSystem coordinateSystem = WktCsParser.read(wkt);
            final byte[] digest = coordinateSystem.md5Digest();
            Maps.addToMap(Maps::newTree, csBymd5, new ByteArray(digest), id, coordinateSystem);
            final GeodeticDatum datum = coordinateSystem.getDatum();
            final Ellipsoid ellipsoid = datum.getEllipsoid();
            final PrimeMeridian primeMeridian = coordinateSystem.getPrimeMeridian();
            final AngularUnit angularUnit = coordinateSystem.getAngularUnit();
            final String csName = coordinateSystem.getCoordinateSystemName();
            this.geographicIdByName.put(csName, id);
            final String datumName = datum.getName();
            final String spheroidName = ellipsoid.getName();
            final double semiMajorAxis = ellipsoid.getSemiMajorAxis();
            final double inverseFlattening = ellipsoid.getInverseFlattening();
            final String primeMeridianName = primeMeridian.getName();
            final double longitude = primeMeridian.getLongitude();
            final String angularUnitName = angularUnit.getName();
            final double conversionFactor = angularUnit.getConversionFactor();
            writer.putInt(id);
            writer.putStringUtf8ByteCount(csName);
            writer.putStringUtf8ByteCount(datumName);
            writer.putStringUtf8ByteCount(spheroidName);
            writer.putDouble(semiMajorAxis);
            writer.putDouble(inverseFlattening);
            writer.putStringUtf8ByteCount(primeMeridianName);
            writer.putDouble(longitude);
            writer.putStringUtf8ByteCount(angularUnitName);
            writer.putDouble(conversionFactor);
        }
    }
    writeDigestFile(csBymd5, "Geographic");
}
Also used : RecordReader(com.revolsys.record.io.RecordReader) GeodeticDatum(com.revolsys.geometry.cs.datum.GeodeticDatum) PrimeMeridian(com.revolsys.geometry.cs.PrimeMeridian) AngularUnit(com.revolsys.geometry.cs.unit.AngularUnit) LinkedHashMap(java.util.LinkedHashMap) ChannelWriter(com.revolsys.io.channels.ChannelWriter) Maps(com.revolsys.collection.map.Maps) Record(com.revolsys.record.Record) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Ellipsoid(com.revolsys.geometry.cs.Ellipsoid)

Aggregations

Ellipsoid (com.revolsys.geometry.cs.Ellipsoid)8 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)3 GeodeticDatum (com.revolsys.geometry.cs.datum.GeodeticDatum)3 ChannelReader (com.revolsys.io.channels.ChannelReader)3 Record (com.revolsys.record.Record)3 RecordReader (com.revolsys.record.io.RecordReader)3 WrappedException (com.revolsys.util.WrappedException)3 EOFException (java.io.EOFException)3 HashMap (java.util.HashMap)3 Authority (com.revolsys.geometry.cs.Authority)2 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)2 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)2 AngularUnit (com.revolsys.geometry.cs.unit.AngularUnit)2 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)2 IntHashMap (com.revolsys.collection.map.IntHashMap)1 Maps (com.revolsys.collection.map.Maps)1 Area (com.revolsys.geometry.cs.Area)1 BaseAuthority (com.revolsys.geometry.cs.BaseAuthority)1 Datum (com.revolsys.geometry.cs.datum.Datum)1 EngineeringDatum (com.revolsys.geometry.cs.datum.EngineeringDatum)1