use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class UsgsGriddedElevationReader method readHeader.
private void readHeader() {
try {
if (readBuffer()) {
final String fileName = getString(40);
final String descriptor = getString(40);
// Blank 81 - 109
skip(29);
final String seGeographic = getString(26);
final String processCode = getString(1);
// Blank 137
skip(1);
final String sectionIndicator = getString(3);
final String originCode = getString(4);
final int demLevelCode = getInteger();
final int elevationPattern = getInteger();
final int planimetricReferenceSystem = getInteger();
final int zone = getInteger();
final double[] projectionParameters = new double[15];
for (int i = 0; i < projectionParameters.length; i++) {
projectionParameters[i] = getDoubleSci();
}
final int planimetricUom = getInteger();
final int verticalUom = getInteger();
this.polygonBounds = getPolygonCoordinates();
final double min = getDouble24();
final double max = getDouble24();
final double angle = getDouble24();
if (angle != 0) {
throw new IllegalArgumentException("Angle=" + angle + " not currently supported for USGS DEM: " + this.resource);
}
final int verticalAccuracy = getInteger();
final double resolutionX = getDouble12();
final double resolutionY = getDouble12();
if (resolutionX != resolutionY) {
throw new IllegalArgumentException("resolutionX " + resolutionX + " != " + resolutionY + " resolutionY for USGS DEM: " + this.resource);
}
this.resolutionX = (int) resolutionX;
this.resolutionY = (int) resolutionY;
if (resolutionX != this.resolutionX) {
throw new IllegalArgumentException("resolutionX " + resolutionX + " must currently be an integer for USGS DEM: " + this.resource);
}
this.resolutionZ = getDouble12();
this.rasterRowCount = getInteger();
this.rasterColCount = getInteger();
final Short largestContourInterval = getShort();
final Byte largestContourIntervalUnits = getByte();
final Short smallestContourInterval = getShort();
final Byte smallest = getByte();
final Integer sourceYear = getInteger(4);
final Integer revisionYear = getInteger(4);
final String inspectionFlag = getString(1);
final String dataValidationFlag = getString(1);
final String suspectAndVoidAreaFlag = getString(1);
final Integer verticalDatum = getInteger(2);
final Integer horizontalDatum = getInteger(2);
final Integer dataEdition = getInteger(4);
final Integer percentVoid = getInteger(4);
final Integer edgeMatchWest = getInteger(2);
final Integer edgeMatchNorth = getInteger(2);
final Integer edgeMatchEast = getInteger(2);
final Integer edgeMatchSouth = getInteger(2);
final Double verticalDatumShift = getDouble(7);
LinearUnit linearUnit = null;
if (planimetricUom == 1) {
linearUnit = EpsgCoordinateSystems.getLinearUnit("foot");
} else if (planimetricUom == 2) {
linearUnit = EpsgCoordinateSystems.getLinearUnit("metre");
}
GeographicCoordinateSystem geographicCoordinateSystem;
switch(horizontalDatum) {
case 0:
geographicCoordinateSystem = null;
break;
case 1:
geographicCoordinateSystem = (GeographicCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem("NAD27");
break;
case 2:
geographicCoordinateSystem = (GeographicCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem("WGS 72");
break;
case 3:
geographicCoordinateSystem = (GeographicCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem("WGS 84");
break;
case 4:
geographicCoordinateSystem = (GeographicCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem("NAD83");
break;
default:
throw new IllegalArgumentException("horizontalDatum=" + horizontalDatum + " not currently supported for USGS DEM: " + this.resource);
}
final double scaleZ = 1.0 / this.resolutionZ;
int coordinateSystemId = 0;
CoordinateSystem coordinateSystem = null;
if (0 == planimetricReferenceSystem) {
coordinateSystemId = geographicCoordinateSystem.getCoordinateSystemId();
} else if (1 == planimetricReferenceSystem) {
coordinateSystemId = 26900 + zone;
} else if (2 == planimetricReferenceSystem) {
throw new IllegalArgumentException("planimetricReferenceSystem=" + planimetricReferenceSystem + " not currently supported for USGS DEM: " + this.resource);
} else if (3 == planimetricReferenceSystem) {
final Map<ParameterName, ParameterValue> parameters = new LinkedHashMap<>();
parameters.put(ParameterNames.CENTRAL_MERIDIAN, fromDms(projectionParameters[4]));
parameters.put(ParameterNames.STANDARD_PARALLEL_1, fromDms(projectionParameters[2]));
parameters.put(ParameterNames.STANDARD_PARALLEL_2, fromDms(projectionParameters[3]));
parameters.put(ParameterNames.LATITUDE_OF_ORIGIN, fromDms(projectionParameters[5]));
parameters.put(ParameterNames.FALSE_EASTING, new ParameterValueNumber(projectionParameters[6]));
parameters.put(ParameterNames.FALSE_NORTHING, new ParameterValueNumber(projectionParameters[7]));
final CoordinateOperationMethod coordinateOperationMethod = new CoordinateOperationMethod("Albers_Equal_Area");
final ProjectedCoordinateSystem projectedCoordinateSystem = new ProjectedCoordinateSystem(-1, "", geographicCoordinateSystem, coordinateOperationMethod, parameters, linearUnit);
final ProjectedCoordinateSystem projectedCoordinateSystem2 = (ProjectedCoordinateSystem) EpsgCoordinateSystems.getCoordinateSystem(projectedCoordinateSystem);
if (projectedCoordinateSystem2 == projectedCoordinateSystem || projectedCoordinateSystem2 == null) {
coordinateSystem = projectedCoordinateSystem2;
} else {
coordinateSystemId = projectedCoordinateSystem2.getCoordinateSystemId();
}
} else {
throw new IllegalArgumentException("planimetricReferenceSystem=" + planimetricReferenceSystem + " not currently supported for USGS DEM: " + this.resource);
}
if (coordinateSystemId > 0) {
this.geometryFactory = GeometryFactory.fixed3d(coordinateSystemId, 0, 0, scaleZ);
} else if (coordinateSystem == null) {
throw new IllegalArgumentException("No coordinate system found: " + this.resource);
} else {
this.geometryFactory = GeometryFactory.fixed3d(coordinateSystem, 0, 0, scaleZ);
}
final Polygon polygon = this.geometryFactory.polygon(this.geometryFactory.linearRing(2, this.polygonBounds));
this.boundingBox = polygon.getBoundingBox();
}
} catch (final Exception e) {
try {
close();
} catch (final Exception e1) {
}
throw Exceptions.wrap(e);
}
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class GeometryGraph method addGeometry.
public void addGeometry(Geometry geometry) {
geometry = getGeometryFactory().geometry(geometry);
final Map<String, Object> properties = new LinkedHashMap<>();
final int geometryIndex = this.geometries.size();
properties.put("geometryIndex", geometryIndex);
this.geometries.add(geometry);
for (int partIndex = 0; partIndex < geometry.getGeometryCount(); partIndex++) {
properties.put("partIndex", partIndex);
final Geometry part = geometry.getGeometry(partIndex);
if (part instanceof Point) {
final Point point = (Point) part;
this.points.add(point);
} else if (part instanceof LineString) {
final LineString line = (LineString) part;
final LineString points = line;
properties.put("type", "LineString");
addEdges(points, properties);
} else if (part instanceof Polygon) {
final Polygon polygon = (Polygon) part;
int ringIndex = 0;
for (final LinearRing ring : polygon.rings()) {
properties.put("ringIndex", ringIndex++);
if (ringIndex == 0) {
properties.put("type", "PolygonShell");
} else {
properties.put("type", "PolygonHole");
}
addEdges(ring, properties);
}
properties.remove("ringIndex");
}
}
this.boundingBox = this.boundingBox.expandToInclude(geometry);
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class EdgeRing method toPolygon.
public Polygon toPolygon(final GeometryFactory geometryFactory) {
final List<LinearRing> rings = new ArrayList<>();
rings.add(getLinearRing());
for (int i = 0; i < this.holes.size(); i++) {
final LinearRing ring = this.holes.get(i).getLinearRing();
rings.add(ring);
}
final Polygon poly = geometryFactory.polygon(rings);
return poly;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class Densifier method densify.
private static Polygonal densify(final Polygonal polygonal, final double distanceTolerance) {
final List<Polygon> polygons = new ArrayList<>();
for (final Polygon polygon : polygonal.getPolygons()) {
final Polygon newPolygon = densify(polygon, distanceTolerance);
polygons.add(newPolygon);
}
final GeometryFactory geometryFactory = polygonal.getGeometryFactory();
final Polygonal newMultiPolygon = geometryFactory.polygonal(polygons);
return (Polygonal) newMultiPolygon.buffer(0);
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class PreparedMultiPolygon method preparePolygons.
private static Polygon[] preparePolygons(final MultiPolygon polygonal) {
final Polygon[] polygons = new Polygon[polygonal.getPolygonCount()];
for (int i = 0; i < polygons.length; i++) {
final Polygon polygon = polygonal.getPolygon(i);
polygons[i] = polygon.prepare();
}
return polygons;
}
Aggregations