1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.imagery;
|
---|
3 |
|
---|
4 | import org.openstreetmap.gui.jmapviewer.Coordinate;
|
---|
5 | import org.openstreetmap.gui.jmapviewer.Projected;
|
---|
6 | import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
|
---|
7 | import org.openstreetmap.gui.jmapviewer.interfaces.IProjected;
|
---|
8 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
9 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Allows easy conversion between JMapViewer coordinate types and JOSM coordinate types.
|
---|
13 | * @since 12669
|
---|
14 | */
|
---|
15 | public final class CoordinateConversion {
|
---|
16 |
|
---|
17 | private CoordinateConversion() {
|
---|
18 | // Hide default constructor for utility classes
|
---|
19 | }
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Converts an {@link EastNorth} to an {@link IProjected} instance.
|
---|
23 | * @param en east/north coordinate
|
---|
24 | * @return {@code IProjected} instance
|
---|
25 | */
|
---|
26 | public static IProjected enToProj(EastNorth en) {
|
---|
27 | return new Projected(en.east(), en.north());
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Converts an {@link IProjected} to an {@link EastNorth} instance.
|
---|
32 | * @param p projected coordinate
|
---|
33 | * @return {@code EastNorth} instance
|
---|
34 | */
|
---|
35 | public static EastNorth projToEn(IProjected p) {
|
---|
36 | return new EastNorth(p.getEast(), p.getNorth());
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Converts a {@link LatLon} to an {@link ICoordinate} instance.
|
---|
41 | * @param ll latitude/longitude coordinate
|
---|
42 | * @return {@code ICoordinate} instance
|
---|
43 | */
|
---|
44 | public static ICoordinate llToCoor(LatLon ll) {
|
---|
45 | return new Coordinate(ll.lat(), ll.lon());
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Converts an {@link ICoordinate} to a {@link LatLon} instance.
|
---|
50 | * @param c coordinate
|
---|
51 | * @return {@code LatLon} instance
|
---|
52 | */
|
---|
53 | public static LatLon coorToLL(ICoordinate c) {
|
---|
54 | return new LatLon(c.getLat(), c.getLon());
|
---|
55 | }
|
---|
56 | }
|
---|