use of com.revolsys.geometry.cs.ProjectedCoordinateSystem 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.ProjectedCoordinateSystem in project com.revolsys.open by revolsys.
the class WikipediaBoundingBoxLayerWorker method handleBackground.
@Override
protected List<LayerRecord> handleBackground() {
BoundingBox boundingBox = this.boundingBox;
GeometryFactory geometryFactory = this.geometryFactory;
final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
if (coordinateSystem instanceof ProjectedCoordinateSystem) {
final ProjectedCoordinateSystem projCs = (ProjectedCoordinateSystem) coordinateSystem;
geometryFactory = projCs.getGeographicCoordinateSystem().getGeometryFactory();
boundingBox = boundingBox.convert(geometryFactory);
}
final List<LayerRecord> results = (List) this.geoNamesService.getWikipediaArticles(boundingBox);
for (final Record record : results) {
final String title = record.getValue("title");
final String wikipediaUrl = record.getValue("wikipediaUrl");
final String thumbnailImage = record.getValue("thumbnailImg");
final Point point = record.getGeometry();
String text;
if (thumbnailImage != null) {
text = "<html><b>" + title + "</b><br /><img src=\"" + thumbnailImage + "\" /><br /></html>";
} else {
text = "<html><b>" + title + "</b><br /></html>";
}
// if (viewport instanceof ComponentViewport2D) {
// final ComponentViewport2D componentViewport =
// (ComponentViewport2D)viewport;
// componentViewport.addHotSpot(geometryFactory, point, text, "http://"
// + wikipediaUrl);
// }
}
return results;
}
use of com.revolsys.geometry.cs.ProjectedCoordinateSystem in project com.revolsys.open by revolsys.
the class MeasureOverlay method setMeasureGeometry.
public void setMeasureGeometry(Geometry measureGeometry) {
if (measureGeometry == null) {
measureGeometry = EMPTY_GEOMETRY;
}
if (measureGeometry != this.measureGeometry) {
this.measureGeometry = measureGeometry;
if (measureGeometry == null) {
this.measureLabel = "";
} else {
Unit<Length> lengthUnit = Units.METRE;
final CoordinateSystem coordinateSystem = measureGeometry.getCoordinateSystem();
if (coordinateSystem instanceof ProjectedCoordinateSystem) {
lengthUnit = coordinateSystem.getLengthUnit();
}
final double length = measureGeometry.getLength(lengthUnit);
@SuppressWarnings("unchecked") final Unit<Area> areaUnit = (Unit<Area>) lengthUnit.multiply(lengthUnit);
final double area = measureGeometry.getArea(areaUnit);
final String unitString = lengthUnit.toString();
synchronized (MEASURE_FORMAT) {
final StringBuilder label = new StringBuilder();
final String lengthString = MEASURE_FORMAT.format(Doubles.makePrecise(100, length));
label.append(lengthString);
label.append(unitString);
if (this.measureDataType == DataTypes.POLYGON && measureGeometry instanceof Polygon) {
final String areaString = MEASURE_FORMAT.format(Doubles.makePrecise(100, area));
label.append(" \n");
label.append(areaString);
label.append(unitString);
label.append('\u00B2');
}
this.measureLabel = label.toString();
}
}
setXorGeometry(null);
}
}
use of com.revolsys.geometry.cs.ProjectedCoordinateSystem in project com.revolsys.open by revolsys.
the class GeoNamesBoundingBoxLayerWorker method handleBackground.
@Override
protected List<LayerRecord> handleBackground() {
BoundingBox boundingBox = this.boundingBox;
GeometryFactory geometryFactory = this.geometryFactory;
final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
if (coordinateSystem instanceof ProjectedCoordinateSystem) {
final ProjectedCoordinateSystem projCs = (ProjectedCoordinateSystem) coordinateSystem;
final GeographicCoordinateSystem geoCs = projCs.getGeographicCoordinateSystem();
geometryFactory = geoCs.getGeometryFactory();
boundingBox = boundingBox.convert(geometryFactory);
}
final List<LayerRecord> results = (List) this.geoNamesService.getNames(boundingBox);
for (final Record record : results) {
final String name = record.getValue("name");
final Point point = record.getGeometry();
final String text = "<html><b>" + name + "</b><br /></html>";
// if (viewport instanceof ComponentViewport2D) {
// final ComponentViewport2D componentViewport =
// (ComponentViewport2D)viewport;
// componentViewport.addHotSpot(geometryFactory, point, text, null);
// }
}
return results;
}
use of com.revolsys.geometry.cs.ProjectedCoordinateSystem 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;
}
}
Aggregations