Ticket #11516: _11516___Sinusoidal_projection.patch

File _11516___Sinusoidal_projection.patch, 8.0 KB (added by simon04, 8 years ago)
  • src/org/openstreetmap/josm/data/projection/Projections.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    4040import org.openstreetmap.josm.data.projection.proj.PolarStereographic;
    4141import org.openstreetmap.josm.data.projection.proj.Proj;
    4242import org.openstreetmap.josm.data.projection.proj.ProjFactory;
     43import org.openstreetmap.josm.data.projection.proj.Sinusoidal;
    4344import org.openstreetmap.josm.data.projection.proj.SwissObliqueMercator;
    4445import org.openstreetmap.josm.data.projection.proj.TransverseMercator;
    4546import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice;
     
    9495        registerBaseProjection("merc", Mercator.class, "core");
    9596        registerBaseProjection("omerc", ObliqueMercator.class, "core");
    9697        registerBaseProjection("somerc", SwissObliqueMercator.class, "core");
     98        registerBaseProjection("sinu", Sinusoidal.class, "core");
    9799        registerBaseProjection("stere", PolarStereographic.class, "core");
    98100        registerBaseProjection("sterea", DoubleStereographic.class, "core");
    99101        registerBaseProjection("tmerc", TransverseMercator.class, "core");
  • data_nodist/projection/josm-epsg

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    417417<6811> +proj=omerc +lat_0=45.91666666666666 +lonc=-123 +alpha=295 +k=1 +x_0=7000000.00000248 +y_0=-2999999.999988 +no_uoff +gamma=295 +ellps=GRS80 +units=ft +no_defs +bounds=-125,45,-121,47 <>
    418418# NAD83(2011) / Oregon Columbia River West zone (m)
    419419<6810> +proj=omerc +lat_0=45.91666666666666 +lonc=-123 +alpha=295 +k=1 +x_0=7000000 +y_0=-3000000 +no_uoff +gamma=295 +ellps=GRS80 +units=m +no_defs +bounds=-125,45,-121,47 <>
     420##
     421## Following entries use Sinusoidal projection
     422##
     423# ESRI:54008 / World Sinusoidal
     424<54008> +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs <>
     425 No newline at end of file
  • src/org/openstreetmap/josm/tools/Geometry.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    3030import org.openstreetmap.josm.data.osm.Relation;
    3131import org.openstreetmap.josm.data.osm.RelationMember;
    3232import org.openstreetmap.josm.data.osm.Way;
     33import org.openstreetmap.josm.data.projection.Projection;
     34import org.openstreetmap.josm.data.projection.Projections;
    3335
    3436/**
    3537 * Some tools for geometry related tasks.
     
    629631
    630632    /**
    631633     * Returns area of a closed way in square meters.
    632      * (approximate(?), but should be OK for small areas)
    633634     *
    634      * Relies on the current projection: Works correctly, when
    635      * one unit in projected coordinates corresponds to one meter.
    636      * This is true for most projections, but not for WGS84 and
    637      * Mercator (EPSG:3857).
    638      *
    639635     * @param way Way to measure, should be closed (first node is the same as last node)
    640636     * @return area of the closed way.
    641637     */
    642638    public static double closedWayArea(Way way) {
    643 
    644         //http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/
    645         double area = 0;
    646         Node lastN = null;
    647         for (Node n : way.getNodes()) {
    648             if (lastN != null) {
    649                 area += (calcX(n) * calcY(lastN)) - (calcY(n) * calcX(lastN));
    650             }
    651             lastN = n;
    652         }
    653         return Math.abs(area/2);
    654     }
     639        return getAreaAndPerimeter(way.getNodes(), Projections.getProjectionByCode("EPSG:54008")).getArea();
     640    }
    655641
    656     protected static double calcX(Node p1) {
    657         double lat1, lon1, lat2, lon2;
    658         double dlon, dlat;
    659 
    660         lat1 = p1.getCoor().lat() * Math.PI / 180.0;
    661         lon1 = p1.getCoor().lon() * Math.PI / 180.0;
    662         lat2 = lat1;
    663         lon2 = 0;
    664 
    665         dlon = lon2 - lon1;
    666         dlat = lat2 - lat1;
    667 
    668         double a = Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2);
    669         double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    670         return 6367000 * c;
    671     }
    672 
    673     protected static double calcY(Node p1) {
    674         double lat1, lon1, lat2, lon2;
    675         double dlon, dlat;
    676 
    677         lat1 = p1.getCoor().lat() * Math.PI / 180.0;
    678         lon1 = p1.getCoor().lon() * Math.PI / 180.0;
    679         lat2 = 0;
    680         lon2 = lon1;
    681 
    682         dlon = lon2 - lon1;
    683         dlat = lat2 - lat1;
    684 
    685         double a = Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2);
    686         double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    687         return 6367000 * c;
    688     }
    689 
    690642    /**
    691643     * Determines whether a way is oriented clockwise.
    692644     *
     
    985937     * @return area and perimeter
    986938     */
    987939    public static AreaAndPerimeter getAreaAndPerimeter(List<Node> nodes) {
     940        return getAreaAndPerimeter(nodes, Main.getProjection());
     941    }
     942
     943    /**
     944     * Calculate area and perimeter length of a polygon in the given projection.
     945     *
     946     * @param nodes the list of nodes representing the polygon
     947     * @param projection the projection to use for the calculation
     948     * @return area and perimeter
     949     */
     950    public static AreaAndPerimeter getAreaAndPerimeter(List<Node> nodes, Projection projection) {
     951        CheckParameterUtil.ensureParameterNotNull(nodes, "nodes");
     952        CheckParameterUtil.ensureParameterNotNull(projection, "projection");
    988953        double area = 0;
    989954        double perimeter = 0;
    990955        if (!nodes.isEmpty()) {
    991956            boolean closed = nodes.get(0) == nodes.get(nodes.size() - 1);
    992957            int numSegments = closed ? nodes.size() - 1 : nodes.size();
    993             EastNorth p1 = nodes.get(0).getEastNorth();
     958            EastNorth p1 = projection.latlon2eastNorth(nodes.get(0).getCoor());
    994959            for (int i = 1; i <= numSegments; i++) {
    995                 EastNorth p2 = nodes.get(i == numSegments ? 0 : i).getEastNorth();
     960                final EastNorth p2 = projection.latlon2eastNorth(nodes.get(i == numSegments ? 0 : i).getCoor());
    996961                area += p1.east() * p2.north() - p2.east() * p1.north();
    997962                perimeter += p1.distance(p2);
    998963                p1 = p2;
  • src/org/openstreetmap/josm/data/projection/proj/Sinusoidal.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.data.projection.proj;
     3
     4import org.openstreetmap.josm.data.Bounds;
     5
     6import static org.openstreetmap.josm.tools.I18n.tr;
     7
     8/**
     9 * Sinusoidal projection (aka. Sanson–Flamsteed, Mercator equal-area projection)
     10 */
     11public class Sinusoidal extends AbstractProj {
     12
     13    @Override
     14    public String getName() {
     15        return tr("Sinusoidal");
     16    }
     17
     18    @Override
     19    public String getProj4Id() {
     20        return "sinu";
     21    }
     22
     23    @Override
     24    public double[] project(double lat_rad, double lon_rad) {
     25        return new double[]{lon_rad * Math.cos(lat_rad), lat_rad};
     26    }
     27
     28    @Override
     29    public double[] invproject(double east, double north) {
     30        return new double[]{east / Math.cos(north), north};
     31    }
     32
     33    @Override
     34    public Bounds getAlgorithmBounds() {
     35        return new Bounds(-90, -180, 90, 180, false);
     36    }
     37}