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.NTV2GridShiftFileWrapper;
|
---|
14 | import org.openstreetmap.josm.data.projection.datum.WGS84Datum;
|
---|
15 | import org.openstreetmap.josm.data.projection.proj.ClassProjFactory;
|
---|
16 | import org.openstreetmap.josm.data.projection.proj.LambertConformalConic;
|
---|
17 | import org.openstreetmap.josm.data.projection.proj.LonLat;
|
---|
18 | import org.openstreetmap.josm.data.projection.proj.Proj;
|
---|
19 | import org.openstreetmap.josm.data.projection.proj.ProjFactory;
|
---|
20 | import org.openstreetmap.josm.data.projection.proj.SwissObliqueMercator;
|
---|
21 | import org.openstreetmap.josm.data.projection.proj.TransverseMercator;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Class to handle projections
|
---|
25 | *
|
---|
26 | */
|
---|
27 | public class Projections {
|
---|
28 | /**
|
---|
29 | * List of all available projections.
|
---|
30 | */
|
---|
31 | private static ArrayList<Projection> allProjections =
|
---|
32 | new ArrayList<Projection>(Arrays.asList(new Projection[] {
|
---|
33 | // global projections
|
---|
34 | new Epsg4326(),
|
---|
35 | new Mercator(),
|
---|
36 | new UTM(),
|
---|
37 | // regional - alphabetical order by country code
|
---|
38 | new BelgianLambert1972(), // BE
|
---|
39 | new BelgianLambert2008(), // BE
|
---|
40 | new SwissGrid(), // CH
|
---|
41 | new GaussKrueger(), // DE
|
---|
42 | new LambertEST(), // EE
|
---|
43 | new Lambert(), // FR
|
---|
44 | new Lambert93(), // FR
|
---|
45 | new LambertCC9Zones(), // FR
|
---|
46 | new UTM_France_DOM(), // FR
|
---|
47 | new TransverseMercatorLV(), // LV
|
---|
48 | new Puwg(), // PL
|
---|
49 | new Epsg3008(), // SE
|
---|
50 | new CustomProjectionPrefGui()
|
---|
51 | }));
|
---|
52 |
|
---|
53 | public static ArrayList<Projection> getProjections() {
|
---|
54 | return allProjections;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Adds a new projection to the list of known projections.
|
---|
59 | *
|
---|
60 | * For Plugins authors: make sure your plugin is an early plugin, i.e. put
|
---|
61 | * Plugin-Early=true in your Manifest.
|
---|
62 | */
|
---|
63 | public static void addProjection(Projection proj) {
|
---|
64 | allProjections.add(proj);
|
---|
65 | }
|
---|
66 |
|
---|
67 | public static EastNorth project(LatLon ll) {
|
---|
68 | if (ll == null) return null;
|
---|
69 | return Main.getProjection().latlon2eastNorth(ll);
|
---|
70 | }
|
---|
71 |
|
---|
72 | public static LatLon inverseProject(EastNorth en) {
|
---|
73 | if (en == null) return null;
|
---|
74 | return Main.getProjection().eastNorth2latlon(en);
|
---|
75 | }
|
---|
76 |
|
---|
77 | /*********************************
|
---|
78 | * Registry for custom projection
|
---|
79 | *
|
---|
80 | * should be compatible to PROJ.4
|
---|
81 | */
|
---|
82 | public static Map<String, Ellipsoid> ellipsoids = new HashMap<String, Ellipsoid>();
|
---|
83 | public static Map<String, ProjFactory> projs = new HashMap<String, ProjFactory>();
|
---|
84 | public static Map<String, Datum> datums = new HashMap<String, Datum>();
|
---|
85 | public static Map<String, NTV2GridShiftFileWrapper> nadgrids = new HashMap<String, NTV2GridShiftFileWrapper>();
|
---|
86 |
|
---|
87 | static {
|
---|
88 | registerBaseProjection("lonlat", LonLat.class, "core");
|
---|
89 | registerBaseProjection("merc", org.openstreetmap.josm.data.projection.proj.Mercator.class, "core");
|
---|
90 | registerBaseProjection("lcc", LambertConformalConic.class, "core");
|
---|
91 | registerBaseProjection("somerc", SwissObliqueMercator.class, "core");
|
---|
92 | registerBaseProjection("tmerc", TransverseMercator.class, "core");
|
---|
93 |
|
---|
94 | ellipsoids.put("intl", Ellipsoid.hayford);
|
---|
95 | ellipsoids.put("GRS80", Ellipsoid.GRS80);
|
---|
96 | ellipsoids.put("WGS84", Ellipsoid.WGS84);
|
---|
97 | ellipsoids.put("bessel", Ellipsoid.Bessel1841);
|
---|
98 |
|
---|
99 | datums.put("WGS84", WGS84Datum.INSTANCE);
|
---|
100 |
|
---|
101 | nadgrids.put("BETA2007.gsb", NTV2GridShiftFileWrapper.BETA2007);
|
---|
102 | nadgrids.put("ntf_r93_b.gsb", NTV2GridShiftFileWrapper.ntf_rgf93);
|
---|
103 | }
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Plugins can register additional base projections.
|
---|
107 | *
|
---|
108 | * @param id The "official" PROJ.4 id. In case the projection is not supported
|
---|
109 | * by PROJ.4, use some prefix, e.g. josm:myproj or gdal:otherproj.
|
---|
110 | * @param fac The base projection factory.
|
---|
111 | * @param origin Multiple plugins may implement the same base projection.
|
---|
112 | * Provide plugin name or similar string, so it be differentiated.
|
---|
113 | */
|
---|
114 | public static void registerBaseProjection(String id, ProjFactory fac, String origin) {
|
---|
115 | projs.put(id, fac);
|
---|
116 | }
|
---|
117 |
|
---|
118 | public static void registerBaseProjection(String id, Class<? extends Proj> projClass, String origin) {
|
---|
119 | registerBaseProjection(id, new ClassProjFactory(projClass), origin);
|
---|
120 | }
|
---|
121 |
|
---|
122 | public static Proj getBaseProjection(String id) {
|
---|
123 | ProjFactory fac = projs.get(id);
|
---|
124 | if (fac == null) return null;
|
---|
125 | return fac.createInstance();
|
---|
126 | }
|
---|
127 |
|
---|
128 | public static Ellipsoid getEllipsoid(String id) {
|
---|
129 | return ellipsoids.get(id);
|
---|
130 | }
|
---|
131 |
|
---|
132 | public static Datum getDatum(String id) {
|
---|
133 | return datums.get(id);
|
---|
134 | }
|
---|
135 |
|
---|
136 | public static NTV2GridShiftFileWrapper getNadgrids(String id) {
|
---|
137 | return nadgrids.get(id);
|
---|
138 | }
|
---|
139 | }
|
---|