root / branches / v02_desarrollo / libraries / libCq CMS for java.old / src / org / cresques / geo / Projection.java @ 988
History | View | Annotate | Download (2.52 KB)
1 |
package org.cresques.geo; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Graphics2D; |
5 |
import java.awt.geom.Point2D; |
6 |
|
7 |
import org.cresques.cts.IDatum; |
8 |
import org.cresques.cts.IProjection; |
9 |
|
10 |
abstract public class Projection implements IProjection { |
11 |
public static int NORTH = 0; |
12 |
public static int SOUTH = 1; |
13 |
static String name = "Sin Proyeccion"; |
14 |
static String abrev = "None"; |
15 |
private static final Color basicGridColor = new Color(64,64,64,128); |
16 |
Color gridColor = basicGridColor;
|
17 |
|
18 |
Ellipsoid eli = Ellipsoid.hayford; |
19 |
Graticule grid; |
20 |
|
21 |
public Projection() {
|
22 |
eli = Ellipsoid.hayford; |
23 |
} |
24 |
|
25 |
public Projection(Ellipsoid e) {
|
26 |
eli = e; |
27 |
} |
28 |
|
29 |
public String getName() { return name; } |
30 |
abstract public String getAbrev(); |
31 |
public IDatum getDatum() { return eli; } |
32 |
|
33 |
public double [] getElliPar() { return eli.getParam(); } |
34 |
|
35 |
abstract public Point2D createPoint(double x, double y); |
36 |
public Point2D createPoint(Point2D pt) { |
37 |
return createPoint(pt.getX(), pt.getY());
|
38 |
} |
39 |
|
40 |
public static IProjection getProjectionByName(IDatum eli, String name) { |
41 |
if (name.indexOf("UTM") >= 0) |
42 |
return UtmZone.getProjectionByName(eli, name);
|
43 |
if (name.indexOf("GEO") >= 0) |
44 |
return Geodetic.getProjectionByName(eli, name);
|
45 |
if (name.indexOf("MERC") >= 0) |
46 |
return Mercator.getProjectionByName(eli, name);
|
47 |
return null; |
48 |
} |
49 |
|
50 |
public ReProjection getReproyectionTo(Projection proj) {
|
51 |
ReProjection rp = new ReProjection(this, proj); |
52 |
return rp;
|
53 |
} |
54 |
|
55 |
abstract public Point2D toGeo(Point2D pt); |
56 |
abstract public Point2D fromGeo(Point2D gPt, Point2D mPt); |
57 |
|
58 |
public void setGridColor(Color c) { gridColor = c;} |
59 |
public Color getGridColor() { return gridColor; } |
60 |
|
61 |
public static String coordToString(double coord, String fmt, boolean isLat) { |
62 |
String txt = fmt;
|
63 |
int donde;
|
64 |
donde = txt.indexOf("%G");
|
65 |
if (donde >= 0) { |
66 |
int deg = (int) coord; |
67 |
if (fmt.indexOf("%N") >= 0 && deg < 0) deg = -deg; |
68 |
txt = txt.substring(0, donde)+Integer.toString(deg)+txt.substring(donde+2); |
69 |
} |
70 |
donde = txt.indexOf("%M");
|
71 |
if (donde >= 0) { |
72 |
int min = (int) ((coord - (int)coord)*60.0) % 60; |
73 |
if (fmt.indexOf("%N") >= 0 && min < 0) min = -min; |
74 |
txt = txt.substring(0, donde)+Integer.toString(min)+txt.substring(donde+2);; |
75 |
} |
76 |
donde = txt.indexOf("%N");
|
77 |
if (donde >= 0) { |
78 |
String t = ""; |
79 |
if (isLat) {
|
80 |
if (coord > 0) t = "N"; |
81 |
else if (coord < 0) t = "S"; |
82 |
} else {
|
83 |
if (coord > 0) t = "E"; |
84 |
else if (coord < 0) t = "W"; |
85 |
} |
86 |
txt = txt.substring(0, donde)+t+txt.substring(donde+2);; |
87 |
} |
88 |
return txt;
|
89 |
} |
90 |
|
91 |
abstract public void drawGrid(Graphics2D g, ViewPortData vp); |
92 |
} |