Changeset 9532 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2016-01-18T22:48:40+01:00 (8 years ago)
Author:
bastiK
Message:

see #12186 - add Oblique Mercator projection
(imports pieces of code from the Geotools project)

Location:
trunk/src/org/openstreetmap/josm
Files:
2 added
5 edited

Legend:

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

    r9431 r9532  
    2525import org.openstreetmap.josm.data.projection.datum.ThreeParameterDatum;
    2626import org.openstreetmap.josm.data.projection.datum.WGS84Datum;
     27import org.openstreetmap.josm.data.projection.proj.ICentralMeridianProvider;
    2728import org.openstreetmap.josm.data.projection.proj.IPolar;
    2829import org.openstreetmap.josm.data.projection.proj.Mercator;
     
    9899        /** Latitude of second standard parallel */
    99100        lat_2("lat_2", true),
    100         /** Latitude of true scale */
     101        /** Latitude of true scale (Polar Stereographic) */
    101102        lat_ts("lat_ts", true),
     103        /** longitude of the center of the projection (Oblique Mercator) */
     104        lonc("lonc", true),
     105        /** azimuth (true) of the center line passing through the center of the
     106         * projection (Oblique Mercator) */
     107        alpha("alpha", true),
     108        /** rectified bearing of the center line (Oblique Mercator) */
     109        gamma("gamma", true),
     110        /** select "Hotine" variant of Oblique Mercator */
     111        no_off("no_off", false),
     112        /** legacy alias for no_off */
     113        no_uoff("no_uoff", false),
     114        /** longitude of first point (Oblique Mercator) */
     115        lon_1("lon_1", true),
     116        /** longitude of second point (Oblique Mercator) */
     117        lon_2("lon_2", true),
    102118        /** the exact proj.4 string will be preserved in the WKT representation */
    103119        wktext("wktext", false),  // ignored
     
    232248            if (s != null) {
    233249                this.lon0 = parseAngle(s, Param.lon_0.key);
     250            }
     251            if (proj instanceof ICentralMeridianProvider) {
     252                this.lon0 = ((ICentralMeridianProvider) proj).getCentralMeridian();
    234253            }
    235254            s = parameters.get(Param.pm.key);
     
    501520        if (s != null) {
    502521            projParams.lat_ts = parseAngle(s, Param.lat_ts.key);
     522        }
     523        s = parameters.get(Param.lonc.key);
     524        if (s != null) {
     525            projParams.lonc = parseAngle(s, Param.lonc.key);
     526        }
     527        s = parameters.get(Param.alpha.key);
     528        if (s != null) {
     529            projParams.alpha = parseAngle(s, Param.alpha.key);
     530        }
     531        s = parameters.get(Param.gamma.key);
     532        if (s != null) {
     533            projParams.gamma = parseAngle(s, Param.gamma.key);
     534        }
     535        s = parameters.get(Param.lon_1.key);
     536        if (s != null) {
     537            projParams.lon1 = parseAngle(s, Param.lon_1.key);
     538        }
     539        s = parameters.get(Param.lon_2.key);
     540        if (s != null) {
     541            projParams.lon2 = parseAngle(s, Param.lon_2.key);
     542        }
     543        if (parameters.containsKey(Param.no_off.key) || parameters.containsKey(Param.no_uoff.key)) {
     544            projParams.no_off = true;
    503545        }
    504546        proj.initialize(projParams);
  • trunk/src/org/openstreetmap/josm/data/projection/Projections.java

    r9419 r9532  
    3535import org.openstreetmap.josm.data.projection.proj.LonLat;
    3636import org.openstreetmap.josm.data.projection.proj.Mercator;
     37import org.openstreetmap.josm.data.projection.proj.ObliqueMercator;
    3738import org.openstreetmap.josm.data.projection.proj.PolarStereographic;
    3839import org.openstreetmap.josm.data.projection.proj.Proj;
     
    8889        registerBaseProjection("lcc", LambertConformalConic.class, "core");
    8990        registerBaseProjection("lonlat", LonLat.class, "core");
     91        registerBaseProjection("omerc", ObliqueMercator.class, "core");
    9092        registerBaseProjection("somerc", SwissObliqueMercator.class, "core");
    9193        registerBaseProjection("stere", PolarStereographic.class, "core");
  • trunk/src/org/openstreetmap/josm/data/projection/proj/AbstractProj.java

    r9432 r9532  
    2525
    2626    /**
     27     * Difference allowed in iterative computations.
     28     */
     29    private static final double ITERATION_TOLERANCE = 1E-10;
     30
     31    /**
    2732     * Relative iteration precision used in the <code>mlfn</code> method
    2833     */
     
    153158
    154159    /**
     160     * Iteratively solve equation (7-9) from Snyder.
     161     */
     162    final double cphi2(final double ts) {
     163        final double eccnth = 0.5 * e;
     164        double phi = (Math.PI/2) - 2.0 * Math.atan(ts);
     165        for (int i=0; i<MAXIMUM_ITERATIONS; i++) {
     166            final double con  = e * Math.sin(phi);
     167            final double dphi = (Math.PI/2) - 2.0*Math.atan(ts * Math.pow((1-con)/(1+con), eccnth)) - phi;
     168            phi += dphi;
     169            if (Math.abs(dphi) <= ITERATION_TOLERANCE) {
     170                return phi;
     171            }
     172        }
     173        throw new RuntimeException("no convergence");
     174    }
     175
     176    /**
    155177     * Computes function <code>f(s,c,e²) = c/sqrt(1 - s²&times;e²)</code> needed for the true scale
    156178     * latitude (Snyder 14-15), where <var>s</var> and <var>c</var> are the sine and cosine of
  • trunk/src/org/openstreetmap/josm/data/projection/proj/ProjParameters.java

    r9419 r9532  
    1414    public Double lat1;
    1515    public Double lat2;
     16
     17    // Polar Stereographic
    1618    public Double lat_ts;
     19
     20    // Oblique Mercator
     21    public Double lonc;
     22    public Double alpha;
     23    public Double gamma;
     24    public Boolean no_off;
     25    public Double lon1;
     26    public Double lon2;
    1727}
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r9246 r9532  
    739739        GeneralPath path = new GeneralPath();
    740740
     741        double d = 1.0;
    741742        path.moveTo(p.x, p.y);
    742743        double max = b.getMax().lat();
    743         for (; lat <= max; lat += 1.0) {
     744        for (; lat <= max; lat += d) {
    744745            p = getPoint(new LatLon(lat >= max ? max : lat, lon));
    745746            path.lineTo(p.x, p.y);
    746747        }
    747748        lat = max; max = b.getMax().lon();
    748         for (; lon <= max; lon += 1.0) {
     749        for (; lon <= max; lon += d) {
    749750            p = getPoint(new LatLon(lat, lon >= max ? max : lon));
    750751            path.lineTo(p.x, p.y);
    751752        }
    752753        lon = max; max = b.getMinLat();
    753         for (; lat >= max; lat -= 1.0) {
     754        for (; lat >= max; lat -= d) {
    754755            p = getPoint(new LatLon(lat <= max ? max : lat, lon));
    755756            path.lineTo(p.x, p.y);
    756757        }
    757758        lat = max; max = b.getMinLon();
    758         for (; lon >= max; lon -= 1.0) {
     759        for (; lon >= max; lon -= d) {
    759760            p = getPoint(new LatLon(lat, lon <= max ? max : lon));
    760761            path.lineTo(p.x, p.y);
Note: See TracChangeset for help on using the changeset viewer.