1 |
| package photospace.space; |
2 |
| |
3 |
| import java.awt.*; |
4 |
| import geotransform.coords.*; |
5 |
| import geotransform.transforms.*; |
6 |
| import geotransform.ellipsoids.*; |
7 |
| |
8 |
| |
9 |
| public class Calculator |
10 |
| implements java.io.Serializable |
11 |
| { |
12 |
| static |
13 |
| { |
14 |
1
| Gdc_To_Utm_Converter.Init(new WE_Ellipsoid());
|
15 |
| } |
16 |
| |
17 |
2
| public static UTMPoint[] toUTMPoint(Position[] positions)
|
18 |
| { |
19 |
2
| UTMPoint[] points = new UTMPoint[positions.length];
|
20 |
2
| for (int i = 0; i < positions.length; i++)
|
21 |
| { |
22 |
2
| points[i] = toUTMPoint(positions[i]);
|
23 |
| } |
24 |
2
| return points;
|
25 |
| } |
26 |
| |
27 |
| |
28 |
2
| public static UTMPoint toUTMPoint(Position position)
|
29 |
| { |
30 |
2
| Gdc_Coord_3d gdc_point = new Gdc_Coord_3d(position.getLatitude().doubleValue(),
|
31 |
| position.getLongitude().doubleValue(), 0); |
32 |
2
| Utm_Coord_3d utm_point = new Utm_Coord_3d();
|
33 |
| |
34 |
2
| Gdc_To_Utm_Converter.Convert(gdc_point,utm_point);
|
35 |
| |
36 |
2
| return new UTMPoint((int) utm_point.x, (int) utm_point.y, utm_point.zone, utm_point.hemisphere_north);
|
37 |
| } |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
1
| public static UTMPoint[] getBounds(UTMPoint[] points, Dimension size, int metersPerPixel)
|
45 |
| { |
46 |
1
| int x = 0, y = 0;
|
47 |
1
| for (int i = 0; i < points.length; i++)
|
48 |
| { |
49 |
1
| x += points[i].getX();
|
50 |
1
| y += points[i].getY();
|
51 |
| } |
52 |
1
| UTMPoint point = new UTMPoint(x/points.length, y/points.length, points[0].getZone(), points[0].isNorth());
|
53 |
1
| UTMPoint min = new UTMPoint(point.getX() - (size.width / 2 * metersPerPixel),
|
54 |
| point.getY() - (size.height / 2 * metersPerPixel), |
55 |
| point.getZone(), point.isNorth()); |
56 |
1
| UTMPoint max = new UTMPoint(point.getX() + (size.width / 2 * metersPerPixel),
|
57 |
| point.getY() + (size.height / 2 * metersPerPixel), |
58 |
| point.getZone(), point.isNorth()); |
59 |
1
| return new UTMPoint[] { min, max };
|
60 |
| } |
61 |
| |
62 |
0
| public static String createTerraServerUrl(UTMPoint[] bounds, Dimension size)
|
63 |
| { |
64 |
0
| String url = "http://terraserver.microsoft.com/ogcmap.ashx?version=1.1.1&request=GetMap&format=image/jpeg&Exceptions=se_xml&Layers=UrbanArea&Styles=&"
|
65 |
| + "SRS=EPSG:269" + bounds[0].getZone() |
66 |
| + "&BBOX=" + bounds[0].getX() + "," + bounds[0].getY() + "," + bounds[1].getX() + "," + bounds[1].getY() |
67 |
| + "&width=" + size.width + "&height=" + size.height; |
68 |
0
| return url;
|
69 |
| } |
70 |
| |
71 |
0
| public static void main(String args[])
|
72 |
| { |
73 |
0
| Position chinaCamp = new Position(new Double(37.997532), new Double(-122.502327), null);
|
74 |
0
| UTMPoint[] points = Calculator.toUTMPoint(new Position[] { chinaCamp });
|
75 |
0
| System.out.println(chinaCamp + " = " + points[0]);
|
76 |
0
| UTMPoint[] bounds = Calculator.getBounds(points, new Dimension(800,600), 4);
|
77 |
0
| System.out.println(Calculator.createTerraServerUrl(bounds, new Dimension(800,600)));
|
78 |
| } |
79 |
| } |