Search in sources :

Example 1 with Area

use of javax.measure.quantity.Area 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;
}
Also used : Area(javax.measure.quantity.Area) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) Quantity(javax.measure.Quantity) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) PreparedLinearRing(com.revolsys.geometry.model.prep.PreparedLinearRing) Unit(javax.measure.Unit)

Example 2 with Area

use of javax.measure.quantity.Area 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);
    }
}
Also used : Area(javax.measure.quantity.Area) Length(javax.measure.quantity.Length) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) LineString(com.revolsys.geometry.model.LineString) Unit(javax.measure.Unit) Polygon(com.revolsys.geometry.model.Polygon)

Aggregations

CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)2 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)2 Unit (javax.measure.Unit)2 Area (javax.measure.quantity.Area)2 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)1 LineString (com.revolsys.geometry.model.LineString)1 Polygon (com.revolsys.geometry.model.Polygon)1 PreparedLinearRing (com.revolsys.geometry.model.prep.PreparedLinearRing)1 Quantity (javax.measure.Quantity)1 Length (javax.measure.quantity.Length)1