Changeset 9419 in josm for trunk


Ignore:
Timestamp:
2016-01-12T17:39:45+01:00 (8 years ago)
Author:
bastiK
Message:

add Albers Equal Area Projection and Polar Stereographic Projection (see #12186)
(imports pieces of code from the Geotools project)

Location:
trunk/src/org/openstreetmap/josm
Files:
3 added
11 edited

Legend:

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

    r9243 r9419  
    123123
    124124    /**
     125     * Check, if a point is within the bounds.
     126     * @param en the point
     127     * @return true, if <code>en</code> is within the bounds
     128     */
     129    public boolean contains(EastNorth en) {
     130        return minEast <= en.east() && en.east() <= maxEast &&
     131                minNorth <= en.north() && en.north() <= maxNorth;
     132    }
     133
     134    /**
    125135     * Returns the min east/north.
    126136     * @return the min east/north
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r9384 r9419  
    5656    public static final LatLon ZERO = new LatLon(0, 0);
    5757
     58    /**
     59     * North and south pole.
     60     */
     61    public static final LatLon NORTH_POLE = new LatLon(90, 0);
     62    public static final LatLon SOUTH_POLE = new LatLon(-90, 0);
     63
    5864    private static DecimalFormat cDmsMinuteFormatter = new DecimalFormat("00");
    5965    private static DecimalFormat cDmsSecondFormatter = new DecimalFormat("00.0");
  • trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java

    r9135 r9419  
    1414import org.openstreetmap.josm.Main;
    1515import org.openstreetmap.josm.data.Bounds;
     16import org.openstreetmap.josm.data.ProjectionBounds;
     17import org.openstreetmap.josm.data.coor.EastNorth;
    1618import org.openstreetmap.josm.data.coor.LatLon;
    1719import org.openstreetmap.josm.data.projection.datum.CentricDatum;
     
    2325import org.openstreetmap.josm.data.projection.datum.ThreeParameterDatum;
    2426import org.openstreetmap.josm.data.projection.datum.WGS84Datum;
     27import org.openstreetmap.josm.data.projection.proj.IPolar;
    2528import org.openstreetmap.josm.data.projection.proj.Mercator;
    2629import org.openstreetmap.josm.data.projection.proj.Proj;
     
    9598        /** Latitude of second standard parallel */
    9699        lat_2("lat_2", true),
     100        /** Latitude of true scale */
     101        lat_ts("lat_ts", true),
    97102        /** the exact proj.4 string will be preserved in the WKT representation */
    98103        wktext("wktext", false),  // ignored
     
    493498            projParams.lat2 = parseAngle(s, Param.lat_2.key);
    494499        }
     500        s = parameters.get(Param.lat_ts.key);
     501        if (s != null) {
     502            projParams.lat_ts = parseAngle(s, Param.lat_ts.key);
     503        }
    495504        proj.initialize(projParams);
    496505        return proj;
     
    690699        return ret;
    691700    }
     701
     702    @Override
     703    public Bounds getLatLonBoundsBox(ProjectionBounds r) {
     704        Bounds result = new Bounds(eastNorth2latlon(r.getMin()));
     705        result.extend(eastNorth2latlon(r.getMax()));
     706        final int N = 40;
     707        double dEast = (r.maxEast - r.minEast) / N;
     708        double dNorth = (r.maxNorth - r.minNorth) / N;
     709        for (int i = 0; i <= N; i++) {
     710            result.extend(eastNorth2latlon(new EastNorth(r.minEast + i * dEast, r.minNorth)));
     711            result.extend(eastNorth2latlon(new EastNorth(r.minEast + i * dEast, r.maxNorth)));
     712            result.extend(eastNorth2latlon(new EastNorth(r.minEast, r.minNorth  + i * dNorth)));
     713            result.extend(eastNorth2latlon(new EastNorth(r.maxEast, r.minNorth  + i * dNorth)));
     714        }
     715        // if the box contains one of the poles, the above method did not get
     716        // correct min/max latitude value
     717        if (proj instanceof IPolar) {;
     718            IPolar polarProj = (IPolar) proj;
     719            if (polarProj.hasPole(false)) {
     720                EastNorth enNorthPole = latlon2eastNorth(LatLon.NORTH_POLE);
     721                if (r.contains(enNorthPole)) {
     722                    result.extend(LatLon.NORTH_POLE);
     723                }
     724            }
     725            if (polarProj.hasPole(true)) {
     726                EastNorth enSouthPole = latlon2eastNorth(LatLon.SOUTH_POLE);
     727                if (r.contains(enSouthPole)) {
     728                    result.extend(LatLon.SOUTH_POLE);
     729                }
     730            }
     731        }
     732        return result;
     733    }
    692734}
  • trunk/src/org/openstreetmap/josm/data/projection/Ellipsoid.java

    r9243 r9419  
    114114
    115115    /**
    116      * first eccentricity
     116     * first eccentricity:
     117     * sqrt(a*a - b*b) / a
    117118     */
    118119    public final double e;
    119120
    120121    /**
    121      * first eccentricity squared
     122     * first eccentricity squared:
     123     * (a*a - b*b) / (a*a)
    122124     */
    123125    public final double e2;
    124126
    125127    /**
    126      * square of the second eccentricity
     128     * square of the second eccentricity:
     129     * (a*a - b*b) / (b*b)
    127130     */
    128131    public final double eb2;
     
    331334        return new LatLon(Math.toDegrees(lt), Math.toDegrees(lg));
    332335    }
    333 
     336   
    334337    /**
    335338     * convert ellipsoidal coordinates to cartesian coordinates
  • trunk/src/org/openstreetmap/josm/data/projection/Projection.java

    r9118 r9419  
    8383
    8484    /**
     85     * Find lat/lon-box containing all the area of a given rectangle in
     86     * east/north space.
     87     *
     88     * This is an approximate method. Points outside of the world should be ignored.
     89     *
     90     * @param pb the rectangle in projected space
     91     * @return minimum lat/lon box, that when projected, covers <code>pb</code>
     92     */
     93    Bounds getLatLonBoundsBox(ProjectionBounds pb);
     94
     95    /**
    8596     * Get the number of meters per unit of this projection. This more
    8697     * defines the scale of the map, than real conversion of unit to meters
  • trunk/src/org/openstreetmap/josm/data/projection/Projections.java

    r9370 r9419  
    2929import org.openstreetmap.josm.data.projection.datum.ThreeParameterDatum;
    3030import org.openstreetmap.josm.data.projection.datum.WGS84Datum;
     31import org.openstreetmap.josm.data.projection.proj.AlbersEqualArea;
    3132import org.openstreetmap.josm.data.projection.proj.ClassProjFactory;
    3233import org.openstreetmap.josm.data.projection.proj.DoubleStereographic;
     
    3435import org.openstreetmap.josm.data.projection.proj.LonLat;
    3536import org.openstreetmap.josm.data.projection.proj.Mercator;
     37import org.openstreetmap.josm.data.projection.proj.PolarStereographic;
    3638import org.openstreetmap.josm.data.projection.proj.Proj;
    3739import org.openstreetmap.josm.data.projection.proj.ProjFactory;
     
    8284
    8385    static {
    84         registerBaseProjection("lonlat", LonLat.class, "core");
     86        registerBaseProjection("aea", AlbersEqualArea.class, "core");
    8587        registerBaseProjection("josm:smerc", Mercator.class, "core");
    8688        registerBaseProjection("lcc", LambertConformalConic.class, "core");
     89        registerBaseProjection("lonlat", LonLat.class, "core");
    8790        registerBaseProjection("somerc", SwissObliqueMercator.class, "core");
     91        registerBaseProjection("stere", PolarStereographic.class, "core");
     92        registerBaseProjection("sterea", DoubleStereographic.class, "core");
    8893        registerBaseProjection("tmerc", TransverseMercator.class, "core");
    89         registerBaseProjection("sterea", DoubleStereographic.class, "core");
    9094
    9195        ellipsoids.put("airy", Ellipsoid.Airy);
  • trunk/src/org/openstreetmap/josm/data/projection/proj/AbstractProj.java

    r9132 r9419  
    5353
    5454    /**
     55     * Ellipsoid excentricity, equals to <code>sqrt({@link #excentricitySquared})</code>.
     56     * Value 0 means that the ellipsoid is spherical.
     57     *
     58     * @see #excentricitySquared
     59     */
     60    protected double e;
     61
     62    /**
    5563     * The square of excentricity: e² = (a²-b²)/a² where
    5664     * <var>e</var> is the excentricity,
     
    6371    public void initialize(ProjParameters params) throws ProjectionConfigurationException {
    6472        e2 = params.ellps.e2;
     73        e = params.ellps.e;
    6574        //  Compute constants for the mlfn
    6675        double t;
     
    134143        }
    135144    }
     145
     146    /**
     147     * Computes function <code>f(s,c,e²) = c/sqrt(1 - s²&times;e²)</code> needed for the true scale
     148     * latitude (Snyder 14-15), where <var>s</var> and <var>c</var> are the sine and cosine of
     149     * the true scale latitude, and <var>e²</var> is the {@linkplain #excentricitySquared
     150     * eccentricity squared}.
     151     */
     152    final double msfn(final double s, final double c) {
     153        return c / Math.sqrt(1.0 - (s*s) * e2);
     154    }
     155
     156    /**
     157     * Computes function (15-9) and (9-13) from Snyder.
     158     * Equivalent to negative of function (7-7).
     159     */
     160    final double tsfn(final double lat, double sinlat) {
     161        sinlat *= e;
     162        /*
     163         * NOTE: change sign to get the equivalent of Snyder (7-7).
     164         */
     165        return Math.tan(0.5 * (Math.PI/2 - lat)) / Math.pow((1 - sinlat) / (1 + sinlat), 0.5*e);
     166    }
    136167}
  • trunk/src/org/openstreetmap/josm/data/projection/proj/ProjParameters.java

    r8346 r9419  
    1414    public Double lat1;
    1515    public Double lat2;
     16    public Double lat_ts;
    1617}
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r9408 r9419  
    311311    }
    312312
     313    public ProjectionBounds getProjectionBounds(Rectangle r) {
     314        EastNorth p1 = getEastNorth(r.x, r.y);
     315        EastNorth p2 = getEastNorth(r.x + r.width, r.y + r.height);
     316        ProjectionBounds pb = new ProjectionBounds(p1);
     317        pb.extend(p2);
     318        return pb;
     319    }
     320   
    313321    /**
    314322     * @param r rectangle
     
    316324     */
    317325    public Bounds getLatLonBounds(Rectangle r) {
    318         // TODO Maybe this should be (optional) method of Projection implementation
    319         EastNorth p1 = getEastNorth(r.x, r.y);
    320         EastNorth p2 = getEastNorth(r.x + r.width, r.y + r.height);
    321 
    322         Bounds result = new Bounds(Main.getProjection().eastNorth2latlon(p1));
    323 
    324         double eastMin = Math.min(p1.east(), p2.east());
    325         double eastMax = Math.max(p1.east(), p2.east());
    326         double northMin = Math.min(p1.north(), p2.north());
    327         double northMax = Math.max(p1.north(), p2.north());
    328         double deltaEast = (eastMax - eastMin) / 10;
    329         double deltaNorth = (northMax - northMin) / 10;
    330 
    331         for (int i = 0; i < 10; i++) {
    332             result.extend(Main.getProjection().eastNorth2latlon(new EastNorth(eastMin + i * deltaEast, northMin)));
    333             result.extend(Main.getProjection().eastNorth2latlon(new EastNorth(eastMin + i * deltaEast, northMax)));
    334             result.extend(Main.getProjection().eastNorth2latlon(new EastNorth(eastMin, northMin  + i * deltaNorth)));
    335             result.extend(Main.getProjection().eastNorth2latlon(new EastNorth(eastMax, northMin  + i * deltaNorth)));
    336         }
    337 
    338         return result;
     326        return Main.getProjection().getLatLonBoundsBox(getProjectionBounds(r));
    339327    }
    340328
  • trunk/src/org/openstreetmap/josm/gui/util/HighlightHelper.java

    r8929 r9419  
    1414
    1515/**
    16  * This class stores the set of highlited primitives and
    17  * allows easy and fast change of highlighting
     16 * This class stores the set of highlighted primitives and
     17 * allows easy and fast change of highlighting.
    1818 */
    1919public class HighlightHelper {
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r9352 r9419  
    9292    public static final String URL_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=%";
    9393
    94     private static char[] DEFAULT_STRIP = {'\u200B', '\uFEFF'};
     94    private static final char[] DEFAULT_STRIP = {'\u200B', '\uFEFF'};
    9595
    9696    /**
     
    10001000
    10011001    /**
    1002      * An alternative to {@link String#trim()} to effectively remove all leading and trailing white characters, including Unicode ones.
     1002     * An alternative to {@link String#trim()} to effectively remove all leading
     1003     * and trailing white characters, including Unicode ones.
    10031004     * @param str The string to strip
    10041005     * @return <code>str</code>, without leading and trailing characters, according to
     
    10171018
    10181019    /**
    1019      * An alternative to {@link String#trim()} to effectively remove all leading and trailing white characters, including Unicode ones.
     1020     * An alternative to {@link String#trim()} to effectively remove all leading
     1021     * and trailing white characters, including Unicode ones.
    10201022     * @param str The string to strip
    10211023     * @param skipChars additional characters to skip
Note: See TracChangeset for help on using the changeset viewer.