53 |
53 |
import org.geotools.referencing.crs.AbstractDerivedCRS;
|
54 |
54 |
import org.geotools.referencing.crs.AbstractSingleCRS;
|
55 |
55 |
import org.geotools.referencing.datum.DefaultGeodeticDatum;
|
|
56 |
import org.gvsig.crs.proj.CrsProj;
|
|
57 |
import org.gvsig.crs.proj.CrsProjException;
|
|
58 |
import org.gvsig.crs.proj.JNIBaseCrs;
|
|
59 |
import org.gvsig.crs.proj.OperationCrsException;
|
56 |
60 |
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
57 |
61 |
|
58 |
62 |
/**
|
... | ... | |
62 |
66 |
*
|
63 |
67 |
*/
|
64 |
68 |
public class CrsGT implements ICrs {
|
|
69 |
private static final Color basicGridColor = new Color(64, 64, 64, 128);
|
65 |
70 |
|
66 |
|
CoordinateReferenceSystem crsGT;
|
|
71 |
private CoordinateReferenceSystem crsGT = null;
|
|
72 |
private boolean targetNad = false;
|
|
73 |
private String proj4 = null;
|
|
74 |
private Color gridColor = basicGridColor;
|
|
75 |
private String nad = null;
|
67 |
76 |
|
68 |
77 |
/**
|
69 |
78 |
* Constructor a partir de un CoordinateReferenceSystem
|
... | ... | |
75 |
84 |
}
|
76 |
85 |
|
77 |
86 |
public int getCode() {
|
78 |
|
// TODO Auto-generated method stub
|
79 |
|
return 0;
|
|
87 |
return Integer.valueOf(getAbrev().split(":")[1]).intValue();
|
80 |
88 |
}
|
81 |
89 |
|
82 |
90 |
public CrsWkt getCrsWkt() {
|
... | ... | |
90 |
98 |
}
|
91 |
99 |
|
92 |
100 |
public void setNadGrid(String nad) {
|
93 |
|
// TODO Auto-generated method stub
|
|
101 |
this.nad = nad;
|
94 |
102 |
|
95 |
103 |
}
|
96 |
104 |
|
... | ... | |
121 |
129 |
}
|
122 |
130 |
|
123 |
131 |
public ICoordTrans getCT(IProjection dest) {
|
124 |
|
// TODO Auto-generated method stub
|
125 |
|
return null;
|
|
132 |
COperation operation = null;
|
|
133 |
CrsGT crsDest = (CrsGT)dest;
|
|
134 |
try {
|
|
135 |
operation = new COperation(this, (ICrs)dest);
|
|
136 |
} catch (CrsException e) {
|
|
137 |
// TODO Auto-generated catch block
|
|
138 |
e.printStackTrace();
|
|
139 |
}
|
|
140 |
|
|
141 |
if (!getNadGrid().equals("")){
|
|
142 |
if (isTargetNad())
|
|
143 |
operation.setNadCrsProj(new CrsProj(crsDest.getProj4()+getNadGrid()), true);
|
|
144 |
else
|
|
145 |
operation.setNadCrsProj(new CrsProj(getProj4()+getNadGrid()), false);
|
|
146 |
|
|
147 |
return operation;
|
|
148 |
}
|
|
149 |
|
|
150 |
return operation;
|
126 |
151 |
}
|
127 |
152 |
|
128 |
153 |
public IDatum getDatum() {
|
... | ... | |
138 |
163 |
}
|
139 |
164 |
|
140 |
165 |
public Color getGridColor() {
|
141 |
|
// TODO Auto-generated method stub
|
142 |
|
return null;
|
|
166 |
return gridColor;
|
143 |
167 |
}
|
144 |
168 |
|
145 |
169 |
public double getScale(double minX, double maxX, double width, double dpi) {
|
146 |
|
// TODO Auto-generated method stub
|
147 |
|
return 0;
|
|
170 |
double scale = 0D;
|
|
171 |
if (!isProjected()) { // Es geogr?fico; calcula la escala.
|
|
172 |
scale = ((maxX - minX) * // grados
|
|
173 |
|
|
174 |
// 1852.0 metros x minuto de meridiano
|
|
175 |
(dpi / 2.54 * 100.0 * 1852.0 * 60.0)) / // px / metro
|
|
176 |
width; // pixels
|
|
177 |
}
|
|
178 |
else{
|
|
179 |
scale = ((maxX - minX) * // metros
|
|
180 |
(dpi / 2.54 * 100.0)) / // px / metro
|
|
181 |
width; // pixels
|
|
182 |
}
|
|
183 |
return scale;
|
148 |
184 |
}
|
149 |
185 |
|
150 |
186 |
public boolean isProjected() {
|
... | ... | |
155 |
191 |
}
|
156 |
192 |
|
157 |
193 |
public void setGridColor(Color c) {
|
158 |
|
// TODO Auto-generated method stub
|
159 |
|
|
|
194 |
gridColor = c;
|
160 |
195 |
}
|
161 |
196 |
|
162 |
197 |
public Point2D toGeo(Point2D pt) {
|
163 |
|
// TODO Auto-generated method stub
|
164 |
|
return null;
|
|
198 |
if (isProjected()){
|
|
199 |
double x[] = {pt.getX()};
|
|
200 |
double y[] = {pt.getY()};
|
|
201 |
double z[] = {0D};
|
|
202 |
try {
|
|
203 |
JNIBaseCrs.operate( x , y, z,
|
|
204 |
crsProj4,crsBase);
|
|
205 |
} catch (OperationCrsException e) {
|
|
206 |
// TODO Auto-generated catch block
|
|
207 |
e.printStackTrace();
|
|
208 |
} catch (CrsProjException e) {
|
|
209 |
// TODO Auto-generated catch block
|
|
210 |
e.printStackTrace();
|
|
211 |
}
|
|
212 |
return new Point2D.Double(x[0],y[0]);
|
|
213 |
}
|
|
214 |
else
|
|
215 |
return pt;
|
165 |
216 |
}
|
166 |
217 |
|
|
218 |
public String getNadGrid() {
|
|
219 |
return nad;
|
|
220 |
}
|
|
221 |
|
|
222 |
/**
|
|
223 |
* @return
|
|
224 |
*/
|
|
225 |
public boolean isTargetNad() {
|
|
226 |
return targetNad;
|
|
227 |
}
|
|
228 |
|
|
229 |
/**
|
|
230 |
*
|
|
231 |
* @return
|
|
232 |
*/
|
|
233 |
public String getProj4() {
|
|
234 |
return proj4;
|
|
235 |
}
|
|
236 |
|
|
237 |
public CoordinateReferenceSystem getCrsGT() {
|
|
238 |
return crsGT;
|
|
239 |
}
|
|
240 |
|
167 |
241 |
}
|