Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/geo/Projection.java
Projection.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 | 3 |
* |
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
... | ... | |
18 | 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
19 | 19 |
* |
20 | 20 |
* For more information, contact: |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* cresques@gmail.com |
23 | 23 |
*/ |
24 | 24 |
package org.cresques.geo; |
25 | 25 |
|
26 |
import org.cresques.cts.IDatum; |
|
27 |
import org.cresques.cts.IProjection; |
|
28 |
|
|
26 | 29 |
import java.awt.Color; |
27 | 30 |
import java.awt.Graphics2D; |
28 | 31 |
import java.awt.geom.Point2D; |
29 | 32 |
|
30 |
import org.cresques.cts.IDatum; |
|
31 |
import org.cresques.cts.IProjection; |
|
32 | 33 |
|
33 | 34 |
abstract public class Projection implements IProjection { |
34 |
public static int NORTH = 0; |
|
35 |
public static int SOUTH = 1; |
|
36 |
static String name = "Sin Proyeccion"; |
|
37 |
static String abrev = "None"; |
|
38 |
private static final Color basicGridColor = new Color(64,64,64,128); |
|
39 |
Color gridColor = basicGridColor; |
|
40 |
|
|
41 |
Ellipsoid eli = Ellipsoid.hayford; |
|
42 |
Graticule grid; |
|
43 |
|
|
44 |
public Projection() { |
|
45 |
eli = Ellipsoid.hayford; |
|
46 |
} |
|
47 |
|
|
48 |
public Projection(Ellipsoid e) { |
|
49 |
eli = e; |
|
50 |
} |
|
51 |
|
|
52 |
public String getName() { return name; } |
|
53 |
abstract public String getAbrev(); |
|
54 |
public IDatum getDatum() { return eli; } |
|
55 |
|
|
56 |
public double [] getElliPar() { return eli.getParam(); } |
|
57 |
|
|
58 |
abstract public Point2D createPoint(double x, double y); |
|
59 |
public Point2D createPoint(Point2D pt) { |
|
60 |
return createPoint(pt.getX(), pt.getY()); |
|
61 |
} |
|
62 |
|
|
63 |
public static IProjection getProjectionByName(IDatum eli, String name) { |
|
64 |
if (name.indexOf("UTM") >= 0) |
|
65 |
return UtmZone.getProjectionByName(eli, name); |
|
66 |
if (name.indexOf("GEO") >= 0) |
|
67 |
return Geodetic.getProjectionByName(eli, name); |
|
68 |
if (name.indexOf("MERC") >= 0) |
|
69 |
return Mercator.getProjectionByName(eli, name); |
|
70 |
return null; |
|
71 |
} |
|
72 |
|
|
73 |
public ReProjection getReproyectionTo(Projection proj) { |
|
74 |
ReProjection rp = new ReProjection(this, proj); |
|
75 |
return rp; |
|
76 |
} |
|
77 |
|
|
78 |
abstract public Point2D toGeo(Point2D pt); |
|
79 |
abstract public Point2D fromGeo(Point2D gPt, Point2D mPt); |
|
80 |
|
|
81 |
public void setGridColor(Color c) { gridColor = c;} |
|
82 |
public Color getGridColor() { return gridColor; } |
|
83 |
|
|
84 |
public static String coordToString(double coord, String fmt, boolean isLat) { |
|
85 |
String txt = fmt; |
|
86 |
int donde; |
|
87 |
donde = txt.indexOf("%G"); |
|
88 |
if (donde >= 0) { |
|
89 |
int deg = (int) coord; |
|
90 |
if (fmt.indexOf("%N") >= 0 && deg < 0) deg = -deg; |
|
91 |
txt = txt.substring(0, donde)+Integer.toString(deg)+txt.substring(donde+2); |
|
92 |
} |
|
93 |
donde = txt.indexOf("%M"); |
|
94 |
if (donde >= 0) { |
|
95 |
int min = (int) ((coord - (int)coord)*60.0) % 60; |
|
96 |
if (fmt.indexOf("%N") >= 0 && min < 0) min = -min; |
|
97 |
txt = txt.substring(0, donde)+Integer.toString(min)+txt.substring(donde+2);; |
|
98 |
} |
|
99 |
donde = txt.indexOf("%N"); |
|
100 |
if (donde >= 0) { |
|
101 |
String t = ""; |
|
102 |
if (isLat) { |
|
103 |
if (coord > 0) t = "N"; |
|
104 |
else if (coord < 0) t = "S"; |
|
105 |
} else { |
|
106 |
if (coord > 0) t = "E"; |
|
107 |
else if (coord < 0) t = "W"; |
|
108 |
} |
|
109 |
txt = txt.substring(0, donde)+t+txt.substring(donde+2);; |
|
110 |
} |
|
111 |
return txt; |
|
112 |
} |
|
113 |
|
|
114 |
abstract public void drawGrid(Graphics2D g, ViewPortData vp); |
|
35 |
public static int NORTH = 0; |
|
36 |
public static int SOUTH = 1; |
|
37 |
static String name = "Sin Proyeccion"; |
|
38 |
static String abrev = "None"; |
|
39 |
private static final Color basicGridColor = new Color(64, 64, 64, 128); |
|
40 |
Color gridColor = basicGridColor; |
|
41 |
Ellipsoid eli = Ellipsoid.hayford; |
|
42 |
Graticule grid; |
|
43 |
|
|
44 |
public Projection() { |
|
45 |
eli = Ellipsoid.hayford; |
|
46 |
} |
|
47 |
|
|
48 |
public Projection(Ellipsoid e) { |
|
49 |
eli = e; |
|
50 |
} |
|
51 |
|
|
52 |
public String getName() { |
|
53 |
return name; |
|
54 |
} |
|
55 |
|
|
56 |
abstract public String getAbrev(); |
|
57 |
|
|
58 |
public IDatum getDatum() { |
|
59 |
return eli; |
|
60 |
} |
|
61 |
|
|
62 |
public double[] getElliPar() { |
|
63 |
return eli.getParam(); |
|
64 |
} |
|
65 |
|
|
66 |
abstract public Point2D createPoint(double x, double y); |
|
67 |
|
|
68 |
public Point2D createPoint(Point2D pt) { |
|
69 |
return createPoint(pt.getX(), pt.getY()); |
|
70 |
} |
|
71 |
|
|
72 |
public static IProjection getProjectionByName(IDatum eli, String name) { |
|
73 |
if (name.indexOf("UTM") >= 0) { |
|
74 |
return UtmZone.getProjectionByName(eli, name); |
|
75 |
} |
|
76 |
|
|
77 |
if (name.indexOf("GEO") >= 0) { |
|
78 |
return Geodetic.getProjectionByName(eli, name); |
|
79 |
} |
|
80 |
|
|
81 |
if (name.indexOf("MERC") >= 0) { |
|
82 |
return Mercator.getProjectionByName(eli, name); |
|
83 |
} |
|
84 |
|
|
85 |
return null; |
|
86 |
} |
|
87 |
|
|
88 |
public ReProjection getReproyectionTo(Projection proj) { |
|
89 |
ReProjection rp = new ReProjection(this, proj); |
|
90 |
|
|
91 |
return rp; |
|
92 |
} |
|
93 |
|
|
94 |
abstract public Point2D toGeo(Point2D pt); |
|
95 |
|
|
96 |
abstract public Point2D fromGeo(Point2D gPt, Point2D mPt); |
|
97 |
|
|
98 |
public void setGridColor(Color c) { |
|
99 |
gridColor = c; |
|
100 |
} |
|
101 |
|
|
102 |
public Color getGridColor() { |
|
103 |
return gridColor; |
|
104 |
} |
|
105 |
|
|
106 |
public static String coordToString(double coord, String fmt, boolean isLat) { |
|
107 |
String txt = fmt; |
|
108 |
int donde; |
|
109 |
donde = txt.indexOf("%G"); |
|
110 |
|
|
111 |
if (donde >= 0) { |
|
112 |
int deg = (int) coord; |
|
113 |
|
|
114 |
if ((fmt.indexOf("%N") >= 0) && (deg < 0)) { |
|
115 |
deg = -deg; |
|
116 |
} |
|
117 |
|
|
118 |
txt = txt.substring(0, donde) + Integer.toString(deg) + |
|
119 |
txt.substring(donde + 2); |
|
120 |
} |
|
121 |
|
|
122 |
donde = txt.indexOf("%M"); |
|
123 |
|
|
124 |
if (donde >= 0) { |
|
125 |
int min = (int) ((coord - (int) coord) * 60.0) % 60; |
|
126 |
|
|
127 |
if ((fmt.indexOf("%N") >= 0) && (min < 0)) { |
|
128 |
min = -min; |
|
129 |
} |
|
130 |
|
|
131 |
txt = txt.substring(0, donde) + Integer.toString(min) + |
|
132 |
txt.substring(donde + 2); |
|
133 |
; |
|
134 |
} |
|
135 |
|
|
136 |
donde = txt.indexOf("%N"); |
|
137 |
|
|
138 |
if (donde >= 0) { |
|
139 |
String t = ""; |
|
140 |
|
|
141 |
if (isLat) { |
|
142 |
if (coord > 0) { |
|
143 |
t = "N"; |
|
144 |
} else if (coord < 0) { |
|
145 |
t = "S"; |
|
146 |
} |
|
147 |
} else { |
|
148 |
if (coord > 0) { |
|
149 |
t = "E"; |
|
150 |
} else if (coord < 0) { |
|
151 |
t = "W"; |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
txt = txt.substring(0, donde) + t + txt.substring(donde + 2); |
|
156 |
; |
|
157 |
} |
|
158 |
|
|
159 |
return txt; |
|
160 |
} |
|
161 |
|
|
162 |
abstract public void drawGrid(Graphics2D g, ViewPortData vp); |
|
115 | 163 |
} |
Also available in: Unified diff