1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.data.projection;
|
---|
3 |
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.Arrays;
|
---|
6 | import java.util.HashMap;
|
---|
7 | import java.util.Map;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.Main;
|
---|
10 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
11 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
12 | import org.openstreetmap.josm.data.projection.datum.Datum;
|
---|
13 | import org.openstreetmap.josm.data.projection.datum.WGS84Datum;
|
---|
14 | import org.openstreetmap.josm.data.projection.proj.LambertConformalConic;
|
---|
15 | import org.openstreetmap.josm.data.projection.proj.Proj;
|
---|
16 | import org.openstreetmap.josm.data.projection.proj.SwissObliqueMercator;
|
---|
17 | import org.openstreetmap.josm.data.projection.proj.TransverseMercator;
|
---|
18 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Class to handle projections
|
---|
22 | *
|
---|
23 | */
|
---|
24 | public class Projections {
|
---|
25 | /**
|
---|
26 | * List of all available projections.
|
---|
27 | */
|
---|
28 | private static ArrayList<Projection> allProjections =
|
---|
29 | new ArrayList<Projection>(Arrays.asList(new Projection[] {
|
---|
30 | // global projections
|
---|
31 | new Epsg4326(),
|
---|
32 | new Mercator(),
|
---|
33 | new UTM(),
|
---|
34 | // regional - alphabetical order by country code
|
---|
35 | new BelgianLambert1972(), // BE
|
---|
36 | new BelgianLambert2008(), // BE
|
---|
37 | new SwissGrid(), // CH
|
---|
38 | new GaussKrueger(), // DE
|
---|
39 | new LambertEST(), // EE
|
---|
40 | new Lambert(), // FR
|
---|
41 | new Lambert93(), // FR
|
---|
42 | new LambertCC9Zones(), // FR
|
---|
43 | new UTM_France_DOM(), // FR
|
---|
44 | new TransverseMercatorLV(), // LV
|
---|
45 | new Puwg(), // PL
|
---|
46 | new Epsg3008(), // SE
|
---|
47 | }));
|
---|
48 |
|
---|
49 | static {
|
---|
50 | if (Main.pref.getBoolean("customprojection")) {
|
---|
51 | addProjection(new CustomProjection());
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | public static ArrayList<Projection> getProjections() {
|
---|
56 | return allProjections;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Adds a new projection to the list of known projections.
|
---|
61 | *
|
---|
62 | * For Plugins authors: make sure your plugin is an early plugin, i.e. put
|
---|
63 | * Plugin-Early=true in your Manifest.
|
---|
64 | */
|
---|
65 | public static void addProjection(Projection proj) {
|
---|
66 | allProjections.add(proj);
|
---|
67 | }
|
---|
68 |
|
---|
69 | public static EastNorth project(LatLon ll) {
|
---|
70 | if (ll == null) return null;
|
---|
71 | return Main.getProjection().latlon2eastNorth(ll);
|
---|
72 | }
|
---|
73 |
|
---|
74 | public static LatLon inverseProject(EastNorth en) {
|
---|
75 | if (en == null) return null;
|
---|
76 | return Main.getProjection().eastNorth2latlon(en);
|
---|
77 | }
|
---|
78 |
|
---|
79 | /*********************************
|
---|
80 | * Registry for custom projection
|
---|
81 | *
|
---|
82 | * should be compatible to PROJ.4
|
---|
83 | */
|
---|
84 |
|
---|
85 | private static Map<String, Ellipsoid> ellipsoids = new HashMap<String, Ellipsoid>();
|
---|
86 | private static Map<String, Class<? extends Proj>> projs = new HashMap<String, Class<? extends Proj>>();
|
---|
87 | private static Map<String, Datum> datums = new HashMap<String, Datum>();
|
---|
88 |
|
---|
89 | static {
|
---|
90 | ellipsoids.put("intl", Ellipsoid.hayford);
|
---|
91 | ellipsoids.put("GRS80", Ellipsoid.GRS80);
|
---|
92 | ellipsoids.put("WGS84", Ellipsoid.WGS84);
|
---|
93 | ellipsoids.put("bessel", Ellipsoid.Bessel1841);
|
---|
94 |
|
---|
95 | projs.put("merc", org.openstreetmap.josm.data.projection.proj.Mercator.class);
|
---|
96 | projs.put("lcc", LambertConformalConic.class);
|
---|
97 | projs.put("somerc", SwissObliqueMercator.class);
|
---|
98 | projs.put("tmerc", TransverseMercator.class);
|
---|
99 |
|
---|
100 | datums.put("WGS84", WGS84Datum.INSTANCE);
|
---|
101 | }
|
---|
102 |
|
---|
103 | public static Ellipsoid getEllipsoid(String id) {
|
---|
104 | return ellipsoids.get(id);
|
---|
105 | }
|
---|
106 |
|
---|
107 | public static Proj getProjection(String id) {
|
---|
108 | Class<? extends Proj> projClass = projs.get(id);
|
---|
109 | if (projClass == null) return null;
|
---|
110 | Proj proj = null;
|
---|
111 | try {
|
---|
112 | proj = projClass.newInstance();
|
---|
113 | } catch (InstantiationException e) {
|
---|
114 | throw new RuntimeException(e);
|
---|
115 | } catch (IllegalAccessException e) {
|
---|
116 | throw new RuntimeException(e);
|
---|
117 | }
|
---|
118 | return proj;
|
---|
119 | }
|
---|
120 |
|
---|
121 | public static Datum getDatum(String id) {
|
---|
122 | return datums.get(id);
|
---|
123 | }
|
---|
124 | }
|
---|