svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.projection / org.gvsig.projection.cresques / org.gvsig.projection.cresques.impl / src / main / java / org / cresques / impl / geo / Projection.java @ 42464
History | View | Annotate | Download (4.7 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.cresques.impl.geo; |
25 |
|
26 |
import org.cresques.cts.IDatum; |
27 |
import org.cresques.cts.IProjection; |
28 |
import org.cresques.geo.ViewPortData; |
29 |
|
30 |
import org.gvsig.fmap.crs.CRSFactory; |
31 |
|
32 |
import java.awt.Color; |
33 |
import java.awt.Graphics2D; |
34 |
import java.awt.geom.Point2D; |
35 |
|
36 |
|
37 |
abstract public class Projection implements IProjection { |
38 |
public static int NORTH = 0; |
39 |
public static int SOUTH = 1; |
40 |
static String name = "Sin Proyeccion"; |
41 |
static String abrev = "None"; |
42 |
private static final Color basicGridColor = new Color(64, 64, 64, 128); |
43 |
Color gridColor = basicGridColor;
|
44 |
Ellipsoid eli = Ellipsoid.hayford; |
45 |
Graticule grid; |
46 |
|
47 |
public Projection() {
|
48 |
eli = Ellipsoid.hayford; |
49 |
} |
50 |
|
51 |
public Projection(Ellipsoid e) {
|
52 |
eli = e; |
53 |
} |
54 |
|
55 |
public String getName() { |
56 |
return name;
|
57 |
} |
58 |
|
59 |
abstract public String getAbrev(); |
60 |
|
61 |
public IDatum getDatum() {
|
62 |
return eli;
|
63 |
} |
64 |
|
65 |
public double[] getElliPar() { |
66 |
return eli.getParam();
|
67 |
} |
68 |
|
69 |
abstract public Point2D createPoint(double x, double y); |
70 |
|
71 |
public Point2D createPoint(Point2D pt) { |
72 |
return createPoint(pt.getX(), pt.getY());
|
73 |
} |
74 |
|
75 |
public static IProjection getProjectionByName(IDatum eli, String name) { |
76 |
if (name.indexOf("UTM") >= 0) { |
77 |
return UtmZone.getProjectionByName(eli, name);
|
78 |
} |
79 |
|
80 |
if (name.indexOf("GEO") >= 0) { |
81 |
return Geodetic.getProjectionByName(eli, name);
|
82 |
} |
83 |
|
84 |
if (name.indexOf("MERC") >= 0) { |
85 |
return Mercator.getProjectionByName(eli, name);
|
86 |
} |
87 |
|
88 |
return null; |
89 |
} |
90 |
|
91 |
public ReProjection getReproyectionTo(Projection proj) {
|
92 |
ReProjection rp = new ReProjection(this, proj); |
93 |
|
94 |
return rp;
|
95 |
} |
96 |
|
97 |
abstract public Point2D toGeo(Point2D pt); |
98 |
|
99 |
abstract public Point2D fromGeo(Point2D gPt, Point2D mPt); |
100 |
|
101 |
public void setGridColor(Color c) { |
102 |
gridColor = c; |
103 |
} |
104 |
|
105 |
public Color getGridColor() { |
106 |
return gridColor;
|
107 |
} |
108 |
|
109 |
public static String coordToString(double coord, String fmt, boolean isLat) { |
110 |
String txt = fmt;
|
111 |
int donde;
|
112 |
donde = txt.indexOf("%G");
|
113 |
|
114 |
if (donde >= 0) { |
115 |
int deg = (int) coord; |
116 |
|
117 |
if ((fmt.indexOf("%N") >= 0) && (deg < 0)) { |
118 |
deg = -deg; |
119 |
} |
120 |
|
121 |
txt = txt.substring(0, donde) + Integer.toString(deg) + |
122 |
txt.substring(donde + 2);
|
123 |
} |
124 |
|
125 |
donde = txt.indexOf("%M");
|
126 |
|
127 |
if (donde >= 0) { |
128 |
int min = (int) ((coord - (int) coord) * 60.0) % 60; |
129 |
|
130 |
if ((fmt.indexOf("%N") >= 0) && (min < 0)) { |
131 |
min = -min; |
132 |
} |
133 |
|
134 |
txt = txt.substring(0, donde) + Integer.toString(min) + |
135 |
txt.substring(donde + 2);
|
136 |
; |
137 |
} |
138 |
|
139 |
donde = txt.indexOf("%N");
|
140 |
|
141 |
if (donde >= 0) { |
142 |
String t = ""; |
143 |
|
144 |
if (isLat) {
|
145 |
if (coord > 0) { |
146 |
t = "N";
|
147 |
} else if (coord < 0) { |
148 |
t = "S";
|
149 |
} |
150 |
} else {
|
151 |
if (coord > 0) { |
152 |
t = "E";
|
153 |
} else if (coord < 0) { |
154 |
t = "W";
|
155 |
} |
156 |
} |
157 |
|
158 |
txt = txt.substring(0, donde) + t + txt.substring(donde + 2); |
159 |
; |
160 |
} |
161 |
|
162 |
return txt;
|
163 |
} |
164 |
|
165 |
abstract public void drawGrid(Graphics2D g, ViewPortData vp); |
166 |
|
167 |
public boolean isProjected() { |
168 |
return false; |
169 |
} |
170 |
|
171 |
public Object clone() throws CloneNotSupportedException { |
172 |
return CRSFactory.getCRS( this.getFullCode() ); |
173 |
} |
174 |
|
175 |
/* (non-Javadoc)
|
176 |
* @see org.cresques.cts.IProjection#export(java.lang.String)
|
177 |
*/
|
178 |
@Override
|
179 |
public String export(String format) { |
180 |
// TODO Auto-generated method stub
|
181 |
return null; |
182 |
} |
183 |
} |