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);
}
}
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(']');
}
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;
}
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;
}
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");
}
Aggregations