IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
|
| 40 | 40 | import org.openstreetmap.josm.data.projection.proj.PolarStereographic; |
| 41 | 41 | import org.openstreetmap.josm.data.projection.proj.Proj; |
| 42 | 42 | import org.openstreetmap.josm.data.projection.proj.ProjFactory; |
| | 43 | import org.openstreetmap.josm.data.projection.proj.Sinusoidal; |
| 43 | 44 | import org.openstreetmap.josm.data.projection.proj.SwissObliqueMercator; |
| 44 | 45 | import org.openstreetmap.josm.data.projection.proj.TransverseMercator; |
| 45 | 46 | import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice; |
| … |
… |
|
| 94 | 95 | registerBaseProjection("merc", Mercator.class, "core"); |
| 95 | 96 | registerBaseProjection("omerc", ObliqueMercator.class, "core"); |
| 96 | 97 | registerBaseProjection("somerc", SwissObliqueMercator.class, "core"); |
| | 98 | registerBaseProjection("sinu", Sinusoidal.class, "core"); |
| 97 | 99 | registerBaseProjection("stere", PolarStereographic.class, "core"); |
| 98 | 100 | registerBaseProjection("sterea", DoubleStereographic.class, "core"); |
| 99 | 101 | registerBaseProjection("tmerc", TransverseMercator.class, "core"); |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
|
| 417 | 417 | <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 <> |
| 418 | 418 | # NAD83(2011) / Oregon Columbia River West zone (m) |
| 419 | 419 | <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 |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
|
| 30 | 30 | import org.openstreetmap.josm.data.osm.Relation; |
| 31 | 31 | import org.openstreetmap.josm.data.osm.RelationMember; |
| 32 | 32 | import org.openstreetmap.josm.data.osm.Way; |
| | 33 | import org.openstreetmap.josm.data.projection.Projection; |
| | 34 | import org.openstreetmap.josm.data.projection.Projections; |
| 33 | 35 | |
| 34 | 36 | /** |
| 35 | 37 | * Some tools for geometry related tasks. |
| … |
… |
|
| 629 | 631 | |
| 630 | 632 | /** |
| 631 | 633 | * Returns area of a closed way in square meters. |
| 632 | | * (approximate(?), but should be OK for small areas) |
| 633 | 634 | * |
| 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 | | * |
| 639 | 635 | * @param way Way to measure, should be closed (first node is the same as last node) |
| 640 | 636 | * @return area of the closed way. |
| 641 | 637 | */ |
| 642 | 638 | 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 | } |
| 655 | 641 | |
| 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 | | |
| 690 | 642 | /** |
| 691 | 643 | * Determines whether a way is oriented clockwise. |
| 692 | 644 | * |
| … |
… |
|
| 985 | 937 | * @return area and perimeter |
| 986 | 938 | */ |
| 987 | 939 | 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"); |
| 988 | 953 | double area = 0; |
| 989 | 954 | double perimeter = 0; |
| 990 | 955 | if (!nodes.isEmpty()) { |
| 991 | 956 | boolean closed = nodes.get(0) == nodes.get(nodes.size() - 1); |
| 992 | 957 | int numSegments = closed ? nodes.size() - 1 : nodes.size(); |
| 993 | | EastNorth p1 = nodes.get(0).getEastNorth(); |
| | 958 | EastNorth p1 = projection.latlon2eastNorth(nodes.get(0).getCoor()); |
| 994 | 959 | 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()); |
| 996 | 961 | area += p1.east() * p2.north() - p2.east() * p1.north(); |
| 997 | 962 | perimeter += p1.distance(p2); |
| 998 | 963 | p1 = p2; |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
|
| | 1 | // License: GPL. For details, see LICENSE file. |
| | 2 | package org.openstreetmap.josm.data.projection.proj; |
| | 3 | |
| | 4 | import org.openstreetmap.josm.data.Bounds; |
| | 5 | |
| | 6 | import static org.openstreetmap.josm.tools.I18n.tr; |
| | 7 | |
| | 8 | /** |
| | 9 | * Sinusoidal projection (aka. Sanson–Flamsteed, Mercator equal-area projection) |
| | 10 | */ |
| | 11 | public 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 | } |