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 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.unit.LinearUnit in project com.revolsys.open by revolsys.
the class WktCsParser method processProjectedCoordinateSystem.
@SuppressWarnings("unchecked")
private ProjectedCoordinateSystem processProjectedCoordinateSystem(final List<Object> values) {
int index = 0;
final String name = (String) values.get(index++);
final GeographicCoordinateSystem geographicCoordinateSystem = (GeographicCoordinateSystem) values.get(index++);
final Map<ParameterName, ParameterValue> parameters = new LinkedHashMap<>();
LinearUnit linearUnit = null;
final List<Axis> axis = new ArrayList<>();
Authority authority = null;
String methodName = null;
while (index < values.size()) {
final Object value = values.get(index++);
if (value instanceof String) {
methodName = (String) value;
} else if (value instanceof Map) {
final Map<String, List<Object>> map = (Map<String, List<Object>>) value;
final String key = map.keySet().iterator().next();
if (key.equals("PARAMETER")) {
final List<Object> paramValues = map.get(key);
final String paramName = (String) paramValues.get(0);
final ParameterName parameterName = new SingleParameterName(paramName);
final ParameterValueBigDecimal paramValue = new ParameterValueBigDecimal((BigDecimal) paramValues.get(1));
parameters.put(parameterName, paramValue);
}
} else if (value instanceof LinearUnit) {
linearUnit = (LinearUnit) value;
} else if (value instanceof Axis) {
axis.add((Axis) value);
} else if (value instanceof Authority) {
authority = (Authority) value;
}
}
final int coordinateSystemId = getCoordinateSystemId(authority);
final CoordinateOperationMethod coordinateOperationMethod = new CoordinateOperationMethod(methodName);
return new ProjectedCoordinateSystem(coordinateSystemId, name, geographicCoordinateSystem, coordinateOperationMethod, parameters, linearUnit, axis, authority);
}
use of com.revolsys.geometry.cs.unit.LinearUnit in project com.revolsys.open by revolsys.
the class EsriCoordinateSystemsLoader method vertical.
private void vertical() {
final Map<ByteArray, Map<Integer, VerticalCoordinateSystem>> csBymd5 = new LinkedHashMap<>();
try (RecordReader reader = RecordReader.newRecordReader(this.mainPath + "data/esri/esriVerticalCs.tsv");
final ChannelWriter writer = ChannelWriter.newChannelWriter(this.mainPath + "resources/CoordinateSystems/esri/Vertical.cs")) {
for (final Record record : reader) {
final int id = record.getInteger("ID");
final String wkt = record.getString("WKT");
final VerticalCoordinateSystem coordinateSystem = WktCsParser.read(wkt);
final byte[] digest = coordinateSystem.md5Digest();
Maps.addToMap(Maps::newTree, csBymd5, new ByteArray(digest), id, coordinateSystem);
final VerticalDatum datum = coordinateSystem.getDatum();
if (datum != null) {
final Map<ParameterName, ParameterValue> parameterValues = coordinateSystem.getParameterValues();
final LinearUnit linearUnit = coordinateSystem.getLinearUnit();
final String csName = coordinateSystem.getCoordinateSystemName();
this.geographicIdByName.put(csName, id);
final String datumName = datum.getName();
final String linearUnitName = linearUnit.getName();
final double conversionFactor = linearUnit.getConversionFactor();
writer.putInt(id);
writer.putStringUtf8ByteCount(csName);
writer.putStringUtf8ByteCount(datumName);
writeParameters(writer, parameterValues);
writer.putStringUtf8ByteCount(linearUnitName);
writer.putDouble(conversionFactor);
}
}
}
writeDigestFile(csBymd5, "Vertical");
}
use of com.revolsys.geometry.cs.unit.LinearUnit in project com.revolsys.open by revolsys.
the class EpsgCoordinateSystems method getCoordinateSystem.
public static synchronized CoordinateSystem getCoordinateSystem(final CoordinateSystem coordinateSystem) {
initialize();
if (coordinateSystem == null) {
return null;
} else {
int srid = coordinateSystem.getCoordinateSystemId();
CoordinateSystem matchedCoordinateSystem = coordinateSystemsById.get(srid);
if (matchedCoordinateSystem == null) {
matchedCoordinateSystem = coordinateSystemsByName.get(coordinateSystem.getCoordinateSystemName());
if (matchedCoordinateSystem == null) {
final int hashCode = coordinateSystem.hashCode();
int matchCoordinateSystemId = 0;
final List<CoordinateSystem> coordinateSystems = coordinateSystemsByCoordinateSystem.get(hashCode);
if (coordinateSystems != null) {
for (final CoordinateSystem coordinateSystem3 : coordinateSystems) {
if (coordinateSystem3.equals(coordinateSystem)) {
final int srid3 = coordinateSystem3.getCoordinateSystemId();
if (matchedCoordinateSystem == null) {
matchedCoordinateSystem = coordinateSystem3;
matchCoordinateSystemId = srid3;
} else if (srid3 < matchCoordinateSystemId) {
if (!coordinateSystem3.isDeprecated() || matchedCoordinateSystem.isDeprecated()) {
matchedCoordinateSystem = coordinateSystem3;
matchCoordinateSystemId = srid3;
}
}
}
}
}
if (matchedCoordinateSystem == null) {
if (srid <= 0) {
srid = nextSrid++;
}
final String name = coordinateSystem.getCoordinateSystemName();
final List<Axis> axis = coordinateSystem.getAxis();
final Area area = coordinateSystem.getArea();
final Authority authority = coordinateSystem.getAuthority();
final boolean deprecated = coordinateSystem.isDeprecated();
if (coordinateSystem instanceof GeographicCoordinateSystem) {
final GeographicCoordinateSystem geographicCs = (GeographicCoordinateSystem) coordinateSystem;
final GeodeticDatum geodeticDatum = geographicCs.getDatum();
final PrimeMeridian primeMeridian = geographicCs.getPrimeMeridian();
final CoordinateSystem sourceCoordinateSystem = geographicCs.getSourceCoordinateSystem();
final CoordinateOperation coordinateOperation = geographicCs.getCoordinateOperation();
final GeographicCoordinateSystem newCs = new GeographicCoordinateSystem(srid, name, geodeticDatum, primeMeridian, axis, area, sourceCoordinateSystem, coordinateOperation, deprecated);
addCoordinateSystem(newCs);
return newCs;
} else if (coordinateSystem instanceof ProjectedCoordinateSystem) {
final ProjectedCoordinateSystem projectedCs = (ProjectedCoordinateSystem) coordinateSystem;
GeographicCoordinateSystem geographicCs = projectedCs.getGeographicCoordinateSystem();
geographicCs = (GeographicCoordinateSystem) getCoordinateSystem(geographicCs);
final CoordinateOperationMethod coordinateOperationMethod = projectedCs.getCoordinateOperationMethod();
final Map<ParameterName, ParameterValue> parameters = projectedCs.getParameterValues();
final LinearUnit linearUnit = projectedCs.getLinearUnit();
final ProjectedCoordinateSystem newCs = new ProjectedCoordinateSystem(srid, name, geographicCs, area, coordinateOperationMethod, parameters, linearUnit, axis, authority, deprecated);
addCoordinateSystem(newCs);
return newCs;
}
return coordinateSystem;
}
}
}
return matchedCoordinateSystem;
}
}
use of com.revolsys.geometry.cs.unit.LinearUnit in project com.revolsys.open by revolsys.
the class EpsgCoordinateSystems method loadEllipsoid.
private static IntHashMap<Ellipsoid> loadEllipsoid() {
final IntHashMap<Ellipsoid> ellipsoids = new IntHashMap<>();
try (ChannelReader reader = newChannelReader("ellipsoid")) {
while (true) {
final int id = reader.getInt();
final String name = reader.getStringUtf8ByteCount();
final int unitId = reader.getInt();
final LinearUnit unit = (LinearUnit) UNIT_BY_ID.get(unitId);
final double semiMinorAxis = unit.toBase(reader.getDouble());
final double semiMajorAxis = unit.toBase(reader.getDouble());
final double inverseFlattening = unit.toBase(reader.getDouble());
final int ellipsoidShape = reader.getByte();
final boolean deprecated = readBoolean(reader);
final EpsgAuthority authority = new EpsgAuthority(id);
final Ellipsoid ellipsoid = new Ellipsoid(name, semiMajorAxis, semiMinorAxis, inverseFlattening, authority, deprecated);
ellipsoids.put(id, ellipsoid);
}
} catch (final NoSuchResourceException e) {
} catch (final WrappedException e) {
if (Exceptions.isException(e, EOFException.class)) {
} else {
throw e;
}
}
return ellipsoids;
}
Aggregations