Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/geo/UtmZone.java
UtmZone.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 java.awt.Graphics2D;
|
|
27 |
import java.awt.geom.AffineTransform;
|
|
28 |
import java.awt.geom.Point2D;
|
|
26 |
import geojava.GeoUtm;
|
|
27 |
import geojava.Ra2De;
|
|
28 |
import geojava.UtmGeo;
|
|
29 | 29 |
|
30 | 30 |
import org.cresques.cts.IDatum; |
31 | 31 |
import org.cresques.cts.IProjection; |
32 |
|
|
32 | 33 |
import org.cresques.px.Extent; |
33 | 34 |
|
34 |
import geojava.UtmGeo;
|
|
35 |
import geojava.Ra2De;
|
|
36 |
import geojava.GeoUtm;
|
|
35 |
import java.awt.Graphics2D;
|
|
36 |
import java.awt.geom.AffineTransform;
|
|
37 |
import java.awt.geom.Point2D;
|
|
37 | 38 |
|
39 |
|
|
38 | 40 |
public class UtmZone extends Projection { |
39 |
static String name = "UTM"; |
|
40 |
static String abrev = "UTM"; |
|
41 |
private final static UtmZone ed5028N = new UtmZone(Ellipsoid.ed50, 28, 0, 0.0); |
|
42 |
private final static UtmZone ed5029N = new UtmZone(Ellipsoid.ed50, 29, 0, 0.0); |
|
43 |
private final static UtmZone ed5030N = new UtmZone(Ellipsoid.ed50, 30, 0, 0.0); |
|
44 |
private final static UtmZone ed5031N = new UtmZone(Ellipsoid.ed50, 31, 0, 0.0); |
|
45 |
private final static UtmZone hayford28N = new UtmZone(Ellipsoid.hayford, 28, 0, 0.0); |
|
46 |
private final static UtmZone hayford29N = new UtmZone(Ellipsoid.hayford, 29, 0, 0.0); |
|
47 |
private final static UtmZone hayford30N = new UtmZone(Ellipsoid.hayford, 30, 0, 0.0); |
|
48 |
private final static UtmZone hayford31N = new UtmZone(Ellipsoid.hayford, 31, 0, 0.0); |
|
49 |
public int Zone = 30; |
|
50 |
public int Hemisphere = 0; |
|
51 |
public double H = 0.0; |
|
41 |
static String name = "UTM"; |
|
42 |
static String abrev = "UTM"; |
|
43 |
private final static UtmZone ed5028N = new UtmZone(Ellipsoid.ed50, 28, 0, |
|
44 |
0.0); |
|
45 |
private final static UtmZone ed5029N = new UtmZone(Ellipsoid.ed50, 29, 0, |
|
46 |
0.0); |
|
47 |
private final static UtmZone ed5030N = new UtmZone(Ellipsoid.ed50, 30, 0, |
|
48 |
0.0); |
|
49 |
private final static UtmZone ed5031N = new UtmZone(Ellipsoid.ed50, 31, 0, |
|
50 |
0.0); |
|
51 |
private final static UtmZone hayford28N = new UtmZone(Ellipsoid.hayford, |
|
52 |
28, 0, 0.0); |
|
53 |
private final static UtmZone hayford29N = new UtmZone(Ellipsoid.hayford, |
|
54 |
29, 0, 0.0); |
|
55 |
private final static UtmZone hayford30N = new UtmZone(Ellipsoid.hayford, |
|
56 |
30, 0, 0.0); |
|
57 |
private final static UtmZone hayford31N = new UtmZone(Ellipsoid.hayford, |
|
58 |
31, 0, 0.0); |
|
59 |
static GeoUtm geoutm = new GeoUtm(); |
|
60 |
static UtmGeo utmgeo = new UtmGeo(); |
|
61 |
public int Zone = 30; |
|
62 |
public int Hemisphere = 0; |
|
63 |
public double H = 0.0; |
|
52 | 64 |
|
53 |
static GeoUtm geoutm = new GeoUtm(); |
|
54 |
static UtmGeo utmgeo = new UtmGeo(); |
|
55 |
|
|
56 |
public UtmZone(Ellipsoid eli, int zone, int hemisphere, double h) { |
|
57 |
super(eli); |
|
58 |
Zone = zone; |
|
59 |
Hemisphere = hemisphere; |
|
60 |
H = h; |
|
61 |
grid = new Graticule(this); |
|
62 |
} |
|
65 |
public UtmZone(Ellipsoid eli, int zone, int hemisphere, double h) { |
|
66 |
super(eli); |
|
67 |
Zone = zone; |
|
68 |
Hemisphere = hemisphere; |
|
69 |
H = h; |
|
70 |
grid = new Graticule(this); |
|
71 |
} |
|
63 | 72 |
|
64 |
public String getAbrev() { return abrev+Zone;} |
|
73 |
public String getAbrev() { |
|
74 |
return abrev + Zone; |
|
75 |
} |
|
65 | 76 |
|
66 |
public static UtmZone getProjection(Ellipsoid eli, int zone, int hemisphere) { |
|
67 |
if (eli == Ellipsoid.hayford && hemisphere == 0) { |
|
68 |
switch (zone) { |
|
69 |
case 28: return hayford28N; |
|
70 |
case 29: return hayford29N; |
|
71 |
case 30: return hayford30N; |
|
72 |
case 31: return hayford31N; |
|
73 |
} |
|
74 |
} else if (eli == Ellipsoid.ed50 && hemisphere == 0) { |
|
75 |
switch (zone) { |
|
76 |
case 28: return ed5028N; |
|
77 |
case 29: return ed5029N; |
|
78 |
case 30: return ed5030N; |
|
79 |
case 31: return ed5031N; |
|
80 |
} |
|
81 |
} |
|
82 |
System.err.println("UtmZone.getProjection(): new "+zone); |
|
83 |
return new UtmZone(eli, zone, hemisphere, 0.0); |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* |
|
88 |
*/ |
|
89 |
public static IProjection getProjectionByName(IDatum eli, String name) { |
|
90 |
int zone, hemisphere = NORTH; |
|
91 |
if (name.indexOf("UTM") < 0) |
|
92 |
return null; |
|
93 |
if (name.substring(0,1).compareTo("S")==0) |
|
94 |
hemisphere = SOUTH; |
|
95 |
zone = Integer.parseInt(name.substring(name.length()-2)); |
|
96 |
return getProjection((Ellipsoid) eli, zone, hemisphere); |
|
97 |
} |
|
77 |
public static UtmZone getProjection(Ellipsoid eli, int zone, int hemisphere) { |
|
78 |
if ((eli == Ellipsoid.hayford) && (hemisphere == 0)) { |
|
79 |
switch (zone) { |
|
80 |
case 28: |
|
81 |
return hayford28N; |
|
98 | 82 |
|
99 |
/** |
|
100 |
* |
|
101 |
*/ |
|
102 |
public Point2D createPoint(double x, double y){ |
|
103 |
return new UtmPoint(this, x, y); |
|
104 |
} |
|
83 |
case 29: |
|
84 |
return hayford29N; |
|
105 | 85 |
|
106 |
/** |
|
107 |
* |
|
108 |
* @param uPt |
|
109 |
* @return |
|
110 |
*/ |
|
111 |
public Point2D toGeo(Point2D uPt) { |
|
112 |
GeoPoint gPt = new GeoPoint(); |
|
113 |
return toGeo((UtmPoint) uPt, gPt); |
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* |
|
118 |
* @param uPt |
|
119 |
* @param gPt |
|
120 |
* @return |
|
121 |
*/ |
|
122 |
|
|
123 |
public GeoPoint toGeo(UtmPoint uPt, GeoPoint gPt) { |
|
124 |
int ai[] = new int[3]; |
|
125 |
double ad[] = new double[3]; |
|
126 |
ai[1] = ((UtmZone) uPt.proj).Zone; |
|
127 |
ai[2] = ((UtmZone) uPt.proj).Hemisphere; |
|
128 |
ad[1] = uPt.X; |
|
129 |
ad[2] = uPt.Y; |
|
130 |
|
|
131 |
utmgeo.set(((Projection) uPt.proj).getElliPar(), ai, ad); |
|
132 |
utmgeo.go(); |
|
86 |
case 30: |
|
87 |
return hayford30N; |
|
133 | 88 |
|
134 |
gPt.Longitude = Ra2De.go(utmgeo.Ge[1]); |
|
135 |
gPt.Latitude = Ra2De.go(utmgeo.Ge[2]); |
|
136 |
gPt.proj = Geodetic.getProjection(((Projection) uPt.proj).eli); |
|
137 |
return gPt; |
|
138 |
} |
|
89 |
case 31: |
|
90 |
return hayford31N; |
|
91 |
} |
|
92 |
} else if ((eli == Ellipsoid.ed50) && (hemisphere == 0)) { |
|
93 |
switch (zone) { |
|
94 |
case 28: |
|
95 |
return ed5028N; |
|
139 | 96 |
|
140 |
/** |
|
141 |
* |
|
142 |
* @param gPt |
|
143 |
* @param uPt |
|
144 |
* @return |
|
145 |
*/ |
|
146 |
public Point2D fromGeo(Point2D gPt, Point2D uPt) { |
|
147 |
int ai[] = { 0, 0, 2 }; |
|
148 |
return fromGeo((GeoPoint) gPt, (UtmPoint) uPt, ai); |
|
149 |
} |
|
97 |
case 29: |
|
98 |
return ed5029N; |
|
150 | 99 |
|
151 |
/** |
|
152 |
* |
|
153 |
* @param gPt |
|
154 |
* @param uPt |
|
155 |
* @param proj |
|
156 |
* @return |
|
157 |
*/ |
|
158 |
public UtmPoint fromGeo(GeoPoint gPt, UtmPoint uPt, UtmZone proj) { |
|
159 |
int ai[] = { 0, proj.Zone, proj.Hemisphere }; |
|
160 |
return fromGeo(gPt, uPt, ai); |
|
161 |
} |
|
100 |
case 30: |
|
101 |
return ed5030N; |
|
162 | 102 |
|
163 |
/** |
|
164 |
* |
|
165 |
* @param gPt |
|
166 |
* @param uPt |
|
167 |
* @param ai |
|
168 |
* @return |
|
169 |
*/ |
|
170 |
public UtmPoint fromGeo(GeoPoint gPt, UtmPoint uPt, int[] ai) { |
|
171 |
double ad[] = new double[4]; |
|
172 |
ad[1] = gPt.Longitude.ToRadians(); |
|
173 |
ad[2] = gPt.Latitude.ToRadians(); |
|
174 |
geoutm.set(((Projection) gPt.proj).getElliPar(), ai, ad); |
|
175 |
geoutm.go(); |
|
176 |
if(geoutm.Ier != 0) |
|
177 |
return null; |
|
178 |
uPt.setLocation(geoutm.Pr[1], geoutm.Pr[2]); |
|
179 |
if (((UtmZone) uPt.proj).Zone != geoutm.Iopar[1] || ((UtmZone) uPt.proj).Hemisphere != geoutm.Iopar[2]) { |
|
180 |
uPt.proj = UtmZone.getProjection(((Projection) uPt.proj).eli, geoutm.Iopar[1], geoutm.Iopar[2]); |
|
181 |
} |
|
182 |
return uPt; |
|
183 |
} |
|
184 |
|
|
185 |
// Calcula el step en funci?n del zoom |
|
186 |
private void generateGrid(Graphics2D g, Extent extent, AffineTransform mat) { |
|
187 |
// calculo del step en funci?n del zoom |
|
188 |
Point2D pt1 = extent.getMin(); |
|
103 |
case 31: |
|
104 |
return ed5031N; |
|
105 |
} |
|
106 |
} |
|
189 | 107 |
|
190 |
double step = 1.0, x = (int) pt1.getX(), dist = 0.0; |
|
191 |
/* GeoPoint gp1, gp2; |
|
192 |
gp1 = (GeoPoint) createPoint( x, (int) pt1.getY()); |
|
193 |
mat.transform(gp1, gp1); |
|
194 |
gp2 = (GeoPoint) createPoint(gp1.getX()+100, gp1.getY()-100); |
|
195 |
try { |
|
196 |
mat.inverseTransform(gp2, gp2); |
|
197 |
} catch (NoninvertibleTransformException e) { |
|
198 |
// TODO Auto-generated catch block |
|
199 |
e.printStackTrace(); |
|
200 |
} |
|
201 |
dist = (gp2.getX()-x); |
|
202 |
System.err.println("distX = " + dist); |
|
203 |
|
|
204 |
if (dist > 30.0) { step = 30.0; |
|
205 |
} else if (dist > 18.0) { step = 18.0; |
|
206 |
} else if (dist > 12.0) { step = 12.0; |
|
207 |
} else if (dist > 6.0) { step = 6.0; |
|
208 |
} else if (dist > 3.0) { step = 3.0; |
|
209 |
} else if (dist > 2.0) { step = 2.0; |
|
210 |
} else if (dist > 1.0) { step = 1.0; |
|
211 |
} else if (dist > .5) { step =.5; |
|
212 |
} else if (dist > .25) { step =.25; |
|
213 |
} else if (dist > 1.0/60*5.0) { step = 1.0/60*5.0; |
|
214 |
} else { step = 1.0/60*2.0; |
|
215 |
} |
|
216 |
//step = 1.0; |
|
217 |
*/ |
|
218 |
generateGrid(g, extent, mat, step); |
|
219 |
} |
|
220 |
private void generateGrid(Graphics2D g, Extent extent, AffineTransform mat, double step) { |
|
221 |
grid = new Graticule(this); |
|
222 |
Point2D pt1 = extent.getMin(), pt2 = extent.getMax(); |
|
223 |
GeoPoint gp1, gp2; |
|
224 |
UtmPoint up1 = (UtmPoint) createPoint(0,0), |
|
225 |
up2 = (UtmPoint) createPoint(0,0); |
|
226 |
Point2D.Double mp1 = new Point2D.Double(0.0, 0.0), |
|
227 |
mp2 = new Point2D.Double(0.0, 0.0); |
|
228 |
Geodetic geoProj = Geodetic.getProjection((Ellipsoid) getDatum()); |
|
229 |
boolean esUso = false; |
|
230 |
|
|
231 |
System.err.println(name+": ViewPort Extent = ("+pt1+","+pt2+")"); |
|
232 |
gp1 = (GeoPoint) toGeo(new UtmPoint(pt1.getX(), pt2.getY())); |
|
233 |
gp2 = (GeoPoint) toGeo(new UtmPoint(pt2)); |
|
234 |
double xMin = (int) gp1.getX() - 1.0; |
|
235 |
double xMax = (int) gp2.getX() + 1.0; |
|
236 |
gp1 = (GeoPoint) toGeo(new UtmPoint(pt1.getX()+(pt2.getX()-pt1.getX())/2.0, pt2.getY())); |
|
237 |
double yMax = (int) gp1.getY() + 2.0; |
|
238 |
gp1 = (GeoPoint) toGeo(new UtmPoint(pt1)); |
|
239 |
double yMin = (int) gp1.getY() - 1.0; |
|
240 |
xMin = -30.0; |
|
241 |
xMax = 30.0; |
|
242 |
yMin = 20.0; |
|
243 |
yMax = 60.0; |
|
244 |
for (double x=xMin; x<=xMax; x+=step) { |
|
245 |
up1 = null; |
|
246 |
if (Math.abs( (x) % 6) < .001 ) esUso = true; |
|
247 |
for (double y=yMin; y<=yMax; y+=step) { |
|
248 |
gp2 = (GeoPoint) geoProj.createPoint(x, y); |
|
249 |
fromGeo(gp2, up2, this); |
|
250 |
if (up1 != null && (extent.isAt(up1) || extent.isAt(up2))) { |
|
251 |
mat.transform(up2, mp2); |
|
252 |
if (up1 != null) { |
|
253 |
if (esUso) |
|
254 |
grid.addLine(mp1, mp2, 1); |
|
255 |
else |
|
256 |
grid.addLine(mp1, mp2); |
|
257 |
} |
|
258 |
} else |
|
259 |
mat.transform(up2, mp2); |
|
260 |
up1 = (UtmPoint) up2.clone(); |
|
261 |
mp1 = (Point2D.Double) mp2.clone(); |
|
262 |
} |
|
263 |
esUso = false; |
|
264 |
} |
|
108 |
System.err.println("UtmZone.getProjection(): new " + zone); |
|
265 | 109 |
|
266 |
for (double y=yMin; y<=yMax; y+=step) { |
|
267 |
up1 = null; |
|
268 |
for (double x=xMin; x<=xMax; x+=step) { |
|
269 |
gp2 = (GeoPoint) geoProj.createPoint(x, y); |
|
270 |
fromGeo(gp2, up2, this); |
|
271 |
if (up1 != null && (extent.isAt(up1) || extent.isAt(up2))) { |
|
272 |
mat.transform(up2, mp2); |
|
273 |
if (up1 != null) { |
|
274 |
grid.addLine(mp1, mp2); |
|
275 |
} |
|
276 |
} else |
|
277 |
mat.transform(up2, mp2); |
|
278 |
up1 = (UtmPoint) up2.clone(); |
|
279 |
mp1 = (Point2D.Double) mp2.clone(); |
|
280 |
} |
|
281 |
} |
|
282 |
} |
|
283 |
|
|
284 |
public void drawGrid(Graphics2D g, ViewPortData vp) { |
|
285 |
generateGrid(g, vp.getExtent(), vp.getMat()); |
|
286 |
grid.setColor(gridColor); |
|
287 |
grid.draw(g, vp); |
|
288 |
} |
|
110 |
return new UtmZone(eli, zone, hemisphere, 0.0); |
|
111 |
} |
|
289 | 112 |
|
290 |
/* (non-Javadoc) |
|
291 |
* @see org.cresques.cts.IProjection#getScale(double, double, double, double) |
|
292 |
*/ |
|
293 |
public double getScale(double minX, double maxX, double width, double dpi) { |
|
294 |
double scale = (maxX-minX)* // metros |
|
295 |
(dpi / 2.54 * 100.0)/ // px / metro |
|
296 |
width; // pixels |
|
297 |
return scale; |
|
298 |
} |
|
299 |
} |
|
113 |
/** |
|
114 |
* |
|
115 |
*/ |
|
116 |
public static IProjection getProjectionByName(IDatum eli, String name) { |
|
117 |
int zone; |
|
118 |
int hemisphere = NORTH; |
|
119 |
|
|
120 |
if (name.indexOf("UTM") < 0) { |
|
121 |
return null; |
|
122 |
} |
|
123 |
|
|
124 |
if (name.substring(0, 1).compareTo("S") == 0) { |
|
125 |
hemisphere = SOUTH; |
|
126 |
} |
|
127 |
|
|
128 |
zone = Integer.parseInt(name.substring(name.length() - 2)); |
|
129 |
|
|
130 |
return getProjection((Ellipsoid) eli, zone, hemisphere); |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* |
|
135 |
*/ |
|
136 |
public Point2D createPoint(double x, double y) { |
|
137 |
return new UtmPoint(this, x, y); |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* |
|
142 |
* @param uPt |
|
143 |
* @return |
|
144 |
*/ |
|
145 |
public Point2D toGeo(Point2D uPt) { |
|
146 |
GeoPoint gPt = new GeoPoint(); |
|
147 |
|
|
148 |
return toGeo((UtmPoint) uPt, gPt); |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* |
|
153 |
* @param uPt |
|
154 |
* @param gPt |
|
155 |
* @return |
|
156 |
*/ |
|
157 |
public GeoPoint toGeo(UtmPoint uPt, GeoPoint gPt) { |
|
158 |
int[] ai = new int[3]; |
|
159 |
double[] ad = new double[3]; |
|
160 |
ai[1] = ((UtmZone) uPt.proj).Zone; |
|
161 |
ai[2] = ((UtmZone) uPt.proj).Hemisphere; |
|
162 |
ad[1] = uPt.X; |
|
163 |
ad[2] = uPt.Y; |
|
164 |
|
|
165 |
utmgeo.set(((Projection) uPt.proj).getElliPar(), ai, ad); |
|
166 |
utmgeo.go(); |
|
167 |
|
|
168 |
gPt.Longitude = Ra2De.go(utmgeo.Ge[1]); |
|
169 |
gPt.Latitude = Ra2De.go(utmgeo.Ge[2]); |
|
170 |
gPt.proj = Geodetic.getProjection(((Projection) uPt.proj).eli); |
|
171 |
|
|
172 |
return gPt; |
|
173 |
} |
|
174 |
|
|
175 |
/** |
|
176 |
* |
|
177 |
* @param gPt |
|
178 |
* @param uPt |
|
179 |
* @return |
|
180 |
*/ |
|
181 |
public Point2D fromGeo(Point2D gPt, Point2D uPt) { |
|
182 |
int[] ai = { 0, 0, 2 }; |
|
183 |
|
|
184 |
return fromGeo((GeoPoint) gPt, (UtmPoint) uPt, ai); |
|
185 |
} |
|
186 |
|
|
187 |
/** |
|
188 |
* |
|
189 |
* @param gPt |
|
190 |
* @param uPt |
|
191 |
* @param proj |
|
192 |
* @return |
|
193 |
*/ |
|
194 |
public UtmPoint fromGeo(GeoPoint gPt, UtmPoint uPt, UtmZone proj) { |
|
195 |
int[] ai = { 0, proj.Zone, proj.Hemisphere }; |
|
196 |
|
|
197 |
return fromGeo(gPt, uPt, ai); |
|
198 |
} |
|
199 |
|
|
200 |
/** |
|
201 |
* |
|
202 |
* @param gPt |
|
203 |
* @param uPt |
|
204 |
* @param ai |
|
205 |
* @return |
|
206 |
*/ |
|
207 |
public UtmPoint fromGeo(GeoPoint gPt, UtmPoint uPt, int[] ai) { |
|
208 |
double[] ad = new double[4]; |
|
209 |
ad[1] = gPt.Longitude.ToRadians(); |
|
210 |
ad[2] = gPt.Latitude.ToRadians(); |
|
211 |
geoutm.set(((Projection) gPt.proj).getElliPar(), ai, ad); |
|
212 |
geoutm.go(); |
|
213 |
|
|
214 |
if (geoutm.Ier != 0) { |
|
215 |
return null; |
|
216 |
} |
|
217 |
|
|
218 |
uPt.setLocation(geoutm.Pr[1], geoutm.Pr[2]); |
|
219 |
|
|
220 |
if ((((UtmZone) uPt.proj).Zone != geoutm.Iopar[1]) || |
|
221 |
(((UtmZone) uPt.proj).Hemisphere != geoutm.Iopar[2])) { |
|
222 |
uPt.proj = UtmZone.getProjection(((Projection) uPt.proj).eli, |
|
223 |
geoutm.Iopar[1], geoutm.Iopar[2]); |
|
224 |
} |
|
225 |
|
|
226 |
return uPt; |
|
227 |
} |
|
228 |
|
|
229 |
// Calcula el step en funci?n del zoom |
|
230 |
private void generateGrid(Graphics2D g, Extent extent, AffineTransform mat) { |
|
231 |
// calculo del step en funci?n del zoom |
|
232 |
Point2D pt1 = extent.getMin(); |
|
233 |
|
|
234 |
double step = 1.0; |
|
235 |
double x = (int) pt1.getX(); |
|
236 |
double dist = 0.0; |
|
237 |
|
|
238 |
/* GeoPoint gp1, gp2; |
|
239 |
gp1 = (GeoPoint) createPoint( x, (int) pt1.getY()); |
|
240 |
mat.transform(gp1, gp1); |
|
241 |
gp2 = (GeoPoint) createPoint(gp1.getX()+100, gp1.getY()-100); |
|
242 |
try { |
|
243 |
mat.inverseTransform(gp2, gp2); |
|
244 |
} catch (NoninvertibleTransformException e) { |
|
245 |
// TODO Auto-generated catch block |
|
246 |
e.printStackTrace(); |
|
247 |
} |
|
248 |
dist = (gp2.getX()-x); |
|
249 |
System.err.println("distX = " + dist); |
|
250 |
|
|
251 |
if (dist > 30.0) { step = 30.0; |
|
252 |
} else if (dist > 18.0) { step = 18.0; |
|
253 |
} else if (dist > 12.0) { step = 12.0; |
|
254 |
} else if (dist > 6.0) { step = 6.0; |
|
255 |
} else if (dist > 3.0) { step = 3.0; |
|
256 |
} else if (dist > 2.0) { step = 2.0; |
|
257 |
} else if (dist > 1.0) { step = 1.0; |
|
258 |
} else if (dist > .5) { step =.5; |
|
259 |
} else if (dist > .25) { step =.25; |
|
260 |
} else if (dist > 1.0/60*5.0) { step = 1.0/60*5.0; |
|
261 |
} else { step = 1.0/60*2.0; |
|
262 |
} |
|
263 |
//step = 1.0; |
|
264 |
*/ |
|
265 |
generateGrid(g, extent, mat, step); |
|
266 |
} |
|
267 |
|
|
268 |
private void generateGrid(Graphics2D g, Extent extent, AffineTransform mat, |
|
269 |
double step) { |
|
270 |
grid = new Graticule(this); |
|
271 |
|
|
272 |
Point2D pt1 = extent.getMin(); |
|
273 |
Point2D pt2 = extent.getMax(); |
|
274 |
GeoPoint gp1; |
|
275 |
GeoPoint gp2; |
|
276 |
UtmPoint up1 = (UtmPoint) createPoint(0, 0); |
|
277 |
UtmPoint up2 = (UtmPoint) createPoint(0, 0); |
|
278 |
Point2D.Double mp1 = new Point2D.Double(0.0, 0.0); |
|
279 |
Point2D.Double mp2 = new Point2D.Double(0.0, 0.0); |
|
280 |
Geodetic geoProj = Geodetic.getProjection((Ellipsoid) getDatum()); |
|
281 |
boolean esUso = false; |
|
282 |
|
|
283 |
System.err.println(name + ": ViewPort Extent = (" + pt1 + "," + pt2 + |
|
284 |
")"); |
|
285 |
gp1 = (GeoPoint) toGeo(new UtmPoint(pt1.getX(), pt2.getY())); |
|
286 |
gp2 = (GeoPoint) toGeo(new UtmPoint(pt2)); |
|
287 |
|
|
288 |
double xMin = (int) gp1.getX() - 1.0; |
|
289 |
double xMax = (int) gp2.getX() + 1.0; |
|
290 |
gp1 = (GeoPoint) toGeo(new UtmPoint(pt1.getX() + |
|
291 |
((pt2.getX() - pt1.getX()) / 2.0), |
|
292 |
pt2.getY())); |
|
293 |
|
|
294 |
double yMax = (int) gp1.getY() + 2.0; |
|
295 |
gp1 = (GeoPoint) toGeo(new UtmPoint(pt1)); |
|
296 |
|
|
297 |
double yMin = (int) gp1.getY() - 1.0; |
|
298 |
xMin = -30.0; |
|
299 |
xMax = 30.0; |
|
300 |
yMin = 20.0; |
|
301 |
yMax = 60.0; |
|
302 |
|
|
303 |
for (double x = xMin; x <= xMax; x += step) { |
|
304 |
up1 = null; |
|
305 |
|
|
306 |
if (Math.abs((x) % 6) < .001) { |
|
307 |
esUso = true; |
|
308 |
} |
|
309 |
|
|
310 |
for (double y = yMin; y <= yMax; y += step) { |
|
311 |
gp2 = (GeoPoint) geoProj.createPoint(x, y); |
|
312 |
fromGeo(gp2, up2, this); |
|
313 |
|
|
314 |
if ((up1 != null) && (extent.isAt(up1) || extent.isAt(up2))) { |
|
315 |
mat.transform(up2, mp2); |
|
316 |
|
|
317 |
if (up1 != null) { |
|
318 |
if (esUso) { |
|
319 |
grid.addLine(mp1, mp2, 1); |
|
320 |
} else { |
|
321 |
grid.addLine(mp1, mp2); |
|
322 |
} |
|
323 |
} |
|
324 |
} else { |
|
325 |
mat.transform(up2, mp2); |
|
326 |
} |
|
327 |
|
|
328 |
up1 = (UtmPoint) up2.clone(); |
|
329 |
mp1 = (Point2D.Double) mp2.clone(); |
|
330 |
} |
|
331 |
|
|
332 |
esUso = false; |
|
333 |
} |
|
334 |
|
|
335 |
for (double y = yMin; y <= yMax; y += step) { |
|
336 |
up1 = null; |
|
337 |
|
|
338 |
for (double x = xMin; x <= xMax; x += step) { |
|
339 |
gp2 = (GeoPoint) geoProj.createPoint(x, y); |
|
340 |
fromGeo(gp2, up2, this); |
|
341 |
|
|
342 |
if ((up1 != null) && (extent.isAt(up1) || extent.isAt(up2))) { |
|
343 |
mat.transform(up2, mp2); |
|
344 |
|
|
345 |
if (up1 != null) { |
|
346 |
grid.addLine(mp1, mp2); |
|
347 |
} |
|
348 |
} else { |
|
349 |
mat.transform(up2, mp2); |
|
350 |
} |
|
351 |
|
|
352 |
up1 = (UtmPoint) up2.clone(); |
|
353 |
mp1 = (Point2D.Double) mp2.clone(); |
|
354 |
} |
|
355 |
} |
|
356 |
} |
|
357 |
|
|
358 |
public void drawGrid(Graphics2D g, ViewPortData vp) { |
|
359 |
generateGrid(g, vp.getExtent(), vp.getMat()); |
|
360 |
grid.setColor(gridColor); |
|
361 |
grid.draw(g, vp); |
|
362 |
} |
|
363 |
|
|
364 |
/* (non-Javadoc) |
|
365 |
* @see org.cresques.cts.IProjection#getScale(double, double, double, double) |
|
366 |
*/ |
|
367 |
public double getScale(double minX, double maxX, double width, double dpi) { |
|
368 |
double scale = ((maxX - minX) * // metros |
|
369 |
(dpi / 2.54 * 100.0)) / // px / metro |
|
370 |
width; // pixels |
|
371 |
|
|
372 |
return scale; |
|
373 |
} |
|
374 |
} |
Also available in: Unified diff