Ignore:
Timestamp:
2016-08-15T14:45:38+02:00 (4 years ago)
Author:
Don-vip
Message:

fix #13287 - Projection updates to support multiple projections (patch by michael2402) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm/data/projection
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/projection/AbstractProjection.java

    r10699 r10805  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.projection;
     3
     4import java.util.Collections;
     5import java.util.HashMap;
     6import java.util.Map;
     7import java.util.function.DoubleUnaryOperator;
    38
    49import org.openstreetmap.josm.data.Bounds;
     
    813import org.openstreetmap.josm.data.projection.datum.Datum;
    914import org.openstreetmap.josm.data.projection.proj.Proj;
     15import org.openstreetmap.josm.tools.Utils;
    1016
    1117/**
     
    116122    @Override
    117123    public LatLon eastNorth2latlon(EastNorth en) {
     124        return eastNorth2latlon(en, LatLon::normalizeLon);
     125    }
     126
     127    @Override
     128    public LatLon eastNorth2latlonClamped(EastNorth en) {
     129        LatLon ll = eastNorth2latlon(en, lon -> Utils.clamp(lon, -180, 180));
     130        Bounds bounds = getWorldBoundsLatLon();
     131        return new LatLon(Utils.clamp(ll.lat(), bounds.getMinLat(), bounds.getMaxLat()),
     132                Utils.clamp(ll.lon(), bounds.getMinLon(), bounds.getMaxLon()));
     133    }
     134
     135    private LatLon eastNorth2latlon(EastNorth en, DoubleUnaryOperator normalizeLon) {
    118136        double[] latlonRad = proj.invproject((en.east() * toMeter - x0) / ellps.a / k0, (en.north() * toMeter - y0) / ellps.a / k0);
    119         LatLon ll = new LatLon(Math.toDegrees(latlonRad[0]), LatLon.normalizeLon(Math.toDegrees(latlonRad[1]) + lon0 + pm));
     137        double lon = Math.toDegrees(latlonRad[1]) + lon0 + pm;
     138        LatLon ll = new LatLon(Math.toDegrees(latlonRad[0]), normalizeLon.applyAsDouble(lon));
    120139        return datum.toWGS84(ll);
     140    }
     141
     142    @Override
     143    public Map<ProjectionBounds, Projecting> getProjectingsForArea(ProjectionBounds area) {
     144        if (proj.lonIsLinearToEast()) {
     145            //FIXME: Respect datum?
     146            // wrap the wrold around
     147            Bounds bounds = getWorldBoundsLatLon();
     148            double minEast = latlon2eastNorth(bounds.getMin()).east();
     149            double maxEast = latlon2eastNorth(bounds.getMax()).east();
     150            double dEast = maxEast - minEast;
     151            if ((area.minEast < minEast || area.maxEast > maxEast) && dEast > 0) {
     152                // We could handle the dEast < 0 case but we don't need it atm.
     153                int minChunk = (int) Math.floor((area.minEast - minEast) / dEast);
     154                int maxChunk = (int) Math.floor((area.maxEast - minEast) / dEast);
     155                HashMap<ProjectionBounds, Projecting> ret = new HashMap<>();
     156                for (int chunk = minChunk; chunk <= maxChunk; chunk++) {
     157                    ret.put(new ProjectionBounds(Math.max(area.minEast, minEast + chunk * dEast), area.minNorth,
     158                            Math.min(area.maxEast, maxEast + chunk * dEast), area.maxNorth),
     159                            new ShiftedProjecting(this, new EastNorth(-chunk * dEast, 0)));
     160                }
     161                return ret;
     162            }
     163        }
     164
     165        return Collections.singletonMap(area, this);
    121166    }
    122167
     
    179224        return projectionBoundsBox;
    180225    }
     226
     227    @Override
     228    public Projection getBaseProjection() {
     229        return this;
     230    }
    181231}
  • trunk/src/org/openstreetmap/josm/data/projection/Projection.java

    r10381 r10805  
    1414 * factor and x/y offset.
    1515 */
    16 public interface Projection {
     16public interface Projection extends Projecting {
    1717    /**
    1818     * The default scale factor in east/north units per pixel
     
    2222     */
    2323    double getDefaultZoomInPPD();
    24 
    25     /**
    26      * Convert from lat/lon to easting/northing.
    27      *
    28      * @param ll the geographical point to convert (in WGS84 lat/lon)
    29      * @return the corresponding east/north coordinates
    30      */
    31     EastNorth latlon2eastNorth(LatLon ll);
    3224
    3325    /**
  • trunk/src/org/openstreetmap/josm/data/projection/proj/Mercator.java

    r10378 r10805  
    120120        return scaleFactor;
    121121    }
     122
     123    @Override
     124    public boolean lonIsLinearToEast() {
     125        return true;
     126    }
    122127}
  • trunk/src/org/openstreetmap/josm/data/projection/proj/Proj.java

    r10001 r10805  
    9191     */
    9292    boolean isGeographic();
     93
     94    /**
     95     * Checks wether the result of projecting a lon coordinate only has a linear relation to the east coordinate and
     96     * is not related to lat/north at all.
     97     * @return <code>true</code> if lon has a linear relationship to east only.
     98     * @since 10805
     99     */
     100    default boolean lonIsLinearToEast() {
     101        return false;
     102    }
    93103}
Note: See TracChangeset for help on using the changeset viewer.