Search in sources :

Example 36 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class FactorZoomMode method getBoundingBox.

/**
 * Get the best bounding box matching the zoom mode policy
 *
 * @param viewport The viewport.
 * @param boundingBox The bounding box.
 * @return The bounding box.
 */
@Override
public BoundingBox getBoundingBox(final ComponentViewport2D viewport, final BoundingBox boundingBox) {
    final GeometryFactory geometryFactory = viewport.getGeometryFactory();
    final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
    final GeometryFactory bboxGeometryFactory = boundingBox.getGeometryFactory();
    BoundingBox newBoundingBox = boundingBox;
    if (bboxGeometryFactory == null) {
        newBoundingBox = boundingBox.convert(geometryFactory);
    } else {
        if (bboxGeometryFactory.equals(geometryFactory)) {
            newBoundingBox = boundingBox;
        } else {
            newBoundingBox = boundingBox.convert(geometryFactory);
        }
        if (coordinateSystem instanceof ProjectedCoordinateSystem) {
            final BoundingBox areaBoundingBox = coordinateSystem.getAreaBoundingBox();
            newBoundingBox = boundingBox.intersection(areaBoundingBox);
        }
    }
    final double viewAspectRatio = viewport.getViewAspectRatio();
    final double modelAspectRatio = newBoundingBox.getAspectRatio();
    if (viewAspectRatio != modelAspectRatio) {
        final double width = newBoundingBox.getWidth();
        final double height = newBoundingBox.getHeight();
        if (viewAspectRatio > modelAspectRatio) {
            final double newWidth = height * viewAspectRatio;
            final double deltaX = (newWidth - width) / 2;
            newBoundingBox = newBoundingBox.expand(deltaX, 0);
        } else if (viewAspectRatio < modelAspectRatio) {
            final double newHeight = width / viewAspectRatio;
            final double deltaY = (newHeight - height) / 2;
            newBoundingBox = newBoundingBox.expand(0, deltaY);
        }
    }
    return newBoundingBox;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) BoundingBox(com.revolsys.geometry.model.BoundingBox) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem)

Example 37 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class GeometryTestUtil method getCentre.

private static Point getCentre(final GeometryFactory geometryFactory) {
    final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
    final BoundingBox areaBoundingBox = coordinateSystem.getAreaBoundingBox();
    final Point centre = areaBoundingBox.getCentre();
    return centre;
}
Also used : CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point)

Example 38 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class MapPanel method zoomToWorld.

public void zoomToWorld() {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
    final BoundingBox boundingBox = coordinateSystem.getAreaBoundingBox();
    setBoundingBox(boundingBox);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) SelectMapCoordinateSystem(com.revolsys.swing.map.component.SelectMapCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 39 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class Viewport2D method toDisplayValue.

public double toDisplayValue(final Quantity<Length> value) {
    double convertedValue;
    final Unit<Length> unit = value.getUnit();
    if (unit.equals(CustomUnits.PIXEL)) {
        convertedValue = QuantityType.doubleValue(value, CustomUnits.PIXEL);
    } else {
        convertedValue = QuantityType.doubleValue(value, Units.METRE);
        final CoordinateSystem coordinateSystem = this.geometryFactory2d.getCoordinateSystem();
        if (coordinateSystem instanceof GeographicCoordinateSystem) {
            final GeographicCoordinateSystem geoCs = (GeographicCoordinateSystem) coordinateSystem;
            final double radius = geoCs.getDatum().getEllipsoid().getSemiMajorAxis();
            convertedValue = Math.toDegrees(convertedValue / radius);
        }
        final double modelUnitsPerViewUnit = getModelUnitsPerViewUnit();
        convertedValue = convertedValue / modelUnitsPerViewUnit;
    }
    return convertedValue;
}
Also used : Length(javax.measure.quantity.Length) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem)

Example 40 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class Project method toMap.

@Override
public MapEx toMap() {
    final MapEx map = super.toMap();
    BoundingBox boundingBox = getViewBoundingBox();
    if (!RectangleUtil.isEmpty(boundingBox)) {
        BoundingBox defaultBoundingBox = null;
        final GeometryFactory geometryFactory = getGeometryFactory();
        if (geometryFactory != null) {
            final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
            if (coordinateSystem != null) {
                defaultBoundingBox = coordinateSystem.getAreaBoundingBox();
            }
            boundingBox = boundingBox.convert(geometryFactory);
        }
        addToMap(map, "viewBoundingBox", boundingBox, defaultBoundingBox);
        final Map<String, BoundingBox> zoomBookmarks = getZoomBookmarks();
        addToMap(map, "zoomBookmarks", zoomBookmarks);
    }
    final ProjectFrame projectFrame = ProjectFrame.get(this);
    if (projectFrame != null) {
        final Rectangle frameBounds = projectFrame.getBounds();
        if (frameBounds != null) {
            map.put("frameBounds", Arrays.asList(frameBounds.x, frameBounds.y, frameBounds.width, frameBounds.height));
        }
    }
    return map;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) MapEx(com.revolsys.collection.map.MapEx) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) BoundingBox(com.revolsys.geometry.model.BoundingBox) Rectangle(java.awt.Rectangle) ProjectFrame(com.revolsys.swing.map.ProjectFrame)

Aggregations

CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)51 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)28 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)25 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)14 BoundingBox (com.revolsys.geometry.model.BoundingBox)11 Point (com.revolsys.geometry.model.Point)8 CompoundCoordinateSystem (com.revolsys.geometry.cs.CompoundCoordinateSystem)7 EngineeringCoordinateSystem (com.revolsys.geometry.cs.EngineeringCoordinateSystem)7 GeocentricCoordinateSystem (com.revolsys.geometry.cs.GeocentricCoordinateSystem)7 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)7 ArrayList (java.util.ArrayList)6 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)5 Map (java.util.Map)5 DataType (com.revolsys.datatype.DataType)4 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)4 Record (com.revolsys.record.Record)4 FieldDefinition (com.revolsys.record.schema.FieldDefinition)4 PrintWriter (java.io.PrintWriter)4 IntHashMap (com.revolsys.collection.map.IntHashMap)3 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)3