Ignore:
Timestamp:
2016-01-12T17:39:45+01:00 (4 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/data/projection
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.