Search in sources :

Example 6 with GeographicCoordinateSystem

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

the class EsriCsWktWriter method write.

public static void write(final Writer out, final CoordinateSystem coordinateSystem, final int indentLevel) {
    try {
        if (coordinateSystem instanceof ProjectedCoordinateSystem) {
            final ProjectedCoordinateSystem projCs = (ProjectedCoordinateSystem) coordinateSystem;
            write(out, projCs, indentLevel);
        } else if (coordinateSystem instanceof GeographicCoordinateSystem) {
            final GeographicCoordinateSystem geoCs = (GeographicCoordinateSystem) coordinateSystem;
            write(out, geoCs, indentLevel);
        } else if (coordinateSystem instanceof VerticalCoordinateSystem) {
            final VerticalCoordinateSystem verticalCs = (VerticalCoordinateSystem) coordinateSystem;
            write(out, verticalCs, indentLevel);
        }
    } catch (final IOException e) {
        throw Exceptions.wrap(e);
    }
}
Also used : VerticalCoordinateSystem(com.revolsys.geometry.cs.VerticalCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) IOException(java.io.IOException)

Example 7 with GeographicCoordinateSystem

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

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

the class LineString method getLength.

@Override
default double getLength(final Unit<Length> unit) {
    double length = 0;
    final CoordinateSystem coordinateSystem = getCoordinateSystem();
    if (coordinateSystem instanceof GeographicCoordinateSystem) {
        final int vertexCount = getVertexCount();
        if (vertexCount > 1) {
            double lon0 = getX(0);
            double lat0 = getY(0);
            for (int i = 1; i < vertexCount; i++) {
                final double lon1 = getX(i);
                final double lat1 = getY(i);
                length += GeographicCoordinateSystem.distanceMetres(lon0, lat0, lon1, lat1);
                lon0 = lon1;
                lat0 = lat1;
            }
        }
        final Quantity<Length> lengthMeasure = Quantities.getQuantity(length, Units.METRE);
        length = QuantityType.doubleValue(lengthMeasure, unit);
    } else if (coordinateSystem instanceof ProjectedCoordinateSystem) {
        final ProjectedCoordinateSystem projectedCoordinateSystem = (ProjectedCoordinateSystem) coordinateSystem;
        final Unit<Length> lengthUnit = projectedCoordinateSystem.getLengthUnit();
        length = getLength();
        final Quantity<Length> lengthMeasure = Quantities.getQuantity(length, lengthUnit);
        length = QuantityType.doubleValue(lengthMeasure, unit);
    } else {
        length = getLength();
    }
    return length;
}
Also used : Length(javax.measure.quantity.Length) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) Quantity(javax.measure.Quantity) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) Unit(javax.measure.Unit)

Example 9 with GeographicCoordinateSystem

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

the class LinearRing method getPolygonArea.

default double getPolygonArea(final Unit<Area> unit) {
    double area = 0;
    final CoordinateSystem coordinateSystem = getCoordinateSystem();
    if (coordinateSystem instanceof GeographicCoordinateSystem) {
        // TODO better algorithm than converting to world mercator
        final GeometryFactory geometryFactory = GeometryFactory.worldMercator();
        final LinearRing ring = as2d(geometryFactory);
        return ring.getPolygonArea(unit);
    } else if (coordinateSystem instanceof ProjectedCoordinateSystem) {
        final ProjectedCoordinateSystem projectedCoordinateSystem = (ProjectedCoordinateSystem) coordinateSystem;
        final Unit<Length> lengthUnit = projectedCoordinateSystem.getLengthUnit();
        @SuppressWarnings("unchecked") final Unit<Area> areaUnit = (Unit<Area>) lengthUnit.multiply(lengthUnit);
        area = getPolygonArea();
        final Quantity<Area> areaMeasure = Quantities.getQuantity(area, areaUnit);
        area = QuantityType.doubleValue(areaMeasure, unit);
    } else {
        area = getPolygonArea();
    }
    return area;
}
Also used : Area(javax.measure.quantity.Area) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) Quantity(javax.measure.Quantity) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) PreparedLinearRing(com.revolsys.geometry.model.prep.PreparedLinearRing) Unit(javax.measure.Unit)

Example 10 with GeographicCoordinateSystem

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

GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)28 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)19 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)13 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)9 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)8 Map (java.util.Map)7 ParameterName (com.revolsys.geometry.cs.ParameterName)5 BoundingBox (com.revolsys.geometry.model.BoundingBox)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 Authority (com.revolsys.geometry.cs.Authority)4 ParameterValue (com.revolsys.geometry.cs.ParameterValue)4 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)4 GeodeticDatum (com.revolsys.geometry.cs.datum.GeodeticDatum)4 IOException (java.io.IOException)4 CompoundCoordinateSystem (com.revolsys.geometry.cs.CompoundCoordinateSystem)3 EngineeringCoordinateSystem (com.revolsys.geometry.cs.EngineeringCoordinateSystem)3 GeocentricCoordinateSystem (com.revolsys.geometry.cs.GeocentricCoordinateSystem)3 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)3