root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / fmap / layers / FLyrPoints.java @ 5491
History | View | Annotate | Download (32.3 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package com.iver.cit.gvsig.fmap.layers; |
20 |
|
21 |
import java.awt.Color; |
22 |
import java.awt.Dimension; |
23 |
import java.awt.Graphics2D; |
24 |
import java.awt.geom.Point2D; |
25 |
import java.awt.geom.Rectangle2D; |
26 |
import java.awt.image.BufferedImage; |
27 |
import java.util.ArrayList; |
28 |
import java.util.Iterator; |
29 |
|
30 |
import org.cresques.cts.ProjectionPool; |
31 |
import org.gvsig.georeferencing.utils.GeoPointPersistence; |
32 |
import org.gvsig.georeferencing.utils.PointManager; |
33 |
|
34 |
import com.iver.andami.PluginServices; |
35 |
import com.iver.cit.gvsig.fmap.DriverException; |
36 |
import com.iver.cit.gvsig.fmap.ViewPort; |
37 |
import com.iver.cit.gvsig.gui.View; |
38 |
import com.iver.utiles.XMLEntity; |
39 |
import com.iver.utiles.swing.threads.Cancellable; |
40 |
|
41 |
|
42 |
/**
|
43 |
* Clase de capa de marcado de puntos sobre una vista. Dibuja un puntero sobre
|
44 |
* cada punto en la vista. Esta capa hereda de GraphicLayer que es una capa que est?
|
45 |
* metida de forma fija en FMap. Con esto conseguimos que nuestra capa de puntos
|
46 |
* no aparezca en el TOC y siempre se dibuje por encima de todas las capas. Tiene
|
47 |
* el inconveniente de que est? en FMap y si hacemos un dibujado de las capas
|
48 |
* sobre un panel que no sea la vista de gvSIG este GraphicLayer no aparece.
|
49 |
* Si queremos hacer este tipo de dibujados tendremos que dibujar todas las capas
|
50 |
* con el draw de FLayers y al final llamar al draw de FLyrPoints.
|
51 |
*
|
52 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
53 |
*/
|
54 |
public class FLyrPoints extends GraphicLayer { |
55 |
|
56 |
//**********************Params********************************
|
57 |
/**
|
58 |
* Diametro del centro de la cruz
|
59 |
*/
|
60 |
private final int DIAM_CIRCLE = 18; |
61 |
/**
|
62 |
* ?ltima herramienta seleccionada. Despu?s de marcar el segundo punto en la vista ser? la
|
63 |
* herramienta por defecto.
|
64 |
*/
|
65 |
private String lastTool = "zoomIn"; |
66 |
//**********************End Params****************************
|
67 |
|
68 |
//**********************Vars**********************************
|
69 |
private ArrayList pointList = new ArrayList(); |
70 |
private boolean showNumber = true; |
71 |
private FLyrPointsState state = null; |
72 |
private IPersistence geoPointPersistence = null; |
73 |
private FLyrGeoRaster lyrGeoRaster = null; |
74 |
public static boolean isDrawing = false; |
75 |
private PointManager pointManager = null; |
76 |
private boolean lyrVisible = true; |
77 |
private Point2D[] transformPointList = null; |
78 |
private boolean withoutBlue = false; |
79 |
private boolean withoutRed = false; |
80 |
//**********************End Vars**********************************
|
81 |
|
82 |
//**********************Classes***********************************
|
83 |
/**
|
84 |
* Estado de la capa de puntos.
|
85 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
86 |
*/
|
87 |
public class FLyrPointsState{ |
88 |
public ArrayList pointList = new ArrayList(); |
89 |
public boolean showNumber = true; |
90 |
public String lastTool = "zoomIn"; |
91 |
} |
92 |
//**********************End Classes*******************************
|
93 |
|
94 |
//**********************Methods***********************************
|
95 |
/**
|
96 |
* Constructor
|
97 |
* @param flyGeoRaster
|
98 |
*/
|
99 |
public FLyrPoints(FLyrGeoRaster lyGeoRaster, IPersistence persistence){
|
100 |
this.lyrGeoRaster = lyGeoRaster;
|
101 |
geoPointPersistence = persistence; |
102 |
} |
103 |
|
104 |
/**
|
105 |
* Salva el estado actual de la capa de puntos. Podr? ser recuperado
|
106 |
* este ?ltimo estado salvado con la funci?n recoveryState
|
107 |
*
|
108 |
*/
|
109 |
public void saveState(){ |
110 |
if(state == null) |
111 |
state = new FLyrPointsState();
|
112 |
else
|
113 |
state.pointList.clear(); |
114 |
|
115 |
for(int i=0;i<this.length();i++) |
116 |
state.pointList.add(((GeoPoint)pointList.get(i)).cloneGeoPoint()); |
117 |
|
118 |
state.showNumber = showNumber; |
119 |
state.lastTool = lastTool; |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Recupera el estado de la capa de puntos desde la ?ltima vez que se
|
124 |
* ejecut? la funci?n saveState. Si no hay ning?n estdo salvado es que
|
125 |
* al principio estaba la capa vacia por lo que reiniciamos la capa de puntos.
|
126 |
*/
|
127 |
public void recoveryState(){ |
128 |
if(state != null){ |
129 |
pointList.clear(); |
130 |
for(int i=0;i<state.pointList.size();i++) |
131 |
pointList.add(((GeoPoint)state.pointList.get(i)).cloneGeoPoint()); |
132 |
|
133 |
showNumber = state.showNumber; |
134 |
lastTool = state.lastTool; |
135 |
} |
136 |
} |
137 |
|
138 |
/**
|
139 |
* Asigna el array de puntos
|
140 |
* @param list
|
141 |
*/
|
142 |
public void setListPoint(ArrayList list){ |
143 |
pointList = list; |
144 |
} |
145 |
|
146 |
/**
|
147 |
* Dibujado de la capa de raster georeferenciado aplicando la
|
148 |
* transformaci?n del viewPort.
|
149 |
*/
|
150 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp, |
151 |
Cancellable cancel,double scale) throws DriverException { |
152 |
|
153 |
Point2D pto = null; |
154 |
|
155 |
if(lyrVisible && lyrGeoRaster != null){ |
156 |
//vp = lyrGeoRaster.toImageCoord(vp);
|
157 |
synchronized (this) { |
158 |
for(int i=0; i<pointList.size();i++){ |
159 |
//Punto de la imagen
|
160 |
if(((GeoPoint)pointList.get(i)).active){
|
161 |
pto = ((GeoPoint)pointList.get(i)).pixelPoint; |
162 |
if(pto != null){ |
163 |
Point2D p = lyrGeoRaster.img2World(pto);
|
164 |
p = vp.fromMapPoint(p); |
165 |
drawPixelCrux(g, p, i); |
166 |
} |
167 |
|
168 |
//Punto de la vista
|
169 |
pto = ((GeoPoint)pointList.get(i)).mapPoint; |
170 |
if(pto != null){ |
171 |
Point2D p = null; |
172 |
p = vp.fromMapPoint(pto); |
173 |
drawMapCrux(g, p, i); |
174 |
} |
175 |
} |
176 |
} |
177 |
} |
178 |
} |
179 |
} |
180 |
|
181 |
/**
|
182 |
* Dibuja el gr?fico que corresponde a los puntos de coordenadas relativas a la imagen de origen
|
183 |
* @param g Graphics sobre el que se dibuja
|
184 |
* @param vp Viewport
|
185 |
* @param cancel
|
186 |
*/
|
187 |
public void drawPixelCrux(Graphics2D g, ViewPort vp, Cancellable cancel){ |
188 |
Point2D pto = null; |
189 |
if(lyrVisible && lyrGeoRaster != null){ |
190 |
for(int i=0; i<pointList.size();i++){ |
191 |
if(((GeoPoint)pointList.get(i)).active){
|
192 |
pto = ((GeoPoint)pointList.get(i)).pixelPoint; |
193 |
if(pto != null){ |
194 |
Point2D p = lyrGeoRaster.img2World(pto);
|
195 |
p = vp.fromMapPoint(p); |
196 |
drawPixelCrux(g, p, i); |
197 |
} |
198 |
} |
199 |
} |
200 |
} |
201 |
} |
202 |
|
203 |
/**
|
204 |
* Dibuja el gr?fico que corresponde a los puntos de coordenadas de mundo real.
|
205 |
* @param g Graphics sobre el que se dibuja
|
206 |
* @param vp Viewport
|
207 |
* @param cancel
|
208 |
*/
|
209 |
public void drawMapCrux(Graphics2D g, ViewPort vp, Cancellable cancel){ |
210 |
Point2D pto = null; |
211 |
if(lyrVisible && lyrGeoRaster != null){ |
212 |
for(int i=0; i<pointList.size();i++){ |
213 |
if(((GeoPoint)pointList.get(i)).active){
|
214 |
pto = ((GeoPoint)pointList.get(i)).mapPoint; |
215 |
if(pto != null){ |
216 |
Point2D p = null; |
217 |
p = vp.fromMapPoint(pto); |
218 |
drawMapCrux(g, p, i); |
219 |
} |
220 |
} |
221 |
} |
222 |
} |
223 |
} |
224 |
|
225 |
/**
|
226 |
* Dibuja sobre el graphics pasado la cruz del punto que marca
|
227 |
* el pixel de la imagen.
|
228 |
* @param g Graphics
|
229 |
*/
|
230 |
private void drawPixelCrux(Graphics2D g, Point2D p, int pointNumber){ |
231 |
int dpto = (DIAM_CIRCLE >> 1); |
232 |
int incr = 5; |
233 |
g.setColor(Color.WHITE);
|
234 |
g.drawOval( (int)p.getX() - dpto + 1, |
235 |
(int)p.getY() - dpto + 1, |
236 |
DIAM_CIRCLE - 2,
|
237 |
DIAM_CIRCLE - 2);
|
238 |
g.drawLine((int)p.getX() - incr, (int)p.getY() - 1, (int)p.getX() - 1, (int)p.getY() - 1); |
239 |
g.drawLine((int)p.getX() - incr, (int)p.getY() + 1, (int)p.getX() - 1, (int)p.getY() + 1); |
240 |
|
241 |
g.drawLine((int)p.getX() + incr, (int)p.getY() - 1, (int)p.getX() + 1, (int)p.getY() - 1); |
242 |
g.drawLine((int)p.getX() + incr, (int)p.getY() + 1, (int)p.getX() + 1, (int)p.getY() + 1); |
243 |
|
244 |
g.drawLine((int)p.getX() - 1, (int)p.getY() - incr, (int)p.getX() - 1, (int)p.getY() - 1); |
245 |
g.drawLine((int)p.getX() + 1, (int)p.getY() - incr, (int)p.getX() + 1, (int)p.getY() - 1); |
246 |
|
247 |
g.drawLine((int)p.getX() - 1, (int)p.getY() + incr, (int)p.getX() - 1, (int)p.getY() + 1); |
248 |
g.drawLine((int)p.getX() + 1, (int)p.getY() + incr, (int)p.getX() + 1, (int)p.getY() + 1); |
249 |
|
250 |
g.setColor(Color.red);
|
251 |
g.drawOval( (int)p.getX() - dpto,
|
252 |
(int)p.getY() - dpto,
|
253 |
DIAM_CIRCLE, |
254 |
DIAM_CIRCLE); |
255 |
g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr); |
256 |
g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY()); |
257 |
|
258 |
if(showNumber){
|
259 |
g.setColor(Color.WHITE);
|
260 |
g.drawString(String.valueOf(pointNumber + 1), (int)(p.getX() + dpto + 4), (int)(p.getY() - dpto - 4) ); |
261 |
g.setColor(Color.red);
|
262 |
g.drawString(String.valueOf(pointNumber + 1), (int)(p.getX() + dpto + 1), (int)(p.getY() - dpto - 1) ); |
263 |
} |
264 |
} |
265 |
|
266 |
/**
|
267 |
* Dibuja sobre el graphics pasado la cruz del punto que marca
|
268 |
* la coordenada de la vista.
|
269 |
* @param g Graphics
|
270 |
*/
|
271 |
private void drawMapCrux(Graphics2D g, Point2D p, int pointNumber){ |
272 |
int dpto = (DIAM_CIRCLE >> 1); |
273 |
int incr = 5; |
274 |
g.setColor(Color.WHITE);
|
275 |
g.drawRect( (int)p.getX() - dpto + 1, |
276 |
(int)p.getY() - dpto + 1, |
277 |
DIAM_CIRCLE - 2,
|
278 |
DIAM_CIRCLE - 2);
|
279 |
g.drawLine((int)p.getX() - incr, (int)p.getY() - 1, (int)p.getX() - 1, (int)p.getY() - 1); |
280 |
g.drawLine((int)p.getX() - incr, (int)p.getY() + 1, (int)p.getX() - 1, (int)p.getY() + 1); |
281 |
|
282 |
g.drawLine((int)p.getX() + incr, (int)p.getY() - 1, (int)p.getX() + 1, (int)p.getY() - 1); |
283 |
g.drawLine((int)p.getX() + incr, (int)p.getY() + 1, (int)p.getX() + 1, (int)p.getY() + 1); |
284 |
|
285 |
g.drawLine((int)p.getX() - 1, (int)p.getY() - incr, (int)p.getX() - 1, (int)p.getY() - 1); |
286 |
g.drawLine((int)p.getX() + 1, (int)p.getY() - incr, (int)p.getX() + 1, (int)p.getY() - 1); |
287 |
|
288 |
g.drawLine((int)p.getX() - 1, (int)p.getY() + incr, (int)p.getX() - 1, (int)p.getY() + 1); |
289 |
g.drawLine((int)p.getX() + 1, (int)p.getY() + incr, (int)p.getX() + 1, (int)p.getY() + 1); |
290 |
|
291 |
g.setColor(new Color(45, 8 , 165)); |
292 |
g.drawRect( (int)p.getX() - dpto,
|
293 |
(int)p.getY() - dpto,
|
294 |
DIAM_CIRCLE, |
295 |
DIAM_CIRCLE); |
296 |
g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr); |
297 |
g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY()); |
298 |
if(showNumber){
|
299 |
g.setColor(Color.WHITE);
|
300 |
g.drawString(String.valueOf(pointNumber + 1), (int)(p.getX() + dpto + 4), (int)(p.getY() - dpto - 4) ); |
301 |
g.setColor(new Color(45, 8 , 165)); |
302 |
g.drawString(String.valueOf(pointNumber + 1), (int)(p.getX() + dpto + 1), (int)(p.getY() - dpto - 1) ); |
303 |
} |
304 |
} |
305 |
|
306 |
/* (non-Javadoc)
|
307 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable, double)
|
308 |
*/
|
309 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
310 |
double scale) throws DriverException { |
311 |
// TODO Auto-generated method stub
|
312 |
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* Elimina los puntos de la lista que no tiene las dos coordenadas asignadas.
|
317 |
*/
|
318 |
public void clean(){ |
319 |
Iterator iter = pointList.iterator();
|
320 |
while (iter.hasNext()) {
|
321 |
GeoPoint gp = (GeoPoint) iter.next(); |
322 |
if(gp.mapPoint == null || gp.pixelPoint == null) |
323 |
iter.remove(); |
324 |
} |
325 |
} |
326 |
/**
|
327 |
* A?ade un punto a la lista
|
328 |
* @param point punto para la lista
|
329 |
*/
|
330 |
public GeoPoint addPoint(Point2D pixel, Point2D map){ |
331 |
GeoPoint p = new GeoPoint(pixel, map);
|
332 |
pointList.add(p); |
333 |
return p;
|
334 |
} |
335 |
|
336 |
/**
|
337 |
* Obtiene el punto de la posici?n pos
|
338 |
*/
|
339 |
public GeoPoint getPoint(int pos){ |
340 |
try{
|
341 |
return (GeoPoint)pointList.get(pos);
|
342 |
}catch(IndexOutOfBoundsException exc){ |
343 |
return null; |
344 |
} |
345 |
} |
346 |
|
347 |
/**
|
348 |
* Elimina la lista de puntos almacenada
|
349 |
*/
|
350 |
public void clear(){ |
351 |
pointList = new ArrayList(); |
352 |
} |
353 |
|
354 |
/**
|
355 |
* Elimina el punto de la posici?n indicada por el par?metro pos
|
356 |
* @param pos Posici?n del punto a eliminar
|
357 |
*/
|
358 |
public void remove(int pos){ |
359 |
pointList.remove(pos); |
360 |
} |
361 |
|
362 |
/**
|
363 |
*Elimina el ?ltimo punto de la lista.
|
364 |
*/
|
365 |
public void delLastPoint(){ |
366 |
pointList.remove(pointList.size() - 1);
|
367 |
} |
368 |
|
369 |
/**
|
370 |
* Funci?n que obtiene si un punto es nuevo o no. Un punto es nuevo si todavia
|
371 |
* no han sido asignadas todas sus coordenadas.
|
372 |
* @param n N?mero de punto a obtener si es nuevo
|
373 |
* @return true si es nuevo o false si no lo es
|
374 |
*/
|
375 |
public boolean isNewPoint(int n){ |
376 |
if(this.getPoint(n) == null) |
377 |
return false; |
378 |
if(this.getPoint(n).pixelPoint == null || this.getPoint(n).mapPoint == null) |
379 |
return true; |
380 |
return false; |
381 |
} |
382 |
|
383 |
/**
|
384 |
* Devuelve el n?mero de puntos de la capa
|
385 |
* @return entero que representa el n?mero de puntos de la capa
|
386 |
*/
|
387 |
public int length(){ |
388 |
return pointList.size();
|
389 |
} |
390 |
|
391 |
/**
|
392 |
* Actualiza un punto de la lista de una posici?n determinada
|
393 |
* @param point punto para la lista
|
394 |
*/
|
395 |
public void updatePoint(Point2D pixel, Point2D map, int pos){ |
396 |
GeoPoint gp = (GeoPoint)pointList.get(pos); |
397 |
if(pixel != null) |
398 |
gp.pixelPoint = pixel; |
399 |
if(map != null) |
400 |
gp.mapPoint = map; |
401 |
} |
402 |
|
403 |
/**
|
404 |
* Calcula el RMS para el punto de la posici?n pos
|
405 |
* @param pos Posici?n
|
406 |
* @return valor RMS para el punto solicitado
|
407 |
*/
|
408 |
public double calcDoubleRMS(int pos){ |
409 |
if(transformPointList != null && getPoint(pos).mapPoint != null){ |
410 |
try{
|
411 |
double a = (transformPointList[pos].getX() - getPoint(pos).mapPoint.getX());
|
412 |
double b = (transformPointList[pos].getY() - getPoint(pos).mapPoint.getY());
|
413 |
return Math.sqrt(a*a + b*b); |
414 |
}catch(ArrayIndexOutOfBoundsException e){ |
415 |
//No hacemos nada pq ha intentado obtener un punto que no existe. Hace un return 0
|
416 |
}catch(NullPointerException e){ |
417 |
//No hacemos nada pq el punto a?n no est? completo y est? intentando obtener un valor que no existe.Hace un return 0
|
418 |
} |
419 |
} |
420 |
return -0D; |
421 |
} |
422 |
|
423 |
/**
|
424 |
* Calcula el RMS para el punto de la posici?n pos
|
425 |
* @param pos Posici?n
|
426 |
* @return RMS en forma de String
|
427 |
*/
|
428 |
public String calcRMS(int pos){ |
429 |
return String.valueOf(calcDoubleRMS(pos)); |
430 |
} |
431 |
|
432 |
/**
|
433 |
* Calcula el residuo en X para el punto de la posici?n pos
|
434 |
* @param pos Posici?n
|
435 |
* @return residuo Y en forma de double
|
436 |
*/
|
437 |
public double calcDoubleResX(int pos){ |
438 |
if( transformPointList != null && |
439 |
transformPointList[pos] != null &&
|
440 |
getPoint(pos).mapPoint != null){
|
441 |
try{
|
442 |
double a = (transformPointList[pos].getX() - getPoint(pos).mapPoint.getX());
|
443 |
return Math.sqrt(a*a); |
444 |
}catch(ArrayIndexOutOfBoundsException e){ |
445 |
//No hacemos nada pq ha intentado obtener un punto que no existe. Hace un return 0
|
446 |
}catch(NullPointerException e){ |
447 |
//No hacemos nada pq el punto a?n no est? completo y est? intentando obtener un valor que no existe.Hace un return 0
|
448 |
} |
449 |
} |
450 |
return -0; |
451 |
} |
452 |
|
453 |
/**
|
454 |
* Calcula el residuo en X para el punto de la posici?n pos
|
455 |
* @param pos Posici?n
|
456 |
* @return residuo Y en forma de String
|
457 |
*/
|
458 |
public String calcResX(int pos){ |
459 |
return String.valueOf(calcDoubleResX(pos)); |
460 |
} |
461 |
|
462 |
/**
|
463 |
* Calcula el residuo en Y para el punto de la posici?n pos
|
464 |
* @param pos Posici?n
|
465 |
* @return residuo Y en forma de double
|
466 |
*/
|
467 |
public double calcDoubleResY(int pos){ |
468 |
if( transformPointList != null && |
469 |
transformPointList[pos] != null &&
|
470 |
getPoint(pos).mapPoint != null){
|
471 |
try{
|
472 |
double b = (transformPointList[pos].getY() - getPoint(pos).mapPoint.getY());
|
473 |
return Math.sqrt(b*b); |
474 |
}catch(ArrayIndexOutOfBoundsException e){ |
475 |
//No hacemos nada pq ha intentado obtener un punto que no existe. Hace un return 0
|
476 |
}catch(NullPointerException e){ |
477 |
//No hacemos nada pq el punto a?n no est? completo y est? intentando obtener un valor que no existe.Hace un return 0
|
478 |
} |
479 |
} |
480 |
return -0D; |
481 |
} |
482 |
|
483 |
/**
|
484 |
* Calcula el residuo en Y para el punto de la posici?n pos
|
485 |
* @param pos Posici?n
|
486 |
* @return residuo Y en forma de String
|
487 |
*/
|
488 |
public String calcResY(int pos){ |
489 |
return String.valueOf(calcDoubleResY(pos)); |
490 |
} |
491 |
|
492 |
/**
|
493 |
* Calcula el error RMS para todos los puntos
|
494 |
* @return Error RMS total en forma de String
|
495 |
*/
|
496 |
public double calcDoubleTotal(){ |
497 |
double add = 0D; |
498 |
try{
|
499 |
for(int i=0;i<transformPointList.length;i++) |
500 |
add += calcDoubleRMS(i); |
501 |
}catch(NullPointerException e){ |
502 |
//transformPointList es null por lo que no hay puntos a transformar devolviendo 0.
|
503 |
return 0D; |
504 |
} |
505 |
return Math.sqrt(add/transformPointList.length); |
506 |
} |
507 |
|
508 |
/**
|
509 |
* Calcula el error RMS para todos los puntos
|
510 |
* @return Error RMS total en forma de String
|
511 |
*/
|
512 |
public String calcTotal(){ |
513 |
return String.valueOf(calcDoubleTotal()); |
514 |
} |
515 |
|
516 |
/**
|
517 |
* Muestra en consola los puntos de la capa
|
518 |
*/
|
519 |
public void showPoints(){ |
520 |
for(int i=0;i<pointList.size();i++){ |
521 |
if(((GeoPoint)pointList.get(i)).pixelPoint != null && ((GeoPoint)pointList.get(i)).mapPoint != null){ |
522 |
System.out.println("PUNTO "+i+": "); |
523 |
System.out.println("pix->"+((GeoPoint)pointList.get(i)).pixelPoint.getX()+" "+((GeoPoint)pointList.get(i)).pixelPoint.getY()); |
524 |
System.out.println("map->"+((GeoPoint)pointList.get(i)).mapPoint.getX()+" "+((GeoPoint)pointList.get(i)).mapPoint.getY()); |
525 |
System.out.println("extRight->"+((GeoPoint)pointList.get(i)).rightViewPort.getExtent()); |
526 |
System.out.println("extLeft->"+((GeoPoint)pointList.get(i)).leftViewPort.getExtent()); |
527 |
}else
|
528 |
System.out.println("PUNTO "+i+": NULL"); |
529 |
} |
530 |
} |
531 |
|
532 |
/**
|
533 |
* Salva la lista de puntos sobre el fichero que se la pasa por
|
534 |
* par?metro
|
535 |
* @param file Nombre del fichero
|
536 |
*/
|
537 |
public void PointList2XML(String file){; |
538 |
geoPointPersistence.savePointList(file); |
539 |
} |
540 |
|
541 |
/**
|
542 |
* Recupera una lista de puntos desde un fichero XML
|
543 |
* @param file Nombre del fichero
|
544 |
*/
|
545 |
public void XML2PointList(String file){ |
546 |
geoPointPersistence.loadPointList(file); |
547 |
} |
548 |
|
549 |
/**
|
550 |
* Salva la lista de puntos en forma tabular sobre el fichero que se la pasa por
|
551 |
* par?metro
|
552 |
* @param file Nombre del fichero
|
553 |
*/
|
554 |
public void PointList2Ascii(String file){; |
555 |
geoPointPersistence.saveAsciiPointList(file); |
556 |
} |
557 |
|
558 |
/* (non-Javadoc)
|
559 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#setXMLEntity(com.iver.utiles.XMLEntity)
|
560 |
*/
|
561 |
public void setXMLEntity(XMLEntity xml)throws XMLException { |
562 |
int nPoints = -1; |
563 |
if (xml.contains("raster.geoPoints.nPoints")) { |
564 |
nPoints = xml.getIntProperty("raster.geoPoints.nPoints");
|
565 |
GeoPoint point = null;
|
566 |
Point2D pixel = new Point2D.Double(), map = new Point2D.Double(); |
567 |
if(nPoints > 0){ |
568 |
|
569 |
for(int i = 0;i<nPoints;i++){ |
570 |
|
571 |
if (xml.contains("raster.geoPoint."+i+".pixelX") && xml.contains("raster.geoPoint."+i+".pixelY")) |
572 |
pixel.setLocation(xml.getDoubleProperty("raster.geoPoint."+i+".pixelX"), xml.getDoubleProperty("raster.geoPoint."+i+".pixelY")); |
573 |
|
574 |
if (xml.contains("raster.geoPoint."+i+".mapX") && xml.contains("raster.geoPoint."+i+".mapY")) |
575 |
map.setLocation(xml.getDoubleProperty("raster.geoPoint."+i+".mapX"), xml.getDoubleProperty("raster.geoPoint."+i+".mapY")); |
576 |
|
577 |
point = this.addPoint(pixel, map);
|
578 |
|
579 |
if (xml.contains("raster.geoPoint."+i+".active")) |
580 |
point.active = xml.getBooleanProperty("raster.geoPoint."+i+".active"); |
581 |
|
582 |
point.leftCenterPoint = new Point2D.Double(); |
583 |
if (xml.contains("raster.geoPoint."+i+".leftCenterX") && xml.contains("raster.geoPoint."+i+".leftCenterY")) |
584 |
point.leftCenterPoint.setLocation(xml.getDoubleProperty("raster.geoPoint."+i+".leftCenterX"), xml.getDoubleProperty("raster.geoPoint."+i+".leftCenterY")); |
585 |
|
586 |
point.rightCenterPoint = new Point2D.Double(); |
587 |
if (xml.contains("raster.geoPoint."+i+".rightCenterX") && xml.contains("raster.geoPoint."+i+".rightCenterY")) |
588 |
point.rightCenterPoint.setLocation(xml.getDoubleProperty("raster.geoPoint."+i+".rightCenterX"), xml.getDoubleProperty("raster.geoPoint."+i+".rightCenterY")); |
589 |
|
590 |
point.leftViewPort = new ViewPort(null); |
591 |
point.rightViewPort = new ViewPort(null); |
592 |
|
593 |
double x = 0D, y = 0D, w = 0D, h = 0D; |
594 |
int width = 0, height = 0; |
595 |
Rectangle2D r = new Rectangle2D.Double(); |
596 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.proj")) |
597 |
point.leftViewPort.setProjection(ProjectionPool.get(xml.getStringProperty("raster.geoPoint."+i+".leftViewPort.proj"))); |
598 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.x")) |
599 |
x = xml.getDoubleProperty("raster.geoPoint."+i+".leftViewPort.x"); |
600 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.y")) |
601 |
y = xml.getDoubleProperty("raster.geoPoint."+i+".leftViewPort.y"); |
602 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.w")) |
603 |
w = xml.getDoubleProperty("raster.geoPoint."+i+".leftViewPort.w"); |
604 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.h")) |
605 |
h = xml.getDoubleProperty("raster.geoPoint."+i+".leftViewPort.h"); |
606 |
r.setRect(x, y, w, h); |
607 |
point.leftViewPort.setExtent(r); |
608 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.imgWidth")) |
609 |
width = xml.getIntProperty("raster.geoPoint."+i+".leftViewPort.imgWidth"); |
610 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.imgHeight")) |
611 |
height = xml.getIntProperty("raster.geoPoint."+i+".leftViewPort.imgHeight"); |
612 |
point.leftViewPort.setImageSize(new Dimension(width, height)); |
613 |
|
614 |
r = new Rectangle2D.Double(); |
615 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.proj")) |
616 |
point.rightViewPort.setProjection(ProjectionPool.get(xml.getStringProperty("raster.geoPoint."+i+".rightViewPort.proj"))); |
617 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.x")) |
618 |
x = xml.getDoubleProperty("raster.geoPoint."+i+".rightViewPort.x"); |
619 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.y")) |
620 |
y = xml.getDoubleProperty("raster.geoPoint."+i+".rightViewPort.y"); |
621 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.w")) |
622 |
w = xml.getDoubleProperty("raster.geoPoint."+i+".rightViewPort.w"); |
623 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.h")) |
624 |
h = xml.getDoubleProperty("raster.geoPoint."+i+".rightViewPort.h"); |
625 |
r.setRect(x, y, w, h); |
626 |
point.rightViewPort.setExtent(r); |
627 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.imgWidth")) |
628 |
width = xml.getIntProperty("raster.geoPoint."+i+".rightViewPort.imgWidth"); |
629 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.imgHeight")) |
630 |
height = xml.getIntProperty("raster.geoPoint."+i+".rightViewPort.imgHeight"); |
631 |
point.rightViewPort.setImageSize(new Dimension(width, height)); |
632 |
|
633 |
} |
634 |
} |
635 |
} |
636 |
} |
637 |
|
638 |
/* (non-Javadoc)
|
639 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getXMLEntity(com.iver.utiles.XMLEntity)
|
640 |
*/
|
641 |
public void getXMLEntity(XMLEntity xml) throws XMLException { |
642 |
xml.putProperty("raster.geoPoints.nPoints", getCountPoints());
|
643 |
for(int i=0;i<this.getCountPoints();i++){ |
644 |
xml.putProperty("raster.geoPoint."+i+".pixelX", getPoint(i).pixelPoint.getX()); |
645 |
xml.putProperty("raster.geoPoint."+i+".pixelY", getPoint(i).pixelPoint.getY()); |
646 |
xml.putProperty("raster.geoPoint."+i+".mapX", getPoint(i).mapPoint.getX()); |
647 |
xml.putProperty("raster.geoPoint."+i+".mapY", getPoint(i).mapPoint.getX()); |
648 |
|
649 |
xml.putProperty("raster.geoPoint."+i+".active", getPoint(i).active); |
650 |
|
651 |
xml.putProperty("raster.geoPoint."+i+".leftCenterX", getPoint(i).leftCenterPoint.getX()); |
652 |
xml.putProperty("raster.geoPoint."+i+".leftCenterY", getPoint(i).leftCenterPoint.getY()); |
653 |
xml.putProperty("raster.geoPoint."+i+".rightCenterX", getPoint(i).rightCenterPoint.getX()); |
654 |
xml.putProperty("raster.geoPoint."+i+".rightCenterY", getPoint(i).rightCenterPoint.getY()); |
655 |
|
656 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.proj", getPoint(i).leftViewPort.getProjection().getAbrev()); |
657 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.x", getPoint(i).leftViewPort.getExtent().getX()); |
658 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.y", getPoint(i).leftViewPort.getExtent().getY()); |
659 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.w", getPoint(i).leftViewPort.getExtent().getWidth()); |
660 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.h", getPoint(i).leftViewPort.getExtent().getHeight()); |
661 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.imgWidth", getPoint(i).leftViewPort.getImageWidth()); |
662 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.imgHeight", getPoint(i).leftViewPort.getImageHeight()); |
663 |
|
664 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.proj", getPoint(i).rightViewPort.getProjection().getAbrev()); |
665 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.x", getPoint(i).rightViewPort.getExtent().getX()); |
666 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.y", getPoint(i).rightViewPort.getExtent().getY()); |
667 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.w", getPoint(i).rightViewPort.getExtent().getWidth()); |
668 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.h", getPoint(i).rightViewPort.getExtent().getHeight()); |
669 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.imgWidth", getPoint(i).rightViewPort.getImageWidth()); |
670 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.imgHeight", getPoint(i).rightViewPort.getImageHeight()); |
671 |
} |
672 |
} |
673 |
//**********************End Methods********************************
|
674 |
|
675 |
//**********************Setters & Getters**************************
|
676 |
/**
|
677 |
* Asigna el viewPort de la mini imagen de la derecha en
|
678 |
* el punto de la posici?n que se le pasa por par?metro
|
679 |
* @param pos Posici?n del punto
|
680 |
* @param vp ViewPort asignado
|
681 |
*/
|
682 |
public void setRightViewPort(int pos, ViewPort vp){ |
683 |
getPoint(pos).rightViewPort = vp; |
684 |
} |
685 |
/**
|
686 |
* @return Returns the showNumber.
|
687 |
*/
|
688 |
public boolean isShowNumber() { |
689 |
return showNumber;
|
690 |
} |
691 |
|
692 |
/**
|
693 |
* @param showNumber The showNumber to set.
|
694 |
*/
|
695 |
public void setShowNumber(boolean showNumber) { |
696 |
this.showNumber = showNumber;
|
697 |
} |
698 |
|
699 |
/**
|
700 |
* Asigna el punto central de la mini imagen de la izquierda
|
701 |
* en el punto de la posici?n que se le pasa por par?metro
|
702 |
* @param pos Posici?n del punto
|
703 |
* @param p Punto asignado
|
704 |
*/
|
705 |
public void setLeftCenterPoint(int pos, Point2D p){ |
706 |
getPoint(pos).leftCenterPoint = p; |
707 |
} |
708 |
|
709 |
/**
|
710 |
* Asigna el punto central de la mini imagen de la derecha
|
711 |
* en el punto de la posici?n que se le pasa por par?metro
|
712 |
* @param pos Posici?n del punto
|
713 |
* @param p Punto asignado
|
714 |
*/
|
715 |
public void setRightCenterPoint(int pos, Point2D p){ |
716 |
getPoint(pos).rightCenterPoint = p; |
717 |
} |
718 |
|
719 |
/**
|
720 |
* Asigna el viewPort de la mini imagen de la izquierda en
|
721 |
* el punto de la posici?n que se le pasa por par?metro
|
722 |
* @param pos Posici?n del punto
|
723 |
* @param vp ViewPort asignado
|
724 |
*/
|
725 |
public void setLeftViewPort(int pos, ViewPort vp){ |
726 |
getPoint(pos).leftViewPort = vp; |
727 |
} |
728 |
|
729 |
/**
|
730 |
* Devuelve el n?mero de puntos de la lista
|
731 |
* @return entero que representa el n?mero de puntos
|
732 |
*/
|
733 |
public int getCountPoints(){ |
734 |
if(pointList != null) |
735 |
return pointList.size();
|
736 |
else
|
737 |
return 0; |
738 |
} |
739 |
|
740 |
/**
|
741 |
* Devuelve el n?mero de puntos de la lista que est?n activos
|
742 |
* @return entero que representa el n?mero de puntos
|
743 |
*/
|
744 |
public int getCountActivePoints(){ |
745 |
int activePoints = 0; |
746 |
if(pointList != null){ |
747 |
for(int i = 0; i< pointList.size(); i++) |
748 |
if(getPoint(i).active)
|
749 |
activePoints ++; |
750 |
return activePoints;
|
751 |
}else
|
752 |
return 0; |
753 |
} |
754 |
|
755 |
/**
|
756 |
* Activa o desactiva el punto de una posici?n de la lista
|
757 |
* @param n N?mero de punto
|
758 |
* @param active true activo, false desactivo
|
759 |
*/
|
760 |
public void setPointActive(int n, boolean active){ |
761 |
if(n < 0 || n >= this.length()) |
762 |
return;
|
763 |
((GeoPoint)pointList.get(n)).active = active; |
764 |
} |
765 |
|
766 |
/**
|
767 |
* Dice si un punto de la lista est? activo o no
|
768 |
* @param n Posici?n del punto
|
769 |
* @return true si est? activo y false si no lo est?.
|
770 |
*/
|
771 |
public boolean isPointActive(int n){ |
772 |
if(n < 0 || n >= this.length()) |
773 |
return false; |
774 |
return ((GeoPoint)pointList.get(n)).active;
|
775 |
} |
776 |
|
777 |
/**
|
778 |
* Obtiene el extent de la capa
|
779 |
* @return extent en Rectangle2D.
|
780 |
*/
|
781 |
public Rectangle2D getFullExtent()throws DriverException { |
782 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
783 |
return theView.getMapControl().getMapContext().getViewPort().getExtent();
|
784 |
} |
785 |
|
786 |
/**
|
787 |
* @return Returns the lastTool.
|
788 |
*/
|
789 |
public String getLastTool() { |
790 |
return lastTool;
|
791 |
} |
792 |
|
793 |
/**
|
794 |
* @param lastTool The lastTool to set.
|
795 |
*/
|
796 |
public void setLastTool(String lastTool) { |
797 |
this.lastTool = lastTool;
|
798 |
} |
799 |
|
800 |
/**
|
801 |
*Asigna el extent para las mini imagenes. Estas deben ser recuperadas cuando se selecciona
|
802 |
*un punto
|
803 |
*/
|
804 |
public void setMiniExtent(int nPoint, Point2D centerPoint, ViewPort vp, boolean isRight){ |
805 |
if(isRight){
|
806 |
((GeoPoint)pointList.get(nPoint)).rightCenterPoint = centerPoint; |
807 |
((GeoPoint)pointList.get(nPoint)).rightViewPort = vp; |
808 |
}else{
|
809 |
((GeoPoint)pointList.get(nPoint)).leftCenterPoint = centerPoint; |
810 |
((GeoPoint)pointList.get(nPoint)).leftViewPort = vp; |
811 |
} |
812 |
} |
813 |
|
814 |
/**
|
815 |
* Obtiene el extent de la mini imagen
|
816 |
* @param nPoint Punto de la lista
|
817 |
* @return
|
818 |
*/
|
819 |
public ViewPort getMiniExtent(int nPoint, boolean isRight){ |
820 |
if(isRight)
|
821 |
return ((GeoPoint)pointList.get(nPoint)).rightViewPort;
|
822 |
else
|
823 |
return ((GeoPoint)pointList.get(nPoint)).leftViewPort;
|
824 |
|
825 |
} |
826 |
|
827 |
/**
|
828 |
* Obtiene el punto central de la mini imagen
|
829 |
* @param nPoint Punto de la lista
|
830 |
* @return
|
831 |
*/
|
832 |
public Point2D getCenterPoint(int nPoint, boolean isRight){ |
833 |
if(isRight)
|
834 |
return ((GeoPoint)pointList.get(nPoint)).rightCenterPoint;
|
835 |
else
|
836 |
return ((GeoPoint)pointList.get(nPoint)).leftCenterPoint;
|
837 |
} |
838 |
|
839 |
/**
|
840 |
* Obtiene le ?ltimo punto de la lista
|
841 |
* @return El ?ltimo punto georreferenciado de la lista
|
842 |
*/
|
843 |
public GeoPoint getLastPoint(){
|
844 |
return (GeoPoint)pointList.get(pointList.size());
|
845 |
} |
846 |
|
847 |
/**
|
848 |
* Obtiene el array de puntos
|
849 |
* @return
|
850 |
*/
|
851 |
public ArrayList getListPoint(){ |
852 |
return pointList;
|
853 |
} |
854 |
|
855 |
/**
|
856 |
* Obtiene el gestor de puntos
|
857 |
* @return PointManager
|
858 |
*/
|
859 |
public PointManager getPointManager() {
|
860 |
return pointManager;
|
861 |
} |
862 |
|
863 |
/**
|
864 |
* Asigna el gestor de puntos
|
865 |
* @param PointManager
|
866 |
*/
|
867 |
public void setPointManager(PointManager pointManager) { |
868 |
this.pointManager = pointManager;
|
869 |
} |
870 |
|
871 |
/**
|
872 |
* Obtiene la capa de la imagen a georreferenciar
|
873 |
* @return FLyrGeoRaster
|
874 |
*/
|
875 |
public FLyrGeoRaster getLyrGeoRaster() {
|
876 |
return lyrGeoRaster;
|
877 |
} |
878 |
|
879 |
/**
|
880 |
* Asigna la capa de la imagen a georreferenciar
|
881 |
* @param flyGeoRaster
|
882 |
*/
|
883 |
public void setLyrGeoRaster(FLyrGeoRaster lyGeoRaster){ |
884 |
this.lyrGeoRaster = lyGeoRaster;
|
885 |
if(geoPointPersistence == null) |
886 |
geoPointPersistence = new GeoPointPersistence(this); |
887 |
} |
888 |
|
889 |
/**
|
890 |
* Asigna el flag de visibilidad a true o false. Si est? a true la capa
|
891 |
* es visible normalmente y si est? a false no se mostrar?
|
892 |
* @param visible flag de visibilidad
|
893 |
*/
|
894 |
public void setVisible(boolean visible){ |
895 |
this.lyrVisible = visible;
|
896 |
} |
897 |
|
898 |
/**
|
899 |
* Obtiene el flag de visibilidad true o false. Si est? a true la capa
|
900 |
* es visible normalmente y si est? a false no se muestra
|
901 |
* @return flag de visibilidad
|
902 |
*/
|
903 |
public boolean isVisible(){ |
904 |
return this.lyrVisible; |
905 |
} |
906 |
|
907 |
/**
|
908 |
* Obtiene la lista de puntos transformados. La lista de puntos transformada es la lista de puntos
|
909 |
* a la que se le ha aplicado la transformaci?n af?n en base a las muestras tomadas.
|
910 |
* Esta lista de puntos transformados hay que mantenerla actualizada cada vez que se hace un
|
911 |
* update de un punto ya se usa para calcular los errores.
|
912 |
* @return Lista de puntos transformada.
|
913 |
*/
|
914 |
public Point2D[] getTransformPointList() { |
915 |
return transformPointList;
|
916 |
} |
917 |
|
918 |
/**
|
919 |
* Asigna la lista de puntos transformada. La lista de puntos transformada es la lista de puntos
|
920 |
* a la que se le ha aplicado la transformaci?n af?n en base a las muestras tomadas.
|
921 |
* Esta lista de puntos transformados hay que mantenerla actualizada cada vez que se hace un
|
922 |
* update de un punto ya se usa para calcular los errores.
|
923 |
* @param transformPointList Lista de puntos transformada.
|
924 |
*/
|
925 |
public void setTransformPointList(Point2D[] transformPointList) { |
926 |
this.transformPointList = transformPointList;
|
927 |
} |
928 |
|
929 |
/**
|
930 |
* Asigna el objeto que gestiona la persistencia
|
931 |
*/
|
932 |
public void setPersistence(IPersistence geoPointPersistence) { |
933 |
if(this.geoPointPersistence == null) |
934 |
this.geoPointPersistence = geoPointPersistence;
|
935 |
} |
936 |
|
937 |
/**
|
938 |
* Obtiene el valor del flag que dice si se dibuja la cruz azul
|
939 |
* @return
|
940 |
*/
|
941 |
public boolean isWithoutBlue() { |
942 |
return withoutBlue;
|
943 |
} |
944 |
|
945 |
/**
|
946 |
* Asigna valor al flag que dice si se dibuja la cruz azul. Ser? true si no queremos
|
947 |
* dibujarla y false si queremos.
|
948 |
* @param withoutBlue
|
949 |
*/
|
950 |
public void setWithoutBlue(boolean withoutBlue) { |
951 |
this.withoutBlue = withoutBlue;
|
952 |
} |
953 |
|
954 |
/**
|
955 |
* Obtiene el valor del flag que dice si se dibuja la cruz roja
|
956 |
* @return
|
957 |
*/
|
958 |
public boolean isWithoutRed() { |
959 |
return withoutRed;
|
960 |
} |
961 |
|
962 |
/**
|
963 |
* Asigna valor al flag que dice si se dibuja la cruz roja. Ser? true si no queremos
|
964 |
* dibujarla y false si queremos.
|
965 |
* @param withoutRed
|
966 |
*/
|
967 |
public void setWithoutRed(boolean withoutRed) { |
968 |
this.withoutRed = withoutRed;
|
969 |
} |
970 |
//**********************End Setters & Getters*********************
|
971 |
} |