use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.
the class GeometryFactory method writeWktCs.
private boolean writeWktCs(final Writer writer, final int indentLevel) {
final CoordinateSystem coordinateSystem = getCoordinateSystem();
if (coordinateSystem == null) {
return false;
} else {
final int coordinateSystemId = getCoordinateSystemId();
final CoordinateSystem esriCoordinateSystem = EsriCoordinateSystems.getCoordinateSystem(coordinateSystemId);
if (esriCoordinateSystem == null) {
EsriCsWktWriter.write(writer, coordinateSystem, indentLevel);
} else {
EsriCsWktWriter.write(writer, esriCoordinateSystem, indentLevel);
}
return true;
}
}
use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.
the class BoundingBox method clipToCoordinateSystem.
/**
* If the coordinate system is a projected coordinate system then clip to the {@link CoordinateSystem#getAreaBoundingBox()}.
*/
default BoundingBox clipToCoordinateSystem() {
final GeometryFactory geometryFactory = getGeometryFactory();
final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
if (coordinateSystem == null || coordinateSystem instanceof GeographicCoordinateSystem) {
return this;
} else {
final BoundingBox areaBoundingBox = coordinateSystem.getAreaBoundingBox();
return intersection(areaBoundingBox);
}
}
use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.
the class BoundingBox method toPolygon.
default Polygon toPolygon(GeometryFactory geometryFactory, int numX, int numY) {
if (isEmpty()) {
return geometryFactory.polygon();
} else {
final GeometryFactory factory = getGeometryFactory();
if (geometryFactory == null) {
if (factory == null) {
geometryFactory = GeometryFactory.floating2d(0);
} else {
geometryFactory = factory;
}
}
try {
double minStep = 0.00001;
final CoordinateSystem coordinateSystem = factory.getCoordinateSystem();
if (coordinateSystem instanceof ProjectedCoordinateSystem) {
minStep = 1;
} else {
minStep = 0.00001;
}
double xStep;
final double width = getWidth();
if (!Double.isFinite(width)) {
return geometryFactory.polygon();
} else if (numX <= 1) {
numX = 1;
xStep = width;
} else {
xStep = width / numX;
if (xStep < minStep) {
xStep = minStep;
}
numX = Math.max(1, (int) Math.ceil(width / xStep));
}
double yStep;
if (numY <= 1) {
numY = 1;
yStep = getHeight();
} else {
yStep = getHeight() / numY;
if (yStep < minStep) {
yStep = minStep;
}
numY = Math.max(1, (int) Math.ceil(getHeight() / yStep));
}
final double minX = getMinX();
final double maxX = getMaxX();
final double minY = getMinY();
final double maxY = getMaxY();
final int coordinateCount = 1 + 2 * (numX + numY);
final double[] coordinates = new double[coordinateCount * 2];
int i = 0;
coordinates[i++] = maxX;
coordinates[i++] = minY;
for (int j = 0; j < numX - 1; j++) {
final double x = maxX - j * xStep;
coordinates[i++] = x;
coordinates[i++] = minY;
}
coordinates[i++] = minX;
coordinates[i++] = minY;
for (int j = 0; j < numY - 1; j++) {
final double y = minY + j * yStep;
coordinates[i++] = minX;
coordinates[i++] = y;
}
coordinates[i++] = minX;
coordinates[i++] = maxY;
for (int j = 0; j < numX - 1; j++) {
final double x = minX + j * xStep;
coordinates[i++] = x;
coordinates[i++] = maxY;
}
coordinates[i++] = maxX;
coordinates[i++] = maxY;
for (int j = 0; j < numY - 1; j++) {
final double y = minY + (numY - j) * yStep;
coordinates[i++] = maxX;
coordinates[i++] = y;
}
coordinates[i++] = maxX;
coordinates[i++] = minY;
final LinearRing ring = factory.linearRing(2, coordinates);
final Polygon polygon = factory.polygon(ring);
if (geometryFactory == null) {
return polygon;
} else {
return (Polygon) polygon.convertGeometry(geometryFactory);
}
} catch (final IllegalArgumentException e) {
Logs.error(this, "Unable to convert to polygon: " + this, e);
return geometryFactory.polygon();
}
}
}
use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.
the class BoundingBox method intersects.
/**
* Check if the region defined by <code>other</code>
* overlaps (intersects) the region of this <code>BoundingBox</code>.
*
*@param other the <code>BoundingBox</code> which this <code>BoundingBox</code> is
* being checked for overlapping
*@return <code>true</code> if the <code>BoundingBox</code>s overlap
*/
default boolean intersects(final BoundingBox other) {
if (isEmpty() || other.isEmpty()) {
return false;
} else {
final CoordinateSystem coordinateSystem = getCoordinateSystem();
final BoundingBox convertedBoundingBox = other.toCoordinateSystem(coordinateSystem, 2);
return intersectsFast(convertedBoundingBox);
}
}
use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.
the class MoepBinaryIterator method loadHeader.
private void loadHeader() throws IOException {
this.fileType = (byte) read();
if (this.fileType / 100 == 0) {
this.coordinateBytes = 2;
} else {
this.fileType %= 100;
this.coordinateBytes = 4;
}
String mapsheet = readString(11);
mapsheet = mapsheet.replaceAll("\\.", "").toLowerCase();
final Bcgs20000RectangularMapGrid bcgsGrid = new Bcgs20000RectangularMapGrid();
final UtmRectangularMapGrid utmGrid = new UtmRectangularMapGrid();
final double latitude = bcgsGrid.getLatitude(mapsheet) + 0.05;
final double longitude = bcgsGrid.getLongitude(mapsheet) - 0.1;
final int crsId = utmGrid.getNad83Srid(longitude, latitude);
final CoordinateSystem coordinateSystem = EpsgCoordinateSystems.getCoordinateSystem(crsId);
final String submissionDateString = readString(6);
final double centreX = readLEInt(this.in);
final double centreY = readLEInt(this.in);
this.center = new PointDoubleXY(centreX, centreY);
this.factory = GeometryFactory.fixed3d(coordinateSystem.getCoordinateSystemId(), 1.0, 1.0, 1.0);
setProperty(IoConstants.GEOMETRY_FACTORY, this.factory);
}
Aggregations