root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / fmap / layers / FLyrPoints.java @ 2998
History | View | Annotate | Download (7.48 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.geom.Point2D; |
46 |
import java.awt.geom.Rectangle2D; |
47 |
import java.awt.image.BufferedImage; |
48 |
import java.util.ArrayList; |
49 |
import java.util.Iterator; |
50 |
|
51 |
import com.iver.andami.PluginServices; |
52 |
import com.iver.cit.gvsig.fmap.DriverException; |
53 |
import com.iver.cit.gvsig.fmap.ViewPort; |
54 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
55 |
import com.iver.cit.gvsig.gui.View; |
56 |
import com.iver.cit.gvsig.gui.Panels.SelectFilePanel; |
57 |
|
58 |
|
59 |
/**
|
60 |
* Clase de capa de marcado de puntos sobre una vista. Dibuja un puntero sobre
|
61 |
* cada punto en la vista.
|
62 |
*
|
63 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
64 |
*/
|
65 |
public class FLyrPoints extends FLyrDefault { |
66 |
|
67 |
public class GeoPoint{ |
68 |
public Point2D pixelPoint = null; |
69 |
public Point2D mapPoint = null; |
70 |
public GeoPoint(Point2D p, Point2D m){ |
71 |
this.pixelPoint = p;
|
72 |
this.mapPoint = m;
|
73 |
} |
74 |
} |
75 |
|
76 |
private ArrayList pointList = new ArrayList(); |
77 |
private final int DIAM_CIRCLE = 18; |
78 |
private String lastTool = null; |
79 |
|
80 |
/**
|
81 |
* Obtiene el array de puntos
|
82 |
* @return
|
83 |
*/
|
84 |
public ArrayList getListPoint(){ |
85 |
return pointList;
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* Asigna el array de puntos
|
90 |
* @param list
|
91 |
*/
|
92 |
public void setListPoint(ArrayList list){ |
93 |
pointList = list; |
94 |
} |
95 |
|
96 |
/**
|
97 |
* Dibujado de la capa de raster georeferenciado aplicando la
|
98 |
* transformaci?n del viewPort.
|
99 |
*/
|
100 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp, |
101 |
Cancellable cancel,double scale) throws DriverException { |
102 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
103 |
//BufferedImage img = theView.getMapControl().getImage();
|
104 |
//g.drawImage(img, 0, 0, null);
|
105 |
int dpto = (DIAM_CIRCLE >> 1); |
106 |
int incr = 5; |
107 |
Point2D pto = null; |
108 |
FLyrGeoRaster lyrGeoRaster = null;
|
109 |
//Obtenemos la capa de puntos y la capa de georaster
|
110 |
|
111 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
112 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
113 |
if( lyr instanceof FLyrGeoRaster && |
114 |
lyr.getName().startsWith("*") &&
|
115 |
lyr.isActive()) |
116 |
lyrGeoRaster = (FLyrGeoRaster)lyr; |
117 |
} |
118 |
|
119 |
for(int i=0; i<pointList.size();i++){ |
120 |
|
121 |
//Punto de la imagen
|
122 |
pto = ((GeoPoint)pointList.get(i)).pixelPoint; |
123 |
|
124 |
if(pto != null){ |
125 |
g.setColor(Color.red);
|
126 |
Point2D p = lyrGeoRaster.img2World(pto);
|
127 |
p = vp.fromMapPoint(p); |
128 |
g.drawOval( (int)p.getX() - dpto,
|
129 |
(int)p.getY() - dpto,
|
130 |
DIAM_CIRCLE, |
131 |
DIAM_CIRCLE); |
132 |
g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr); |
133 |
g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY()); |
134 |
} |
135 |
|
136 |
//Punto de la vista
|
137 |
pto = ((GeoPoint)pointList.get(i)).mapPoint; |
138 |
if(pto != null){ |
139 |
Point2D p = vp.fromMapPoint(pto);
|
140 |
g.setColor(Color.green);
|
141 |
g.drawOval( (int)p.getX() - dpto,
|
142 |
(int)p.getY() - dpto,
|
143 |
DIAM_CIRCLE, |
144 |
DIAM_CIRCLE); |
145 |
g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr); |
146 |
g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY()); |
147 |
} |
148 |
} |
149 |
} |
150 |
|
151 |
/* (non-Javadoc)
|
152 |
* @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)
|
153 |
*/
|
154 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
155 |
double scale) throws DriverException { |
156 |
// TODO Auto-generated method stub
|
157 |
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* Elimina los puntos de la lista que no tiene las dos coordenadas asignadas.
|
162 |
*/
|
163 |
public void clean(){ |
164 |
Iterator iter = pointList.iterator();
|
165 |
while (iter.hasNext()) {
|
166 |
GeoPoint gp = (GeoPoint) iter.next(); |
167 |
if(gp.mapPoint == null || gp.pixelPoint == null) |
168 |
iter.remove(); |
169 |
} |
170 |
} |
171 |
/**
|
172 |
* A?ade un punto a la lista
|
173 |
* @param point punto para la lista
|
174 |
*/
|
175 |
public void addPoint(Point2D pixel, Point2D map){ |
176 |
pointList.add(new GeoPoint(pixel, map));
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* Obtiene el punto de la posici?n pos
|
181 |
*/
|
182 |
public GeoPoint getPoint(int pos){ |
183 |
return (GeoPoint)pointList.get(pos);
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* Elimina la lista de puntos almacenada
|
188 |
*/
|
189 |
public void clear(){ |
190 |
pointList = new ArrayList(); |
191 |
} |
192 |
|
193 |
/**
|
194 |
* Elimina el punto de la posici?n indicada por el par?metro pos
|
195 |
* @param pos Posici?n del punto a eliminar
|
196 |
*/
|
197 |
public void remove(int pos){ |
198 |
pointList.remove(pos); |
199 |
} |
200 |
|
201 |
/**
|
202 |
*Elimina el ?ltimo punto de la lista.
|
203 |
*/
|
204 |
public void delLastPoint(){ |
205 |
pointList.remove(pointList.size() - 1);
|
206 |
} |
207 |
|
208 |
/**
|
209 |
* Obtiene le ?ltimo punto de la lista
|
210 |
*
|
211 |
*/
|
212 |
public GeoPoint getLastPoint(){
|
213 |
return (GeoPoint)pointList.get(pointList.size());
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* Devuelve el n?mero de puntos de la capa
|
218 |
* @return
|
219 |
*/
|
220 |
public int length(){ |
221 |
return pointList.size();
|
222 |
} |
223 |
|
224 |
/**
|
225 |
* Actualiza un punto de la lista de una posici?n determinada
|
226 |
* @param point punto para la lista
|
227 |
*/
|
228 |
public void updatePoint(Point2D pixel, Point2D map, int pos){ |
229 |
GeoPoint gp = (GeoPoint)pointList.get(pos); |
230 |
if(pixel != null) |
231 |
gp.pixelPoint = pixel; |
232 |
if(map != null) |
233 |
gp.mapPoint = map; |
234 |
} |
235 |
|
236 |
/**
|
237 |
* Devuelve el n?mero de puntos de la lista
|
238 |
* @return
|
239 |
*/
|
240 |
public int getCountPoints(){ |
241 |
if(pointList != null) |
242 |
return pointList.size();
|
243 |
else
|
244 |
return 0; |
245 |
} |
246 |
|
247 |
/**
|
248 |
* Obtiene el extent de la capa
|
249 |
* @return extent en Rectangle2D.
|
250 |
*/
|
251 |
public Rectangle2D getFullExtent()throws DriverException { |
252 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
253 |
return theView.getMapControl().getMapContext().getViewPort().getExtent();
|
254 |
} |
255 |
|
256 |
/**
|
257 |
* @return Returns the lastTool.
|
258 |
*/
|
259 |
public String getLastTool() { |
260 |
return lastTool;
|
261 |
} |
262 |
|
263 |
/**
|
264 |
* @param lastTool The lastTool to set.
|
265 |
*/
|
266 |
public void setLastTool(String lastTool) { |
267 |
this.lastTool = lastTool;
|
268 |
} |
269 |
|
270 |
/**
|
271 |
* Muestra en consola los puntos de la capa
|
272 |
*/
|
273 |
public void showPoints(){ |
274 |
for(int i=0;i<pointList.size();i++){ |
275 |
if(((GeoPoint)pointList.get(i)).pixelPoint != null && ((GeoPoint)pointList.get(i)).mapPoint != null){ |
276 |
System.out.println("PUNTO "+i+": "); |
277 |
System.out.println("pix->"+((GeoPoint)pointList.get(i)).pixelPoint.getX()+" "+((GeoPoint)pointList.get(i)).pixelPoint.getY()); |
278 |
System.out.println("map->"+((GeoPoint)pointList.get(i)).mapPoint.getX()+" "+((GeoPoint)pointList.get(i)).mapPoint.getY()); |
279 |
}else
|
280 |
System.out.println("PUNTO "+i+": NULL"); |
281 |
} |
282 |
} |
283 |
} |