use of com.revolsys.geometry.cs.CoordinateOperationMethod in project com.revolsys.open by revolsys.
the class EpsgCsWktWriter method write.
public static void write(final PrintWriter out, final ProjectedCoordinateSystem coordinateSystem) {
if (coordinateSystem != null) {
out.print("PROJCS[");
write(out, coordinateSystem.getCoordinateSystemName());
final GeographicCoordinateSystem geoCs = coordinateSystem.getGeographicCoordinateSystem();
out.print(",");
write(out, geoCs);
final CoordinateOperationMethod coordinateOperationMethod = coordinateSystem.getCoordinateOperationMethod();
write(out, coordinateOperationMethod);
for (final Entry<ParameterName, Object> parameter : coordinateSystem.getParameters().entrySet()) {
final ParameterName name = parameter.getKey();
final Object value = parameter.getValue();
write(out, name, value);
}
final LinearUnit unit = coordinateSystem.getLinearUnit();
if (unit != null) {
write(out, unit);
}
final Authority authority = coordinateSystem.getAuthority();
write(out, authority);
out.write(']');
}
}
use of com.revolsys.geometry.cs.CoordinateOperationMethod in project com.revolsys.open by revolsys.
the class EpsgCoordinateSystemsLoader method validateEsri.
private void validateEsri() {
EsriCoordinateSystems.getCoordinateSystem(0);
for (final CoordinateSystem coordinateSytstem : EpsgCoordinateSystems.getCoordinateSystems()) {
if (coordinateSytstem instanceof GeographicCoordinateSystem) {
final GeographicCoordinateSystem geoCs = (GeographicCoordinateSystem) coordinateSytstem;
final int id = coordinateSytstem.getCoordinateSystemId();
final GeographicCoordinateSystem esri = EsriCoordinateSystems.getCoordinateSystem(id);
if (esri != null && !geoCs.equalsExact(esri)) {
// System.out.println(id + coordinateSytstem.getCoordinateSystemName());
}
} else if (coordinateSytstem instanceof ProjectedCoordinateSystem) {
final ProjectedCoordinateSystem projectedCs = (ProjectedCoordinateSystem) coordinateSytstem;
final int id = coordinateSytstem.getCoordinateSystemId();
final String wkt = new UrlResource("http://spatialreference.org/ref/epsg/" + id + "/esriwkt/").contentsAsString();
final ProjectedCoordinateSystem esri = GeometryFactory.floating2d(wkt).getCoordinateSystem();
final CoordinateOperationMethod coordinateOperationMethod = esri.getCoordinateOperationMethod();
if (esri != null && !projectedCs.equals(esri) && coordinateOperationMethod != null && Property.hasValue(coordinateOperationMethod.getName()) && !projectedCs.isDeprecated()) {
final Map<ParameterName, Object> p1 = projectedCs.getParameters();
final Map<ParameterName, Object> p2 = esri.getParameters();
final Set<ParameterName> n1 = p1.keySet();
final Set<ParameterName> n2 = p2.keySet();
if (!n1.equals(n2)) {
final TreeSet<ParameterName> nm1 = new TreeSet<>(n1);
nm1.removeAll(n2);
final TreeSet<ParameterName> nm2 = new TreeSet<>(n2);
nm2.removeAll(n1);
final String m = id + "\t" + coordinateSytstem.getCoordinateSystemName() + "\t" + nm1 + "\t" + nm2;
// System.out.println(m);
}
}
}
}
}
use of com.revolsys.geometry.cs.CoordinateOperationMethod in project com.revolsys.open by revolsys.
the class TiffImage method loadGeoTiffMetaData.
private boolean loadGeoTiffMetaData(final XTIFFDirectory directory) {
try {
final int xResolution = (int) getFieldAsDouble(directory, TAG_X_RESOLUTION, 1);
final int yResolution = (int) getFieldAsDouble(directory, TAG_Y_RESOLUTION, 1);
setDpi(xResolution, yResolution);
} catch (final Throwable e) {
Logs.error(this, e);
}
GeometryFactory geometryFactory = null;
final Map<Integer, Object> geoKeys = getGeoKeys(directory);
int coordinateSystemId = Maps.getInteger(geoKeys, PROJECTED_COORDINATE_SYSTEM_ID, 0);
if (coordinateSystemId == 0) {
coordinateSystemId = Maps.getInteger(geoKeys, GEOGRAPHIC_COORDINATE_SYSTEM_ID, 0);
if (coordinateSystemId != 0) {
geometryFactory = GeometryFactory.floating2d(coordinateSystemId);
}
} else if (coordinateSystemId <= 0 || coordinateSystemId == 32767) {
final int geoSrid = Maps.getInteger(geoKeys, 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 = getProjection(geoKeys);
final Map<ParameterName, ParameterValue> parameters = new LinkedHashMap<>();
addDoubleParameter(parameters, ParameterNames.STANDARD_PARALLEL_1, geoKeys, STANDARD_PARALLEL_1_KEY);
addDoubleParameter(parameters, ParameterNames.STANDARD_PARALLEL_2, geoKeys, STANDARD_PARALLEL_2_KEY);
addDoubleParameter(parameters, ParameterNames.CENTRAL_MERIDIAN, geoKeys, LONGITUDE_OF_CENTER_2_KEY);
addDoubleParameter(parameters, ParameterNames.LATITUDE_OF_ORIGIN, geoKeys, LATITUDE_OF_CENTER_2_KEY);
addDoubleParameter(parameters, ParameterNames.FALSE_EASTING, geoKeys, FALSE_EASTING_KEY);
addDoubleParameter(parameters, ParameterNames.FALSE_NORTHING, geoKeys, FALSE_NORTHING_KEY);
final LinearUnit linearUnit = getLinearUnit(geoKeys);
final ProjectedCoordinateSystem coordinateSystem = new ProjectedCoordinateSystem(coordinateSystemId, name, geographicCoordinateSystem, coordinateOperationMethod, parameters, linearUnit);
final CoordinateSystem epsgCoordinateSystem = EpsgCoordinateSystems.getCoordinateSystem(coordinateSystem);
geometryFactory = GeometryFactory.floating2d(epsgCoordinateSystem.getCoordinateSystemId());
}
}
} else {
geometryFactory = GeometryFactory.floating2d(coordinateSystemId);
}
if (geometryFactory != null) {
setGeometryFactory(geometryFactory);
}
final XTIFFField tiePoints = directory.getField(XTIFF.TIFFTAG_GEO_TIEPOINTS);
if (tiePoints == null) {
final XTIFFField geoTransform = directory.getField(XTIFF.TIFFTAG_GEO_TRANS_MATRIX);
if (geoTransform == null) {
return false;
} else {
final double x1 = geoTransform.getAsDouble(3);
final double y1 = geoTransform.getAsDouble(7);
final double pixelWidth = geoTransform.getAsDouble(0);
final double pixelHeight = geoTransform.getAsDouble(5);
final double xRotation = geoTransform.getAsDouble(4);
final double yRotation = geoTransform.getAsDouble(1);
setResolution(pixelWidth);
// TODO rotation
setBoundingBox(x1, y1, pixelWidth, pixelHeight);
return true;
}
} else {
final XTIFFField pixelScale = directory.getField(XTIFF.TIFFTAG_GEO_PIXEL_SCALE);
if (pixelScale == null) {
return false;
} else {
final double rasterXOffset = tiePoints.getAsDouble(0);
final double rasterYOffset = tiePoints.getAsDouble(1);
if (rasterXOffset != 0 && rasterYOffset != 0) {
// These should be 0, not sure what to do if they are not
throw new IllegalArgumentException("Exepectig 0 for the raster x,y tie points in a GeoTIFF");
}
// double rasterZOffset = fieldModelTiePoints.getAsDouble(2);
// setTopLeftRasterPoint(new PointDouble(
// rasterXOffset,
// rasterYOffset));
// Top left corner of image in model coordinates
final double x1 = tiePoints.getAsDouble(3);
final double y1 = tiePoints.getAsDouble(4);
// double modelZOffset = fieldModelTiePoints.getAsDouble(5);
// setTopLeftModelPoint(new PointDouble(
// modelXOffset,
// modelYOffset));
final double pixelWidth = pixelScale.getAsDouble(0);
final double pixelHeight = pixelScale.getAsDouble(1);
setResolution(pixelWidth);
setBoundingBox(x1, y1, pixelWidth, -pixelHeight);
return true;
}
}
}
use of com.revolsys.geometry.cs.CoordinateOperationMethod in project com.revolsys.open by revolsys.
the class TiffImage method addProjection.
private static void addProjection(final int id, final String name) {
final CoordinateOperationMethod coordinateOperationMethod = new CoordinateOperationMethod(name);
PROJECTION_BY_ID.put(id, coordinateOperationMethod);
}
Aggregations