svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap / src / org / gvsig / fmap / mapcontext / layers / vectorial / FLyrVect.java @ 21155
History | View | Annotate | Download (62.1 KB)
1 | 1100 | fjp | /* 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 | 20989 | jmvivo | package org.gvsig.fmap.mapcontext.layers.vectorial; |
42 | 214 | fernando | |
43 | 1828 | fernando | import java.awt.Graphics2D; |
44 | 14409 | vcaballero | import java.awt.geom.AffineTransform; |
45 | 1828 | fernando | import java.awt.geom.Point2D; |
46 | import java.awt.geom.Rectangle2D; |
||
47 | import java.awt.image.BufferedImage; |
||
48 | 13558 | evercher | import java.net.URI; |
49 | 11704 | jaume | import java.util.ArrayList; |
50 | 21104 | vcaballero | import java.util.Iterator; |
51 | 1828 | fernando | |
52 | 9010 | caballero | import javax.print.attribute.PrintRequestAttributeSet; |
53 | 12657 | jaume | import javax.print.attribute.standard.PrintQuality; |
54 | 9010 | caballero | |
55 | 1828 | fernando | import org.apache.log4j.Logger; |
56 | import org.cresques.cts.ICoordTrans; |
||
57 | 21104 | vcaballero | import org.gvsig.data.DataStore; |
58 | import org.gvsig.data.ReadException; |
||
59 | import org.gvsig.data.vectorial.Feature; |
||
60 | import org.gvsig.data.vectorial.FeatureCollection; |
||
61 | import org.gvsig.data.vectorial.FeatureStore; |
||
62 | import org.gvsig.data.vectorial.FeatureType; |
||
63 | import org.gvsig.data.vectorial.visitor.FeaturesVisitor; |
||
64 | import org.gvsig.exceptions.BaseException; |
||
65 | import org.gvsig.exceptions.DriverException; |
||
66 | import org.gvsig.fmap.geom.Geometry; |
||
67 | import org.gvsig.fmap.geom.operation.DrawInts; |
||
68 | import org.gvsig.fmap.geom.operation.DrawOperationContext; |
||
69 | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
||
70 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
71 | 20989 | jmvivo | import org.gvsig.fmap.mapcontext.MapContext; |
72 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
73 | import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
||
74 | import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
||
75 | import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException; |
||
76 | import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException; |
||
77 | import org.gvsig.fmap.mapcontext.layers.AbstractLinkProperties; |
||
78 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
79 | import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
||
80 | import org.gvsig.fmap.mapcontext.layers.FLyrVectLinkProperties; |
||
81 | import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
||
82 | import org.gvsig.fmap.mapcontext.layers.SelectionSupport; |
||
83 | import org.gvsig.fmap.mapcontext.layers.SpatialCache; |
||
84 | import org.gvsig.fmap.mapcontext.layers.XMLException; |
||
85 | import org.gvsig.fmap.mapcontext.layers.operations.AlphanumericData; |
||
86 | import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial; |
||
87 | import org.gvsig.fmap.mapcontext.layers.operations.ILabelable; |
||
88 | import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
||
89 | import org.gvsig.fmap.mapcontext.layers.operations.VectorialData; |
||
90 | import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend; |
||
91 | import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
||
92 | import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
||
93 | import org.gvsig.fmap.mapcontext.rendering.legend.SingleSymbolLegend; |
||
94 | import org.gvsig.fmap.mapcontext.rendering.legend.ZSort; |
||
95 | import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent; |
||
96 | import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
||
97 | import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
||
98 | import org.gvsig.fmap.mapcontext.rendering.symbols.FSymbol; |
||
99 | import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
||
100 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
101 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
102 | 21114 | vcaballero | import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
103 | 1828 | fernando | |
104 | 21104 | vcaballero | import spatialindex.spatialindex.ISpatialIndex; |
105 | |||
106 | 415 | fernando | import com.iver.utiles.XMLEntity; |
107 | 5317 | fjp | import com.iver.utiles.swing.threads.Cancellable; |
108 | 214 | fernando | |
109 | 562 | fernando | /**
|
110 | 1034 | vcaballero | * Capa b?sica Vectorial.
|
111 | 5184 | caballero | *
|
112 | 562 | fernando | * @author Fernando Gonz?lez Cort?s
|
113 | */
|
||
114 | 885 | fjp | |
115 | 5152 | fjp | // TODO Cuando no sea para pruebas debe no ser public
|
116 | 10679 | jaume | public class FLyrVect extends FLyrDefault implements ILabelable, |
117 | 21104 | vcaballero | ClassifiableVectorial, SingleLayer, VectorialData, //RandomVectorialData,
|
118 | AlphanumericData //, InfoByPoint
|
||
119 | { |
||
120 | 12349 | jaume | private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
121 | 14409 | vcaballero | |
122 | 12349 | jaume | /** Leyenda de la capa vectorial */
|
123 | 13884 | jaume | private IVectorLegend legend;
|
124 | 12349 | jaume | private int typeShape = -1; |
125 | 21104 | vcaballero | // private ReadableVectorial source;
|
126 | // private SelectableDataSource sds;
|
||
127 | private FeatureStore featureStore=null; |
||
128 | 12349 | jaume | private SelectionSupport selectionSupport = new SelectionSupport(); |
129 | private SpatialCache spatialCache = new SpatialCache(); |
||
130 | private boolean spatialCacheEnabled = false; |
||
131 | 3940 | caballero | |
132 | 12349 | jaume | /**
|
133 | * An implementation of gvSIG spatial index
|
||
134 | */
|
||
135 | protected ISpatialIndex spatialIndex = null; |
||
136 | private boolean bHasJoin = false; |
||
137 | private XMLEntity orgXMLEntity = null; |
||
138 | private XMLEntity loadSelection = null; |
||
139 | 13884 | jaume | private IVectorLegend loadLegend = null; |
140 | 461 | fernando | |
141 | 13558 | evercher | //Lo a?ado. Caracter?sticas de HyperEnlace (LINK)
|
142 | private FLyrVectLinkProperties linkProperties=new FLyrVectLinkProperties(); |
||
143 | |||
144 | 12349 | jaume | /**
|
145 | * Devuelve el VectorialAdapater de la capa.
|
||
146 | *
|
||
147 | * @return VectorialAdapter.
|
||
148 | */
|
||
149 | 21104 | vcaballero | public DataStore getDataStore() {
|
150 | 12349 | jaume | if (!this.isAvailable()) return null; |
151 | 21104 | vcaballero | return featureStore;
|
152 | 12349 | jaume | } |
153 | 5115 | caballero | |
154 | 12349 | jaume | /**
|
155 | * If we use a persistent spatial index associated with this layer, and the
|
||
156 | * index is not intrisic to the layer (for example spatial databases) this
|
||
157 | * method looks for existent spatial index, and loads it.
|
||
158 | *
|
||
159 | */
|
||
160 | 21104 | vcaballero | // private void loadSpatialIndex() {
|
161 | // //FIXME: Al abrir el indice en fichero...
|
||
162 | // //?C?mo lo liberamos? un metodo Layer.shutdown()
|
||
163 | //
|
||
164 | //
|
||
165 | // ReadableVectorial source = getSource();
|
||
166 | // //REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
|
||
167 | // //PUES SON VECTORIALFILEADAPTER
|
||
168 | // if (!(source instanceof VectorialFileAdapter)) {
|
||
169 | // // we are not interested in db adapters
|
||
170 | // return;
|
||
171 | // }
|
||
172 | // VectorialDriver driver = source.getDriver();
|
||
173 | // if (!(driver instanceof BoundedShapes)) {
|
||
174 | // // we dont spatially index layers that are not bounded
|
||
175 | // return;
|
||
176 | // }
|
||
177 | // File file = ((VectorialFileAdapter) source).getFile();
|
||
178 | // String fileName = file.getAbsolutePath();
|
||
179 | // File sptFile = new File(fileName + ".qix");
|
||
180 | // if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
||
181 | // // before to exit, look for it in temp path
|
||
182 | // String tempPath = System.getProperty("java.io.tmpdir");
|
||
183 | // fileName = tempPath + File.separator + sptFile.getName();
|
||
184 | // sptFile = new File(fileName);
|
||
185 | // // it doesnt exists, must to create
|
||
186 | // if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
||
187 | // return;
|
||
188 | // }// if
|
||
189 | // }// if
|
||
190 | //
|
||
191 | // try {
|
||
192 | // source.start();
|
||
193 | // spatialIndex = new QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
|
||
194 | // "NM", source.getFullExtent(), source.getShapeCount(), false);
|
||
195 | // source.setSpatialIndex(spatialIndex);
|
||
196 | // } catch (SpatialIndexException e) {
|
||
197 | // spatialIndex = null;
|
||
198 | // e.printStackTrace();
|
||
199 | // return;
|
||
200 | // } catch (ReadDriverException e) {
|
||
201 | // spatialIndex = null;
|
||
202 | // e.printStackTrace();
|
||
203 | // return;
|
||
204 | // }
|
||
205 | //
|
||
206 | // }
|
||
207 | 5484 | caballero | |
208 | 12349 | jaume | /**
|
209 | * Checks if it has associated an external spatial index
|
||
210 | * (an spatial index file).
|
||
211 | *
|
||
212 | * It looks for it in main file path, or in temp system path.
|
||
213 | * If main file is rivers.shp, it looks for a file called
|
||
214 | * rivers.shp.qix.
|
||
215 | 5484 | caballero | |
216 | 12349 | jaume | * @return
|
217 | */
|
||
218 | 21104 | vcaballero | // public boolean isExternallySpatiallyIndexed() {
|
219 | // /*
|
||
220 | // * FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
|
||
221 | // * con el que se trabaje (ahora mismo considera la extension .qix,
|
||
222 | // * pero esto depender? del tipo de ?ndice)
|
||
223 | // * */
|
||
224 | // ReadableVectorial source = getSource();
|
||
225 | // if (!(source instanceof VectorialFileAdapter)) {
|
||
226 | // // we are not interested in db adapters.
|
||
227 | // // think in non spatial dbs, like HSQLDB
|
||
228 | // return false;
|
||
229 | // }
|
||
230 | // File file = ((VectorialFileAdapter) source).getFile();
|
||
231 | // String fileName = file.getAbsolutePath();
|
||
232 | // File sptFile = new File(fileName + ".qix");
|
||
233 | // if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
||
234 | // // before to exit, look for it in temp path
|
||
235 | // // it doesnt exists, must to create
|
||
236 | // String tempPath = System.getProperty("java.io.tmpdir");
|
||
237 | // fileName = tempPath + File.separator + sptFile.getName();
|
||
238 | // sptFile = new File(fileName);
|
||
239 | // if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
||
240 | // return false;
|
||
241 | // }// if
|
||
242 | // }// if
|
||
243 | // return true;
|
||
244 | // }
|
||
245 | 472 | fernando | |
246 | 12349 | jaume | /**
|
247 | * Inserta el VectorialAdapter a la capa.
|
||
248 | *
|
||
249 | * @param va
|
||
250 | * VectorialAdapter.
|
||
251 | */
|
||
252 | 21104 | vcaballero | public void setDataStore(DataStore dataStore) { |
253 | featureStore = (FeatureStore)dataStore; |
||
254 | 12349 | jaume | // azabala: we check if this layer could have a file spatial index
|
255 | // and load it if it exists
|
||
256 | 21104 | vcaballero | // loadSpatialIndex();
|
257 | 12349 | jaume | } |
258 | 214 | fernando | |
259 | 21104 | vcaballero | public Rectangle2D getFullExtent() throws ReadException { |
260 | Rectangle2D rAux=null; |
||
261 | // source.start();
|
||
262 | // rAux = (Rectangle2D)source.getFullExtent().clone();
|
||
263 | // source.stop();
|
||
264 | //
|
||
265 | //
|
||
266 | // // Si existe reproyecci?n, reproyectar el extent
|
||
267 | // ICoordTrans ct = getCoordTrans();
|
||
268 | //
|
||
269 | // if (ct != null) {
|
||
270 | // Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY());
|
||
271 | // Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY());
|
||
272 | // pt1 = ct.convert(pt1, null);
|
||
273 | // pt2 = ct.convert(pt2, null);
|
||
274 | // rAux = new Rectangle2D.Double();
|
||
275 | // rAux.setFrameFromDiagonal(pt1, pt2);
|
||
276 | // }
|
||
277 | //
|
||
278 | // //Esto es para cuando se crea una capa nueva con el fullExtent de ancho y alto 0.
|
||
279 | // if (rAux.getWidth()==0 && rAux.getHeight()==0) {
|
||
280 | // rAux=new Rectangle2D.Double(0,0,100,100);
|
||
281 | // }
|
||
282 | 885 | fjp | |
283 | 12349 | jaume | return rAux;
|
284 | } |
||
285 | 214 | fernando | |
286 | 12466 | jaume | /**
|
287 | * Draws using IFeatureIterator. This method will replace the old draw(...) one.
|
||
288 | * @autor jaume dominguez faus - jaume.dominguez@iver.es
|
||
289 | * @param image
|
||
290 | * @param g
|
||
291 | * @param viewPort
|
||
292 | * @param cancel
|
||
293 | * @param scale
|
||
294 | * @throws ReadDriverException
|
||
295 | */
|
||
296 | 21104 | vcaballero | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
297 | Cancellable cancel, double scale) throws ReadException { |
||
298 | 14369 | jdominguez | boolean bDrawShapes = true; |
299 | if (legend instanceof SingleSymbolLegend) { |
||
300 | bDrawShapes = legend.getDefaultSymbol().isShapeVisible(); |
||
301 | } |
||
302 | 14452 | vcaballero | Point2D offset = viewPort.getOffset();
|
303 | 14369 | jdominguez | double dpi = MapContext.getScreenDPI();
|
304 | 12657 | jaume | |
305 | 15601 | vcaballero | |
306 | |||
307 | 14369 | jdominguez | if (bDrawShapes) {
|
308 | 15601 | vcaballero | boolean cacheFeatures = isSpatialCacheEnabled();
|
309 | SpatialCache cache = null;
|
||
310 | if (cacheFeatures) {
|
||
311 | getSpatialCache().clearAll(); |
||
312 | cache = getSpatialCache(); |
||
313 | } |
||
314 | 11704 | jaume | |
315 | 14369 | jdominguez | try {
|
316 | ArrayList<String> fieldList = new ArrayList<String>(); |
||
317 | 11704 | jaume | |
318 | 14369 | jdominguez | // fields from legend
|
319 | String[] aux = null; |
||
320 | 13445 | caballero | |
321 | 14369 | jdominguez | if (legend instanceof IClassifiedVectorLegend) { |
322 | aux = ((IClassifiedVectorLegend) legend).getClassifyingFieldNames(); |
||
323 | for (int i = 0; i < aux.length; i++) { |
||
324 | fieldList.add(aux[i]); |
||
325 | 13884 | jaume | } |
326 | 14369 | jdominguez | } |
327 | 21104 | vcaballero | FeatureStore featureStore=(FeatureStore)getDataStore(); |
328 | 18621 | jdominguez | // Get the iterator over the visible features
|
329 | 21104 | vcaballero | Iterator it =featureStore.getDataCollection(
|
330 | 18621 | jdominguez | fieldList.toArray(new String[fieldList.size()]), |
331 | 21104 | vcaballero | null,//filter |
332 | null).iterator();//order |
||
333 | |||
334 | |||
335 | // viewPort.getAdjustedExtent(),
|
||
336 | // fieldList.toArray(new String[fieldList.size()]),
|
||
337 | // viewPort.getProjection(),
|
||
338 | // true);
|
||
339 | |||
340 | 14369 | jdominguez | ZSort zSort = ((IVectorLegend) getLegend()).getZSort(); |
341 | 21104 | vcaballero | |
342 | 18621 | jdominguez | boolean bSymbolLevelError = false; |
343 | 21104 | vcaballero | |
344 | 14369 | jdominguez | // if layer has map levels it will use a ZSort
|
345 | boolean useZSort = zSort != null && zSort.isUsingZSort(); |
||
346 | 12075 | jaume | |
347 | 14369 | jdominguez | // -- visual FX stuff
|
348 | long time = System.currentTimeMillis(); |
||
349 | BufferedImage virtualBim;
|
||
350 | Graphics2D virtualGraphics;
|
||
351 | 11853 | jaume | |
352 | 14369 | jdominguez | // render temporary map each screenRefreshRate milliseconds;
|
353 | int screenRefreshDelay = (int) ((1D/MapControl.getDrawFrameRate())*3*1000); |
||
354 | BufferedImage[] imageLevels = null; |
||
355 | Graphics2D[] graphics = null; |
||
356 | if (useZSort) {
|
||
357 | imageLevels = new BufferedImage[zSort.getLevelCount()]; |
||
358 | graphics = new Graphics2D[imageLevels.length]; |
||
359 | for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) { |
||
360 | imageLevels[i] = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); |
||
361 | graphics[i] = imageLevels[i].createGraphics(); |
||
362 | 14409 | vcaballero | graphics[i].setTransform(g.getTransform()); |
363 | 20704 | vcaballero | graphics[i].setRenderingHints(g.getRenderingHints()); |
364 | 14369 | jdominguez | } |
365 | } |
||
366 | // -- end visual FX stuff
|
||
367 | 12466 | jaume | |
368 | 21104 | vcaballero | |
369 | 14369 | jdominguez | // Iteration over each feature
|
370 | while ( !cancel.isCanceled() && it.hasNext()) {
|
||
371 | 21104 | vcaballero | Feature feat = (Feature)it.next(); |
372 | Geometry geom = (Geometry)feat.getDefaultGeometry(); |
||
373 | 11853 | jaume | |
374 | 15601 | vcaballero | if (cacheFeatures) {
|
375 | if (cache.getMaxFeatures() >= cache.size()) {
|
||
376 | // already reprojected
|
||
377 | cache.insert(geom.getBounds2D(), geom); |
||
378 | } |
||
379 | } |
||
380 | |||
381 | 14369 | jdominguez | // retrieve the symbol associated to such feature
|
382 | ISymbol sym = legend.getSymbolByFeature(feat); |
||
383 | |||
384 | 18621 | jdominguez | if (sym == null) continue; |
385 | 21104 | vcaballero | |
386 | 14573 | vcaballero | //C?digo para poder acceder a los ?ndices para ver si est? seleccionado un Feature
|
387 | 21104 | vcaballero | // ReadableVectorial rv=getSource();
|
388 | // int selectionIndex=-1;
|
||
389 | // if (rv instanceof ISpatialDB){
|
||
390 | // selectionIndex=((ISpatialDB)rv).getRowIndexByFID(feat);
|
||
391 | // }else{
|
||
392 | // selectionIndex=Integer.parseInt(feat.getID());
|
||
393 | // }
|
||
394 | // if (selectionIndex!=-1) {
|
||
395 | // if (selectionSupport.isSelected(selectionIndex)) {
|
||
396 | // sym = sym.getSymbolForSelection();
|
||
397 | // }
|
||
398 | // }
|
||
399 | 14369 | jdominguez | |
400 | // Check if this symbol is sized with CartographicSupport
|
||
401 | CartographicSupport csSym = null;
|
||
402 | int symbolType = sym.getSymbolType();
|
||
403 | boolean bDrawCartographicSupport = false; |
||
404 | |||
405 | 21128 | vcaballero | if ( symbolType == Geometry.TYPES.POINT
|
406 | || symbolType == Geometry.TYPES.CURVE |
||
407 | 12466 | jaume | || sym instanceof CartographicSupport) {
|
408 | 11807 | jaume | |
409 | 18621 | jdominguez | // patch
|
410 | 14481 | vcaballero | if (!sym.getClass().equals(FSymbol.class)) {
|
411 | csSym = (CartographicSupport) sym; |
||
412 | bDrawCartographicSupport = (csSym.getUnit() != -1);
|
||
413 | } |
||
414 | 14369 | jdominguez | } |
415 | 11853 | jaume | |
416 | 14369 | jdominguez | int x = -1; |
417 | int y = -1; |
||
418 | int[] xyCoords = new int[2]; |
||
419 | 11853 | jaume | |
420 | 14369 | jdominguez | // Check if size is a pixel
|
421 | boolean onePoint = bDrawCartographicSupport ?
|
||
422 | 14409 | vcaballero | isOnePoint(g.getTransform(), viewPort, MapContext.getScreenDPI(), csSym, geom, xyCoords) : |
423 | isOnePoint(g.getTransform(), viewPort, geom, xyCoords); |
||
424 | 12466 | jaume | |
425 | 14409 | vcaballero | // Avoid out of bounds exceptions
|
426 | if (onePoint) {
|
||
427 | x = xyCoords[0];
|
||
428 | y = xyCoords[1];
|
||
429 | if (x<0 || y<0 || x>= viewPort.getImageWidth() || y>=viewPort.getImageHeight()) continue; |
||
430 | } |
||
431 | 13445 | caballero | |
432 | 14409 | vcaballero | if (useZSort) {
|
433 | // Check if this symbol is a multilayer
|
||
434 | if (sym instanceof IMultiLayerSymbol) { |
||
435 | // if so, treat each of its layers as a single symbol
|
||
436 | // in its corresponding map level
|
||
437 | IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym; |
||
438 | 20704 | vcaballero | for (int i = 0; !cancel.isCanceled() && i < mlSym.getLayerCount(); i++) { |
439 | 14409 | vcaballero | ISymbol mySym = mlSym.getLayer(i); |
440 | 18621 | jdominguez | int symbolLevel = zSort.getSymbolLevel(mySym);
|
441 | 21104 | vcaballero | |
442 | 18621 | jdominguez | if (symbolLevel == -1) { |
443 | /* an error occured when managing symbol levels
|
||
444 | * some of the legend changed events regarding the
|
||
445 | * symbols did not finish satisfactory and the legend
|
||
446 | * is now inconsistent. For this drawing, it will finish
|
||
447 | * as it was at the bottom (level 0) but, when done, the
|
||
448 | * ZSort will be reset to avoid app crashes. This is
|
||
449 | * a bug that has to be fixed.
|
||
450 | */
|
||
451 | bSymbolLevelError = true;
|
||
452 | symbolLevel=0;
|
||
453 | } |
||
454 | 21104 | vcaballero | |
455 | 14409 | vcaballero | if (onePoint) {
|
456 | 18621 | jdominguez | if (x<0 || y<0 || x>= imageLevels[symbolLevel].getWidth() || y>=imageLevels[symbolLevel].getHeight()) continue; |
457 | imageLevels[symbolLevel].setRGB(x, y, mySym.getOnePointRgb()); |
||
458 | 14409 | vcaballero | } else {
|
459 | if (!bDrawCartographicSupport) {
|
||
460 | 21104 | vcaballero | DrawOperationContext doc=new DrawOperationContext();
|
461 | doc.setGraphics(graphics[symbolLevel]); |
||
462 | doc.setViewPort(viewPort); |
||
463 | doc.setSymbol(mySym); |
||
464 | doc.setCancellable(cancel); |
||
465 | geom.invokeOperation(DrawInts.CODE,doc); |
||
466 | 14409 | vcaballero | } else {
|
467 | 21104 | vcaballero | DrawOperationContext doc=new DrawOperationContext();
|
468 | doc.setGraphics(graphics[symbolLevel]); |
||
469 | doc.setViewPort(viewPort); |
||
470 | doc.setSymbol(mySym); |
||
471 | doc.setCancellable(cancel); |
||
472 | doc.setDPI(dpi); |
||
473 | geom.invokeOperation(DrawInts.CODE,doc); |
||
474 | 14409 | vcaballero | } |
475 | } |
||
476 | } |
||
477 | } else {
|
||
478 | // else, just draw the symbol in its level
|
||
479 | if (!bDrawCartographicSupport) {
|
||
480 | 21104 | vcaballero | DrawOperationContext doc=new DrawOperationContext();
|
481 | doc.setGraphics(graphics[zSort.getSymbolLevel(sym)]); |
||
482 | doc.setViewPort(viewPort); |
||
483 | doc.setSymbol(sym); |
||
484 | doc.setCancellable(cancel); |
||
485 | geom.invokeOperation(DrawInts.CODE,doc); |
||
486 | 14409 | vcaballero | } else {
|
487 | 21104 | vcaballero | DrawOperationContext doc=new DrawOperationContext();
|
488 | doc.setGraphics(graphics[zSort.getSymbolLevel(sym)]); |
||
489 | doc.setViewPort(viewPort); |
||
490 | doc.setSymbol((ISymbol)csSym); |
||
491 | doc.setCancellable(cancel); |
||
492 | doc.setDPI(dpi); |
||
493 | geom.invokeOperation(DrawInts.CODE,doc); |
||
494 | 14409 | vcaballero | } |
495 | } |
||
496 | 214 | fernando | |
497 | 14409 | vcaballero | // -- visual FX stuff
|
498 | 14452 | vcaballero | // Cuando el offset!=0 se est? dibujando sobre el Layout y por tanto no tiene que ejecutar el siguiente c?digo.
|
499 | if (offset.getX()==0 && offset.getY()==0) |
||
500 | if ((System.currentTimeMillis() - time) > screenRefreshDelay) { |
||
501 | virtualBim = new BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_INT_ARGB); |
||
502 | virtualGraphics = virtualBim.createGraphics(); |
||
503 | virtualGraphics.drawImage(image,0,0, null); |
||
504 | 20704 | vcaballero | for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) { |
505 | 14452 | vcaballero | virtualGraphics.drawImage(imageLevels[i],0,0, null); |
506 | } |
||
507 | g.clearRect(0, 0, image.getWidth(), image.getHeight()); |
||
508 | g.drawImage(virtualBim, 0, 0, null); |
||
509 | time = System.currentTimeMillis();
|
||
510 | } |
||
511 | 14409 | vcaballero | // -- end visual FX stuff
|
512 | 6246 | caballero | |
513 | 14409 | vcaballero | } else {
|
514 | // no ZSort, so there is only a map level, symbols are
|
||
515 | // just drawn.
|
||
516 | if (onePoint) {
|
||
517 | if (x<0 || y<0 || x>= image.getWidth() || y>=image.getHeight()) continue; |
||
518 | image.setRGB(x, y, sym.getOnePointRgb()); |
||
519 | } else {
|
||
520 | 21104 | vcaballero | |
521 | 14409 | vcaballero | if (!bDrawCartographicSupport) {
|
522 | 21104 | vcaballero | DrawOperationContext doc=new DrawOperationContext();
|
523 | doc.setGraphics(g); |
||
524 | doc.setViewPort(viewPort); |
||
525 | doc.setSymbol(sym); |
||
526 | doc.setCancellable(cancel); |
||
527 | geom.invokeOperation(DrawInts.CODE,doc); |
||
528 | 14409 | vcaballero | } else {
|
529 | 21104 | vcaballero | DrawOperationContext doc=new DrawOperationContext();
|
530 | doc.setGraphics(g); |
||
531 | doc.setViewPort(viewPort); |
||
532 | doc.setSymbol((ISymbol)csSym); |
||
533 | doc.setCancellable(cancel); |
||
534 | doc.setDPI(dpi); |
||
535 | geom.invokeOperation(DrawInts.CODE,doc); |
||
536 | 14409 | vcaballero | } |
537 | } |
||
538 | } |
||
539 | 14369 | jdominguez | } |
540 | 650 | vcaballero | |
541 | 14369 | jdominguez | if (useZSort) {
|
542 | g.drawImage(image, 0, 0, null); |
||
543 | 14409 | vcaballero | g.translate(offset.getX(), offset.getY()); |
544 | 20704 | vcaballero | for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) { |
545 | 14369 | jdominguez | g.drawImage(imageLevels[i],0,0, null); |
546 | imageLevels[i] = null;
|
||
547 | graphics[i] = null;
|
||
548 | 12349 | jaume | } |
549 | 14409 | vcaballero | g.translate(-offset.getX(), -offset.getY()); |
550 | 14369 | jdominguez | imageLevels = null;
|
551 | graphics = null;
|
||
552 | } |
||
553 | 21104 | vcaballero | // it.closeIterator();
|
554 | |||
555 | 18621 | jdominguez | if (bSymbolLevelError) {
|
556 | ((IVectorLegend) getLegend()).setZSort(null);
|
||
557 | } |
||
558 | 21104 | vcaballero | |
559 | } catch (ReadException e) {
|
||
560 | 14369 | jdominguez | this.setVisible(false); |
561 | this.setActive(false); |
||
562 | throw e;
|
||
563 | 21104 | vcaballero | } catch (GeometryOperationNotSupportedException e) {
|
564 | this.setVisible(false); |
||
565 | this.setActive(false); |
||
566 | throw new ReadException(getName(),e); |
||
567 | } catch (GeometryOperationException e) {
|
||
568 | this.setVisible(false); |
||
569 | this.setActive(false); |
||
570 | throw new ReadException(getName(),e); |
||
571 | } |
||
572 | 11807 | jaume | |
573 | 5484 | caballero | |
574 | 12349 | jaume | } |
575 | } |
||
576 | 5484 | caballero | |
577 | 21104 | vcaballero | // public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
|
578 | // Cancellable cancel, double scale) throws ReadException {
|
||
579 | //// forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD = true;
|
||
580 | // if (!isUseStrategy()) {
|
||
581 | // _draw(image, g, viewPort, cancel, scale);
|
||
582 | // } else {
|
||
583 | //// moved up to FLayers
|
||
584 | //// if (isWithinScale(scale)) {
|
||
585 | //
|
||
586 | //
|
||
587 | // // Las que solo tienen etiquetado sin pintar el shape,
|
||
588 | // // no pasamos por ellas
|
||
589 | // boolean bDrawShapes = true;
|
||
590 | // if (legend instanceof SingleSymbolLegend) {
|
||
591 | // if (legend.getDefaultSymbol().isShapeVisible() == false)
|
||
592 | // bDrawShapes = false;
|
||
593 | // }
|
||
594 | // if (bDrawShapes) {
|
||
595 | // Strategy strategy = StrategyManager.getStrategy(this);
|
||
596 | // try {
|
||
597 | // prepareDrawing(image, g, viewPort);
|
||
598 | // strategy.draw(image, g, viewPort, cancel);
|
||
599 | // } catch (ReadDriverException e) {
|
||
600 | // this.setVisible(false);
|
||
601 | // this.setActive(false);
|
||
602 | // throw e;
|
||
603 | // }
|
||
604 | // }
|
||
605 | // if (getVirtualLayers() != null) {
|
||
606 | // getVirtualLayers().draw(image, g, viewPort, cancel, scale);
|
||
607 | // }
|
||
608 | //// }
|
||
609 | // }
|
||
610 | // }
|
||
611 | |||
612 | 12349 | jaume | /**
|
613 | * Se llama antes de empezar a pintar.
|
||
614 | * Es ?til para preparar la cache a emplear, las leyendas, etc.
|
||
615 | * @param image
|
||
616 | * @param g
|
||
617 | * @param viewPort
|
||
618 | */
|
||
619 | private void prepareDrawing(BufferedImage image, Graphics2D g, ViewPort viewPort) { |
||
620 | |||
621 | } |
||
622 | |||
623 | 21104 | vcaballero | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
624 | double scale, PrintRequestAttributeSet properties) throws ReadException { |
||
625 | 12657 | jaume | // TEST METHOD
|
626 | |||
627 | 21104 | vcaballero | |
628 | 18621 | jdominguez | /* SVN */
|
629 | 21104 | vcaballero | |
630 | 18621 | jdominguez | /* boolean bDrawShapes = true;
|
631 | 12657 | jaume | if (legend instanceof SingleSymbolLegend) {
|
632 | bDrawShapes = legend.getDefaultSymbol().isShapeVisible();
|
||
633 | }
|
||
634 | |||
635 | |||
636 | if (bDrawShapes) {
|
||
637 | double dpi = 72;
|
||
638 | |||
639 | PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class);
|
||
640 | if (resolution.equals(PrintQuality.NORMAL)){
|
||
641 | dpi = 300;
|
||
642 | } else if (resolution.equals(PrintQuality.HIGH)){
|
||
643 | dpi = 600;
|
||
644 | } else if (resolution.equals(PrintQuality.DRAFT)){
|
||
645 | dpi = 72;
|
||
646 | }
|
||
647 | |||
648 | |||
649 | try {
|
||
650 | prepareDrawing(null, g, viewPort);
|
||
651 | 13884 | jaume | ArrayList<String> fieldList = new ArrayList<String>();
|
652 | String[] aux;
|
||
653 | 14409 | vcaballero | |
654 | 12657 | jaume | // fields from legend
|
655 | 13884 | jaume | if (legend instanceof IClassifiedVectorLegend) {
|
656 | aux = ((IClassifiedVectorLegend) legend).
|
||
657 | getClassifyingFieldNames();
|
||
658 | for (int i = 0; i < aux.length; i++) {
|
||
659 | fieldList.add(aux[i]);
|
||
660 | }
|
||
661 | 12657 | jaume | }
|
662 | |||
663 | // fields from labeling
|
||
664 | if (isLabeled()) {
|
||
665 | aux = getLabelingStrategy().getUsedFields();
|
||
666 | for (int i = 0; i < aux.length; i++) {
|
||
667 | fieldList.add(aux[i]);
|
||
668 | }
|
||
669 | }
|
||
670 | |||
671 | 13884 | jaume | ZSort zSort = ((IVectorLegend) getLegend()).getZSort();
|
672 | 12657 | jaume | |
673 | // if layer has map levels it will use a ZSort
|
||
674 | boolean useZSort = zSort != null && zSort.isUsingZSort();
|
||
675 | |||
676 | |||
677 | int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1;
|
||
678 | for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) {
|
||
679 | // Get the iterator over the visible features
|
||
680 | IFeatureIterator it = getSource().getFeatureIterator(
|
||
681 | viewPort.getAdjustedExtent(),
|
||
682 | 13884 | jaume | fieldList.toArray(new String[fieldList.size()]),
|
683 | 12657 | jaume | viewPort.getProjection(),
|
684 | true);
|
||
685 | |||
686 | // Iteration over each feature
|
||
687 | while ( !cancel.isCanceled() && it.hasNext()) {
|
||
688 | IFeature feat = it.next();
|
||
689 | IGeometry geom = feat.getGeometry();
|
||
690 | |||
691 | // retreive the symbol associated to such feature
|
||
692 | ISymbol sym = legend.getSymbolByFeature(feat);
|
||
693 | 14409 | vcaballero | |
694 | 14369 | jdominguez | if (useZSort) {
|
695 | // Check if this symbol is a multilayer
|
||
696 | if (sym instanceof IMultiLayerSymbol) {
|
||
697 | // if so, get the layer corresponding to the current
|
||
698 | // level. If none, continue to next iteration
|
||
699 | IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
|
||
700 | for (int i = 0; i < mlSym.getLayerCount(); i++) {
|
||
701 | ISymbol mySym = mlSym.getLayer(i);
|
||
702 | if (zSort.getSymbolLevel(mySym) == mapPass) {
|
||
703 | sym = mySym;
|
||
704 | break;
|
||
705 | }
|
||
706 | System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")");
|
||
707 | }
|
||
708 | 14409 | vcaballero | |
709 | 14369 | jdominguez | if (sym == null) {
|
710 | continue;
|
||
711 | }
|
||
712 | } else {
|
||
713 | // else, just draw the symbol in its level
|
||
714 | if (zSort.getSymbolLevel(sym) != mapPass) {
|
||
715 | System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")");
|
||
716 | continue;
|
||
717 | }
|
||
718 | }
|
||
719 | }
|
||
720 | 12657 | jaume | |
721 | // Check if this symbol is sized with CartographicSupport
|
||
722 | CartographicSupport csSym = null;
|
||
723 | int symbolType = sym.getSymbolType();
|
||
724 | boolean bDrawCartographicSupport = false;
|
||
725 | |||
726 | if ( symbolType == FShape.POINT
|
||
727 | || symbolType == FShape.LINE
|
||
728 | || sym instanceof CartographicSupport) {
|
||
729 | |||
730 | csSym = (CartographicSupport) sym;
|
||
731 | bDrawCartographicSupport = (csSym.getUnit() != -1);
|
||
732 | }
|
||
733 | 14409 | vcaballero | |
734 | 14369 | jdominguez | System.err.println("passada "+mapPass+" pinte s?mboll "+sym.getDescription());
|
735 | 12657 | jaume | |
736 | if (!bDrawCartographicSupport) {
|
||
737 | 13952 | jaume | geom.drawInts(g, viewPort, sym, null);
|
738 | 12657 | jaume | } else {
|
739 | geom.drawInts(g, viewPort, dpi, (CartographicSupport) csSym);
|
||
740 | }
|
||
741 | |||
742 | }
|
||
743 | it.closeIterator();
|
||
744 | }
|
||
745 | } catch (ReadDriverException e) {
|
||
746 | this.setVisible(false);
|
||
747 | this.setActive(false);
|
||
748 | throw e;
|
||
749 | 14409 | vcaballero | }
|
750 | 18621 | jdominguez | */
|
751 | 21104 | vcaballero | |
752 | |||
753 | 18621 | jdominguez | // TEST METHOD
|
754 | boolean bDrawShapes = true; |
||
755 | if (legend instanceof SingleSymbolLegend) { |
||
756 | bDrawShapes = legend.getDefaultSymbol().isShapeVisible(); |
||
757 | 12657 | jaume | } |
758 | 18621 | jdominguez | |
759 | |||
760 | if (bDrawShapes) {
|
||
761 | |||
762 | try {
|
||
763 | double dpi = 72; |
||
764 | |||
765 | PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class); |
||
766 | if (resolution.equals(PrintQuality.NORMAL)){ |
||
767 | dpi = 300;
|
||
768 | } else if (resolution.equals(PrintQuality.HIGH)){ |
||
769 | dpi = 600;
|
||
770 | } else if (resolution.equals(PrintQuality.DRAFT)){ |
||
771 | dpi = 72;
|
||
772 | } |
||
773 | ArrayList<String> fieldList = new ArrayList<String>(); |
||
774 | String[] aux; |
||
775 | |||
776 | // fields from legend
|
||
777 | if (legend instanceof IClassifiedVectorLegend) { |
||
778 | aux = ((IClassifiedVectorLegend) legend). |
||
779 | getClassifyingFieldNames(); |
||
780 | for (int i = 0; i < aux.length; i++) { |
||
781 | fieldList.add(aux[i]); |
||
782 | } |
||
783 | } |
||
784 | //
|
||
785 | // // fields from labeling
|
||
786 | // if (isLabeled()) {
|
||
787 | // aux = getLabelingStrategy().getUsedFields();
|
||
788 | // for (int i = 0; i < aux.length; i++) {
|
||
789 | // fieldList.add(aux[i]);
|
||
790 | // }
|
||
791 | // }
|
||
792 | |||
793 | ZSort zSort = ((IVectorLegend) getLegend()).getZSort(); |
||
794 | |||
795 | // if layer has map levels it will use a ZSort
|
||
796 | boolean useZSort = zSort != null && zSort.isUsingZSort(); |
||
797 | |||
798 | |||
799 | int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1; |
||
800 | for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) { |
||
801 | // Get the iterator over the visible features
|
||
802 | 21104 | vcaballero | FeatureStore featureStore=(FeatureStore)getDataStore(); |
803 | // Get the iterator over the visible features
|
||
804 | Iterator it =featureStore.getDataCollection(
|
||
805 | fieldList.toArray(new String[fieldList.size()]), |
||
806 | null,//filter |
||
807 | null).iterator();//order |
||
808 | 18621 | jdominguez | |
809 | 21104 | vcaballero | // viewPort.getAdjustedExtent(),
|
810 | // fieldList.toArray(new String[fieldList.size()]),
|
||
811 | // viewPort.getProjection(),
|
||
812 | // true);
|
||
813 | |||
814 | 18621 | jdominguez | // Iteration over each feature
|
815 | while ( !cancel.isCanceled() && it.hasNext()) {
|
||
816 | 21104 | vcaballero | Feature feat = (Feature)it.next(); |
817 | Geometry geom = (Geometry)feat.getDefaultGeometry(); |
||
818 | 18621 | jdominguez | |
819 | // retreive the symbol associated to such feature
|
||
820 | ISymbol sym = legend.getSymbolByFeature(feat); |
||
821 | |||
822 | if (useZSort) {
|
||
823 | // Check if this symbol is a multilayer
|
||
824 | if (sym instanceof IMultiLayerSymbol) { |
||
825 | // if so, get the layer corresponding to the current
|
||
826 | // level. If none, continue to next iteration
|
||
827 | IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym; |
||
828 | for (int i = 0; i < mlSym.getLayerCount(); i++) { |
||
829 | ISymbol mySym = mlSym.getLayer(i); |
||
830 | if (zSort.getSymbolLevel(mySym) == mapPass) {
|
||
831 | sym = mySym; |
||
832 | break;
|
||
833 | } |
||
834 | System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")"); |
||
835 | } |
||
836 | |||
837 | if (sym == null) { |
||
838 | continue;
|
||
839 | } |
||
840 | } else {
|
||
841 | // else, just draw the symbol in its level
|
||
842 | if (zSort.getSymbolLevel(sym) != mapPass) {
|
||
843 | System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")"); |
||
844 | continue;
|
||
845 | } |
||
846 | } |
||
847 | } |
||
848 | |||
849 | // Check if this symbol is sized with CartographicSupport
|
||
850 | CartographicSupport csSym = null;
|
||
851 | int symbolType = sym.getSymbolType();
|
||
852 | boolean bDrawCartographicSupport = false; |
||
853 | |||
854 | 21128 | vcaballero | if ( symbolType == Geometry.TYPES.POINT
|
855 | || symbolType == Geometry.TYPES.CURVE |
||
856 | 18621 | jdominguez | || sym instanceof CartographicSupport) {
|
857 | |||
858 | csSym = (CartographicSupport) sym; |
||
859 | bDrawCartographicSupport = (csSym.getUnit() != -1);
|
||
860 | } |
||
861 | |||
862 | System.err.println("passada "+mapPass+" pinte s?mboll "+sym.getDescription()); |
||
863 | |||
864 | if (!bDrawCartographicSupport) {
|
||
865 | 21104 | vcaballero | DrawOperationContext doc=new DrawOperationContext();
|
866 | doc.setGraphics(g); |
||
867 | doc.setViewPort(viewPort); |
||
868 | doc.setSymbol(sym); |
||
869 | doc.setCancellable(cancel); |
||
870 | geom.invokeOperation(DrawInts.CODE,doc); |
||
871 | } else {
|
||
872 | DrawOperationContext doc=new DrawOperationContext();
|
||
873 | doc.setGraphics(g); |
||
874 | doc.setViewPort(viewPort); |
||
875 | doc.setSymbol((ISymbol)csSym); |
||
876 | doc.setCancellable(cancel); |
||
877 | doc.setDPI(dpi); |
||
878 | geom.invokeOperation(DrawInts.CODE,doc); |
||
879 | } |
||
880 | 18621 | jdominguez | } |
881 | 21104 | vcaballero | // it.closeIterator();
|
882 | 18621 | jdominguez | } |
883 | 21104 | vcaballero | } catch (ReadException e) {
|
884 | 18621 | jdominguez | this.setVisible(false); |
885 | this.setActive(false); |
||
886 | throw e;
|
||
887 | 21104 | vcaballero | } catch (GeometryOperationNotSupportedException e) {
|
888 | this.setVisible(false); |
||
889 | this.setActive(false); |
||
890 | throw new ReadException(getName(),e); |
||
891 | } catch (GeometryOperationException e) {
|
||
892 | this.setVisible(false); |
||
893 | this.setActive(false); |
||
894 | throw new ReadException(getName(),e); |
||
895 | } |
||
896 | 18621 | jdominguez | } |
897 | 12349 | jaume | } |
898 | |||
899 | 12657 | jaume | |
900 | 21104 | vcaballero | // public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
|
901 | // double scale, PrintRequestAttributeSet properties) throws ReadException {
|
||
902 | // if (forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD) {
|
||
903 | // _print(g, viewPort, cancel, scale, properties);
|
||
904 | // } else {
|
||
905 | //// moved up to Flayers
|
||
906 | //// if (isVisible() && isWithinScale(scale)) {
|
||
907 | // Strategy strategy = StrategyManager.getStrategy(this);
|
||
908 | //
|
||
909 | // strategy.print(g, viewPort, cancel, properties);
|
||
910 | // ILabelingStrategy labeling;
|
||
911 | // if ( (labeling = getLabelingStrategy() ) != null) {
|
||
912 | // // contains labels
|
||
913 | // labeling.print(g, viewPort, cancel, properties);
|
||
914 | // }
|
||
915 | //// }
|
||
916 | // }
|
||
917 | // }
|
||
918 | 12349 | jaume | |
919 | public void deleteSpatialIndex() { |
||
920 | //must we delete possible spatial indexes files?
|
||
921 | spatialIndex = null;
|
||
922 | } |
||
923 | |||
924 | 5414 | azabala | /**
|
925 | * <p>
|
||
926 | * Creates an spatial index associated to this layer.
|
||
927 | * The spatial index will used
|
||
928 | * the native projection of the layer, so if the layer is reprojected, it will
|
||
929 | * be ignored.
|
||
930 | * </p>
|
||
931 | * @param cancelMonitor instance of CancellableMonitorable that allows
|
||
932 | * to monitor progress of spatial index creation, and cancel the process
|
||
933 | 5484 | caballero | */
|
934 | 21104 | vcaballero | // public void createSpatialIndex(CancellableMonitorable cancelMonitor){
|
935 | // // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
||
936 | // // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
||
937 | // // para que acepten recorrer sin geometria, solo con rectangulos.
|
||
938 | //
|
||
939 | // //If this vectorial layer is based in a spatial database, the spatial
|
||
940 | // //index is already implicit. We only will index file drivers
|
||
941 | // ReadableVectorial va = getSource();
|
||
942 | // //We must think in non spatial databases, like HSQLDB
|
||
943 | // if(!(va instanceof VectorialFileAdapter)){
|
||
944 | // return;
|
||
945 | // }
|
||
946 | // if (!(va.getDriver() instanceof BoundedShapes)) {
|
||
947 | // return;
|
||
948 | // }
|
||
949 | // File file = ((VectorialFileAdapter) va).getFile();
|
||
950 | // String fileName = file.getAbsolutePath();
|
||
951 | // ISpatialIndex localCopy = null;
|
||
952 | // try {
|
||
953 | // va.start();
|
||
954 | // localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(),
|
||
955 | // va.getShapeCount(), true);
|
||
956 | //
|
||
957 | // } catch (SpatialIndexException e1) {
|
||
958 | // // Probably we dont have writing permissions
|
||
959 | // String directoryName = System.getProperty("java.io.tmpdir");
|
||
960 | // File newFile = new File(directoryName +
|
||
961 | // File.separator +
|
||
962 | // file.getName());
|
||
963 | // String newFileName = newFile.getName();
|
||
964 | // try {
|
||
965 | // localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(),
|
||
966 | // va.getShapeCount(), true);
|
||
967 | // } catch (SpatialIndexException e) {
|
||
968 | // // if we cant build a file based spatial index, we'll build
|
||
969 | // // a pure memory spatial index
|
||
970 | // localCopy = new QuadtreeJts();
|
||
971 | // } catch (ReadException e) {
|
||
972 | // localCopy = new QuadtreeJts();
|
||
973 | // }
|
||
974 | //
|
||
975 | // } catch(Exception e){
|
||
976 | // e.printStackTrace();
|
||
977 | // }//try
|
||
978 | // BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
|
||
979 | // try {
|
||
980 | // for (int i=0; i < va.getShapeCount(); i++)
|
||
981 | // {
|
||
982 | // if(cancelMonitor != null){
|
||
983 | // if(cancelMonitor.isCanceled())
|
||
984 | // return;
|
||
985 | // cancelMonitor.reportStep();
|
||
986 | // }
|
||
987 | // Rectangle2D r = shapeBounds.getShapeBounds(i);
|
||
988 | // if(r != null)
|
||
989 | // localCopy.insert(r, i);
|
||
990 | // } // for
|
||
991 | // va.stop();
|
||
992 | // if(localCopy instanceof IPersistentSpatialIndex)
|
||
993 | // ((IPersistentSpatialIndex) localCopy).flush();
|
||
994 | // spatialIndex = localCopy;
|
||
995 | // //vectorial adapter needs a reference to the spatial index, to solve
|
||
996 | // //request for feature iteration based in spatial queries
|
||
997 | // source.setSpatialIndex(spatialIndex);
|
||
998 | // } catch (ReadException e) {
|
||
999 | // // TODO Auto-generated catch block
|
||
1000 | // e.printStackTrace();
|
||
1001 | // }
|
||
1002 | // }
|
||
1003 | 5484 | caballero | |
1004 | 21104 | vcaballero | // public void createSpatialIndex() {
|
1005 | // createSpatialIndex(null);
|
||
1006 | // }
|
||
1007 | 5484 | caballero | |
1008 | 21104 | vcaballero | public void process(FeaturesVisitor visitor, FeatureCollection collection) |
1009 | throws ReadException {
|
||
1010 | try {
|
||
1011 | collection.accept(visitor); |
||
1012 | } catch (BaseException e) {
|
||
1013 | throw new ReadException(getName(),e); |
||
1014 | } |
||
1015 | // Strategy s = StrategyManager.getStrategy(this);
|
||
1016 | // s.process(visitor, subset);
|
||
1017 | } |
||
1018 | 5115 | caballero | |
1019 | 21104 | vcaballero | public void process(FeaturesVisitor visitor) throws ReadException { |
1020 | FeatureCollection collection=(FeatureCollection)((FeatureStore)getDataStore()).getDataCollection(); |
||
1021 | 5414 | azabala | try {
|
1022 | 21104 | vcaballero | collection.accept(visitor); |
1023 | } catch (BaseException e) {
|
||
1024 | throw new ReadException(getName(),e); |
||
1025 | } |
||
1026 | 5414 | azabala | } |
1027 | 5484 | caballero | |
1028 | 21104 | vcaballero | // public void process(FeaturesVisitor visitor, Rectangle2D rect)
|
1029 | // throws ReadException {
|
||
1030 | // Strategy s = StrategyManager.getStrategy(this);
|
||
1031 | // s.process(visitor, rect);
|
||
1032 | // }
|
||
1033 | 214 | fernando | |
1034 | 21104 | vcaballero | // public FBitSet queryByRect(Rectangle2D rect) throws ReadException {
|
1035 | // Strategy s = StrategyManager.getStrategy(this);
|
||
1036 | //
|
||
1037 | // return s.queryByRect(rect);
|
||
1038 | // }
|
||
1039 | 228 | fernando | |
1040 | 21104 | vcaballero | // public FBitSet queryByPoint(Point2D p, double tolerance)
|
1041 | // throws ReadException {
|
||
1042 | // Strategy s = StrategyManager.getStrategy(this);
|
||
1043 | // return s.queryByPoint(p, tolerance);
|
||
1044 | // }
|
||
1045 | 4223 | caballero | |
1046 | 21104 | vcaballero | // public FBitSet queryByShape(Geometry g, int relationship)
|
1047 | // throws ReadException {
|
||
1048 | // Strategy s = StrategyManager.getStrategy(this);
|
||
1049 | // return s.queryByShape(g, relationship);
|
||
1050 | // }
|
||
1051 | 562 | fernando | |
1052 | 21104 | vcaballero | // public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws ReadDriverException, VisitorException {
|
1053 | // Point2D pReal = this.getMapContext().getViewPort().toMapPoint(p);
|
||
1054 | // FBitSet bs = queryByPoint(pReal, tolerance);
|
||
1055 | // VectorialXMLItem[] item = new VectorialXMLItem[1];
|
||
1056 | // item[0] = new VectorialXMLItem(bs, this);
|
||
1057 | //
|
||
1058 | // return item;
|
||
1059 | // }
|
||
1060 | 562 | fernando | |
1061 | 13884 | jaume | public void setLegend(IVectorLegend r) throws LegendLayerException { |
1062 | IVectorLegend oldLegend = legend; |
||
1063 | 12349 | jaume | legend = r; |
1064 | try {
|
||
1065 | 21144 | vcaballero | legend.setFeatureStore(getFeatureStore()); |
1066 | 21104 | vcaballero | } catch (ReadException e1) {
|
1067 | 12349 | jaume | throw new LegendLayerException(getName(),e1); |
1068 | } |
||
1069 | LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent( |
||
1070 | oldLegend, legend); |
||
1071 | callLegendChanged(e); |
||
1072 | } |
||
1073 | 303 | fernando | |
1074 | 12349 | jaume | /**
|
1075 | * Devuelve la Leyenda de la capa.
|
||
1076 | *
|
||
1077 | * @return Leyenda.
|
||
1078 | */
|
||
1079 | public ILegend getLegend() {
|
||
1080 | return legend;
|
||
1081 | } |
||
1082 | 373 | fernando | |
1083 | 12349 | jaume | /**
|
1084 | * Devuelve el tipo de shape que contiene la capa.
|
||
1085 | *
|
||
1086 | * @return tipo de shape.
|
||
1087 | *
|
||
1088 | * @throws DriverException
|
||
1089 | */
|
||
1090 | 21104 | vcaballero | public int getShapeType() throws ReadException { |
1091 | 12349 | jaume | if (typeShape == -1) { |
1092 | 21104 | vcaballero | // getSource().start();
|
1093 | typeShape = ((FeatureType)((FeatureStore)getDataStore()).getFeatureTypes().get(0)).getGeometryTypes()[0]; |
||
1094 | // getSource().stop();
|
||
1095 | 12349 | jaume | } |
1096 | 562 | fernando | |
1097 | 12349 | jaume | return typeShape;
|
1098 | } |
||
1099 | 435 | vcaballero | |
1100 | 12349 | jaume | public XMLEntity getXMLEntity() throws XMLException { |
1101 | 21104 | vcaballero | // if (!this.isAvailable() && this.orgXMLEntity != null) {
|
1102 | // return this.orgXMLEntity;
|
||
1103 | // }
|
||
1104 | // XMLEntity xml = super.getXMLEntity();
|
||
1105 | // if (getLegend()!=null)
|
||
1106 | // xml.addChild(getLegend().getXMLEntity());
|
||
1107 | // try {
|
||
1108 | // if (getRecordset()!=null)
|
||
1109 | // xml.addChild(getRecordset().getSelectionSupport().getXMLEntity());
|
||
1110 | // } catch (ReadException e1) {
|
||
1111 | // e1.printStackTrace();
|
||
1112 | // throw new XMLException(e1);
|
||
1113 | // }
|
||
1114 | // // Repongo el mismo ReadableVectorial m?s abajo para cuando se guarda el proyecto.
|
||
1115 | // ReadableVectorial rv=getSource();
|
||
1116 | // xml.putProperty("type", "vectorial");
|
||
1117 | // if (source instanceof VectorialEditableAdapter) {
|
||
1118 | // setSource(((VectorialEditableAdapter) source).getOriginalAdapter());
|
||
1119 | // }
|
||
1120 | // if (source instanceof VectorialFileAdapter) {
|
||
1121 | // xml.putProperty("type", "vectorial");
|
||
1122 | // xml.putProperty("file", ((VectorialFileAdapter) source)
|
||
1123 | // .getFile());
|
||
1124 | // try {
|
||
1125 | // xml.putProperty("recordset-name", source.getRecordset()
|
||
1126 | // .getName());
|
||
1127 | // } catch (ReadException e) {
|
||
1128 | // throw new XMLException(e);
|
||
1129 | // } catch (RuntimeException e) {
|
||
1130 | // e.printStackTrace();
|
||
1131 | // }
|
||
1132 | // } else if (source instanceof VectorialDBAdapter) {
|
||
1133 | // xml.putProperty("type", "vectorial");
|
||
1134 | //
|
||
1135 | // IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) source
|
||
1136 | // .getDriver();
|
||
1137 | //
|
||
1138 | // // Guardamos el nombre del driver para poder recuperarlo
|
||
1139 | // // con el DriverManager de Fernando.
|
||
1140 | // xml.putProperty("db", dbDriver.getName());
|
||
1141 | // try {
|
||
1142 | // xml.putProperty("recordset-name", source.getRecordset()
|
||
1143 | // .getName());
|
||
1144 | // } catch (ReadException e) {
|
||
1145 | // throw new XMLException(e);
|
||
1146 | // } catch (RuntimeException e) {
|
||
1147 | // e.printStackTrace();
|
||
1148 | // }
|
||
1149 | // xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos
|
||
1150 | // // metido la leyenda y el
|
||
1151 | // // selection support
|
||
1152 | // } else if (source instanceof VectorialAdapter) {
|
||
1153 | // // Se supone que hemos hecho algo gen?rico.
|
||
1154 | // xml.putProperty("type", "vectorial");
|
||
1155 | //
|
||
1156 | // VectorialDriver driver = source.getDriver();
|
||
1157 | //
|
||
1158 | // // Guardamos el nombre del driver para poder recuperarlo
|
||
1159 | // // con el DriverManager de Fernando.
|
||
1160 | // xml.putProperty("other", driver.getName());
|
||
1161 | // // try {
|
||
1162 | // try {
|
||
1163 | // xml.putProperty("recordset-name", source.getRecordset()
|
||
1164 | // .getName());
|
||
1165 | // } catch (ReadException e) {
|
||
1166 | // throw new XMLException(e);
|
||
1167 | // } catch (RuntimeException e) {
|
||
1168 | // e.printStackTrace();
|
||
1169 | // }
|
||
1170 | // if (driver instanceof IPersistence) {
|
||
1171 | // // xml.putProperty("className", driver.getClass().getName());
|
||
1172 | // IPersistence persist = (IPersistence) driver;
|
||
1173 | // xml.addChild(persist.getXMLEntity()); // Tercer child. Antes
|
||
1174 | // // hemos metido la
|
||
1175 | // // leyenda y el
|
||
1176 | // // selection support
|
||
1177 | // }
|
||
1178 | // }
|
||
1179 | // if (rv!=null)
|
||
1180 | // setSource(rv);
|
||
1181 | // xml.putProperty("driverName", source.getDriver().getName());
|
||
1182 | // if (bHasJoin)
|
||
1183 | // xml.putProperty("hasJoin", "true");
|
||
1184 | //
|
||
1185 | // // properties from ILabelable
|
||
1186 | // xml.putProperty("isLabeled", isLabeled);
|
||
1187 | // if (strategy != null) {
|
||
1188 | // XMLEntity strategyXML = strategy.getXMLEntity();
|
||
1189 | // strategyXML.putProperty("Strategy", strategy.getClassName());
|
||
1190 | // xml.addChild(strategy.getXMLEntity());
|
||
1191 | // }
|
||
1192 | // xml.addChild(getLinkProperties().getXMLEntity());
|
||
1193 | // return xml;
|
||
1194 | return null; |
||
1195 | 12349 | jaume | } |
1196 | /*
|
||
1197 | * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
1198 | */
|
||
1199 | public void setXMLEntity(XMLEntity xml) throws XMLException { |
||
1200 | 21104 | vcaballero | // try {
|
1201 | // super.setXMLEntity(xml);
|
||
1202 | // XMLEntity legendXML = xml.getChild(0);
|
||
1203 | // IVectorLegend leg = LegendFactory.createFromXML(legendXML);
|
||
1204 | // /* (jaume) begin patch;
|
||
1205 | // * for backward compatibility purposes. Since gvSIG v1.1 labeling is
|
||
1206 | // * no longer managed by the Legend but by the ILabelingStrategy. The
|
||
1207 | // * following allows restoring older projects' labelings.
|
||
1208 | // */
|
||
1209 | // if (legendXML.contains("labelFieldName")) {
|
||
1210 | // String labelTextField = legendXML.getStringProperty("labelFieldName");
|
||
1211 | // if (labelTextField != null) {
|
||
1212 | // AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
|
||
1213 | // labeling.setLayer(this);
|
||
1214 | // labeling.setTextField(legendXML.getStringProperty("labelFieldName"));
|
||
1215 | // labeling.setHeightField(legendXML.getStringProperty("labelHeightFieldName"));
|
||
1216 | // labeling.setRotationField(legendXML.getStringProperty("labelRotationFieldName"));
|
||
1217 | // this.setLabelingStrategy(labeling);
|
||
1218 | // this.setIsLabeled(true);
|
||
1219 | // }
|
||
1220 | // }
|
||
1221 | // /* end patch */
|
||
1222 | // try {
|
||
1223 | // getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
||
1224 | // // JMVIVO: Esto sirve para algo????
|
||
1225 | // String recordsetName = xml.getStringProperty("recordset-name");
|
||
1226 | //
|
||
1227 | // LayerFactory.getDataSourceFactory().changeDataSourceName(
|
||
1228 | // getSource().getRecordset().getName(), recordsetName);
|
||
1229 | // } catch (NoSuchTableException e1) {
|
||
1230 | // this.setAvailable(false);
|
||
1231 | // throw new XMLException(e1);
|
||
1232 | // } catch (ReadException e1) {
|
||
1233 | // this.setAvailable(false);
|
||
1234 | // throw new XMLException(e1);
|
||
1235 | // }
|
||
1236 | // // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
||
1237 | // // el final
|
||
1238 | // // de la lectura del proyecto
|
||
1239 | // if (xml.contains("hasJoin")) {
|
||
1240 | // setIsJoined(true);
|
||
1241 | // PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1);
|
||
1242 | // } else {
|
||
1243 | // try {
|
||
1244 | // setLegend(leg);
|
||
1245 | // } catch (LegendLayerException e) {
|
||
1246 | // throw new XMLException(e);
|
||
1247 | // }
|
||
1248 | // }
|
||
1249 | //
|
||
1250 | // // set properties for ILabelable
|
||
1251 | // XMLEntity labelingXML = xml.firstChild("id", "LabelingStrategy");
|
||
1252 | // if (labelingXML!= null) {
|
||
1253 | // isLabeled = true;
|
||
1254 | // try {
|
||
1255 | // this.strategy = LabelingFactory.createStrategyFromXML(labelingXML, this);
|
||
1256 | // } catch (NotExistInXMLEntity neXMLEX) {
|
||
1257 | // // no strategy was set, just continue;
|
||
1258 | // logger.warn("Reached what should be unreachable code");
|
||
1259 | // }
|
||
1260 | // } else {
|
||
1261 | // isLabeled = false;
|
||
1262 | // }
|
||
1263 | //
|
||
1264 | // XMLEntity xmlLinkProperties=xml.firstChild("typeChild","linkProperties");
|
||
1265 | // if (xmlLinkProperties != null){
|
||
1266 | // getLinkProperties().setXMLEntity(xmlLinkProperties);
|
||
1267 | // }
|
||
1268 | //
|
||
1269 | // } catch (XMLException e) {
|
||
1270 | // this.setAvailable(false);
|
||
1271 | // this.orgXMLEntity = xml;
|
||
1272 | // } catch (Exception e) {
|
||
1273 | // e.printStackTrace();
|
||
1274 | // this.setAvailable(false);
|
||
1275 | // this.orgXMLEntity = xml;
|
||
1276 | //
|
||
1277 | // }
|
||
1278 | //
|
||
1279 | 6476 | caballero | |
1280 | 12349 | jaume | } |
1281 | 562 | fernando | |
1282 | 12349 | jaume | public void setXMLEntityNew(XMLEntity xml) throws XMLException { |
1283 | 21104 | vcaballero | // try {
|
1284 | // super.setXMLEntity(xml);
|
||
1285 | //
|
||
1286 | // XMLEntity legendXML = xml.getChild(0);
|
||
1287 | // IVectorLegend leg = LegendFactory.createFromXML(legendXML);
|
||
1288 | // /* (jaume) begin patch;
|
||
1289 | // * for backward compatibility purposes. Since gvSIG v1.1 labeling is
|
||
1290 | // * no longer managed by the Legend but by the ILabelingStrategy. The
|
||
1291 | // * following allows restoring older projects' labelings.
|
||
1292 | // */
|
||
1293 | // if (legendXML.contains("labelFieldHeight")) {
|
||
1294 | // AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
|
||
1295 | // labeling.setLayer(this);
|
||
1296 | // labeling.setTextField(legendXML.getStringProperty("labelFieldHeight"));
|
||
1297 | // labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
|
||
1298 | // this.setLabelingStrategy(labeling);
|
||
1299 | // this.setIsLabeled(true);
|
||
1300 | // }
|
||
1301 | // /* end patch */
|
||
1302 | // try {
|
||
1303 | // getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
||
1304 | //
|
||
1305 | // this.setLoadSelection(xml.getChild(1));
|
||
1306 | // } catch (ReadException e1) {
|
||
1307 | // this.setAvailable(false);
|
||
1308 | // throw new XMLException(e1);
|
||
1309 | // }
|
||
1310 | // // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
||
1311 | // // el final
|
||
1312 | // // de la lectura del proyecto
|
||
1313 | // if (xml.contains("hasJoin")) {
|
||
1314 | // setIsJoined(true);
|
||
1315 | // PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1);
|
||
1316 | // } else {
|
||
1317 | // this.setLoadLegend(leg);
|
||
1318 | // }
|
||
1319 | //
|
||
1320 | // } catch (XMLException e) {
|
||
1321 | // this.setAvailable(false);
|
||
1322 | // this.orgXMLEntity = xml;
|
||
1323 | // } catch (Exception e) {
|
||
1324 | // this.setAvailable(false);
|
||
1325 | // this.orgXMLEntity = xml;
|
||
1326 | // }
|
||
1327 | 6768 | jmvivo | |
1328 | 9010 | caballero | |
1329 | 12349 | jaume | } |
1330 | 9010 | caballero | |
1331 | 562 | fernando | |
1332 | 12349 | jaume | /**
|
1333 | * Sobreimplementaci?n del m?todo toString para que las bases de datos
|
||
1334 | * identifiquen la capa.
|
||
1335 | *
|
||
1336 | * @return DOCUMENT ME!
|
||
1337 | */
|
||
1338 | public String toString() { |
||
1339 | /*
|
||
1340 | * Se usa internamente para que la parte de datos identifique de forma
|
||
1341 | * un?voca las tablas
|
||
1342 | */
|
||
1343 | String ret = super.toString(); |
||
1344 | 911 | fernando | |
1345 | 12349 | jaume | return "layer" + ret.substring(ret.indexOf('@') + 1); |
1346 | } |
||
1347 | 2672 | fjp | |
1348 | 12349 | jaume | public boolean isJoined() { |
1349 | return bHasJoin;
|
||
1350 | } |
||
1351 | 5115 | caballero | |
1352 | 12349 | jaume | /**
|
1353 | * Returns if a layer is spatially indexed
|
||
1354 | *
|
||
1355 | * @return if this layer has the ability to proces spatial queries without
|
||
1356 | * secuential scans.
|
||
1357 | */
|
||
1358 | 21104 | vcaballero | // public boolean isSpatiallyIndexed() {
|
1359 | // ReadableVectorial source = getSource();
|
||
1360 | // if (source instanceof ISpatialDB)
|
||
1361 | // return true;
|
||
1362 | //
|
||
1363 | ////FIXME azabala
|
||
1364 | ///*
|
||
1365 | // * Esto es muy dudoso, y puede cambiar.
|
||
1366 | // * Estoy diciendo que las que no son fichero o no son
|
||
1367 | // * BoundedShapes estan indexadas. Esto es mentira, pero
|
||
1368 | // * as? quien pregunte no querr? generar el indice.
|
||
1369 | // * Esta por ver si interesa generar el indice para capas
|
||
1370 | // * HSQLDB, WFS, etc.
|
||
1371 | // */
|
||
1372 | // if(!(source instanceof VectorialFileAdapter)){
|
||
1373 | // return true;
|
||
1374 | // }
|
||
1375 | // if (!(source.getDriver() instanceof BoundedShapes)) {
|
||
1376 | // return true;
|
||
1377 | // }
|
||
1378 | //
|
||
1379 | // if (getISpatialIndex() != null)
|
||
1380 | // return true;
|
||
1381 | // return false;
|
||
1382 | // }
|
||
1383 | 6246 | caballero | |
1384 | 12349 | jaume | public void setIsJoined(boolean hasJoin) { |
1385 | bHasJoin = hasJoin; |
||
1386 | } |
||
1387 | 2978 | fjp | |
1388 | 21104 | vcaballero | // /**
|
1389 | // * @return Returns the spatialIndex.
|
||
1390 | // */
|
||
1391 | // public ISpatialIndex getISpatialIndex() {
|
||
1392 | // return spatialIndex;
|
||
1393 | // }
|
||
1394 | // /**
|
||
1395 | // * Sets the spatial index. This could be useful if, for some
|
||
1396 | // * reasons, you want to work with a distinct spatial index
|
||
1397 | // * (for example, a spatial index which could makes nearest
|
||
1398 | // * neighbour querys)
|
||
1399 | // * @param spatialIndex
|
||
1400 | // */
|
||
1401 | // public void setISpatialIndex(ISpatialIndex spatialIndex){
|
||
1402 | // this.spatialIndex = spatialIndex;
|
||
1403 | // }
|
||
1404 | 3366 | caballero | |
1405 | 21104 | vcaballero | // public SelectableDataSource getRecordset() throws ReadException {
|
1406 | // if (!this.isAvailable()) return null;
|
||
1407 | // if (sds == null) {
|
||
1408 | //
|
||
1409 | // SelectableDataSource ds = source.getRecordset();
|
||
1410 | //
|
||
1411 | // if (ds == null) {
|
||
1412 | // return null;
|
||
1413 | // }
|
||
1414 | //
|
||
1415 | // sds = ds;
|
||
1416 | // sds.setSelectionSupport(selectionSupport);
|
||
1417 | //
|
||
1418 | // }
|
||
1419 | // return sds;
|
||
1420 | // }
|
||
1421 | 10910 | jaume | |
1422 | 12349 | jaume | public void setEditing(boolean b) throws StartEditionLayerException { |
1423 | super.setEditing(b);
|
||
1424 | try {
|
||
1425 | 21104 | vcaballero | getDataStore().startEditing(); |
1426 | } catch (ReadException e) {
|
||
1427 | throw new StartEditionLayerException(getName(),e); |
||
1428 | } |
||
1429 | // try {
|
||
1430 | // if (b) {
|
||
1431 | // VectorialEditableAdapter vea = null;
|
||
1432 | // // TODO: Qu? pasa si hay m?s tipos de adapters?
|
||
1433 | // // FJP: Se podr?a pasar como argumento el
|
||
1434 | // // VectorialEditableAdapter
|
||
1435 | // // que se quiera usar para evitar meter c?digo aqu? de este
|
||
1436 | // // estilo.
|
||
1437 | // if (getSource() instanceof VectorialDBAdapter) {
|
||
1438 | // vea = new VectorialEditableDBAdapter();
|
||
1439 | // } else if (this instanceof FLyrAnnotation) {
|
||
1440 | // vea = new AnnotationEditableAdapter(
|
||
1441 | // (FLyrAnnotation) this);
|
||
1442 | // } else {
|
||
1443 | // vea = new VectorialEditableAdapter();
|
||
1444 | // }
|
||
1445 | // vea.setOriginalVectorialAdapter(getSource());
|
||
1446 | //// azo: implementations of readablevectorial need
|
||
1447 | // //references of projection and spatial index
|
||
1448 | // vea.setProjection(getProjection());
|
||
1449 | // vea.setSpatialIndex(spatialIndex);
|
||
1450 | //
|
||
1451 | //
|
||
1452 | // // /vea.setSpatialIndex(getSpatialIndex());
|
||
1453 | // // /vea.setFullExtent(getFullExtent());
|
||
1454 | // vea.setCoordTrans(getCoordTrans());
|
||
1455 | // vea.startEdition(EditionEvent.GRAPHIC);
|
||
1456 | // setSource(vea);
|
||
1457 | // getRecordset().setSelectionSupport(
|
||
1458 | // vea.getOriginalAdapter().getRecordset()
|
||
1459 | // .getSelectionSupport());
|
||
1460 | //
|
||
1461 | // } else {
|
||
1462 | // VectorialEditableAdapter vea = (VectorialEditableAdapter) getSource();
|
||
1463 | // setSource(vea.getOriginalAdapter());
|
||
1464 | // }
|
||
1465 | // // Si tenemos una leyenda, hay que pegarle el cambiazo a su
|
||
1466 | // // recordset
|
||
1467 | // setRecordset(getSource().getRecordset());
|
||
1468 | // if (getLegend() instanceof IVectorLegend) {
|
||
1469 | // IVectorLegend ley = (IVectorLegend) getLegend();
|
||
1470 | // ley.setDataSource(getSource().getRecordset());
|
||
1471 | // // Esto lo pongo para evitar que al dibujar sobre un
|
||
1472 | // // dxf, dwg, o dgn no veamos nada. Es debido al checkbox
|
||
1473 | // // de la leyenda de textos "dibujar solo textos".
|
||
1474 | ////jaume
|
||
1475 | //// if (!(getSource().getDriver() instanceof IndexedShpDriver)){
|
||
1476 | //// FSymbol symbol=new FSymbol(getShapeType());
|
||
1477 | //// symbol.setFontSizeInPixels(false);
|
||
1478 | //// symbol.setFont(new Font("SansSerif", Font.PLAIN, 9));
|
||
1479 | //// Color color=symbol.getColor();
|
||
1480 | //// int alpha=symbol.getColor().getAlpha();
|
||
1481 | //// if (alpha>250) {
|
||
1482 | //// symbol.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),100));
|
||
1483 | //// }
|
||
1484 | //// ley.setDefaultSymbol(symbol);
|
||
1485 | //// }
|
||
1486 | ////jaume//
|
||
1487 | // ley.useDefaultSymbol(true);
|
||
1488 | // }
|
||
1489 | // } catch (ReadDriverException e) {
|
||
1490 | // throw new StartEditionLayerException(getName(),e);
|
||
1491 | // } catch (FieldNotFoundException e) {
|
||
1492 | // throw new StartEditionLayerException(getName(),e);
|
||
1493 | // } catch (StartWriterVisitorException e) {
|
||
1494 | // throw new StartEditionLayerException(getName(),e);
|
||
1495 | // }
|
||
1496 | 11704 | jaume | |
1497 | 12349 | jaume | setSpatialCacheEnabled(b); |
1498 | callEditionChanged(LayerEvent |
||
1499 | .createEditionChangedEvent(this, "edition")); |
||
1500 | 5152 | fjp | |
1501 | 12349 | jaume | } |
1502 | 4147 | fjp | |
1503 | 12349 | jaume | /**
|
1504 | * Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
|
||
1505 | * forma, podr?s poner leyendas basadas en el nuevo recordset
|
||
1506 | *
|
||
1507 | * @param newSds
|
||
1508 | */
|
||
1509 | 21104 | vcaballero | // public void setRecordset(SelectableDataSource newSds) {
|
1510 | // sds = newSds;
|
||
1511 | // sds.setSelectionSupport(selectionSupport);
|
||
1512 | // }
|
||
1513 | 3366 | caballero | |
1514 | 12349 | jaume | public void clearSpatialCache() |
1515 | { |
||
1516 | spatialCache.clearAll(); |
||
1517 | } |
||
1518 | 5223 | fjp | |
1519 | 12349 | jaume | public boolean isSpatialCacheEnabled() { |
1520 | return spatialCacheEnabled;
|
||
1521 | } |
||
1522 | 5223 | fjp | |
1523 | 12349 | jaume | public void setSpatialCacheEnabled(boolean spatialCacheEnabled) { |
1524 | this.spatialCacheEnabled = spatialCacheEnabled;
|
||
1525 | } |
||
1526 | 5223 | fjp | |
1527 | 12349 | jaume | public SpatialCache getSpatialCache() {
|
1528 | return spatialCache;
|
||
1529 | } |
||
1530 | 5226 | fjp | |
1531 | 12349 | jaume | /**
|
1532 | * Siempre es un numero mayor de 1000
|
||
1533 | * @param maxFeatures
|
||
1534 | */
|
||
1535 | public void setMaxFeaturesInEditionCache(int maxFeatures) { |
||
1536 | 20989 | jmvivo | if (maxFeatures > spatialCache.getMaxFeatures())
|
1537 | 12349 | jaume | spatialCache.setMaxFeatures(maxFeatures); |
1538 | 6246 | caballero | |
1539 | 12349 | jaume | } |
1540 | 6246 | caballero | |
1541 | 12349 | jaume | /**
|
1542 | * This method returns a boolean that is used by the FPopMenu
|
||
1543 | * to make visible the properties menu or not. It is visible by
|
||
1544 | * default, and if a later don't have to show this menu only
|
||
1545 | * has to override this method.
|
||
1546 | * @return
|
||
1547 | * If the properties menu is visible (or not)
|
||
1548 | */
|
||
1549 | public boolean isPropertiesMenuVisible(){ |
||
1550 | return true; |
||
1551 | } |
||
1552 | 9010 | caballero | |
1553 | 12349 | jaume | public void reload() throws ReloadLayerException { |
1554 | this.setAvailable(true); |
||
1555 | super.reload();
|
||
1556 | 21104 | vcaballero | // try {
|
1557 | // this.source.getDriver().reload();
|
||
1558 | // if (this.getLegend() == null) {
|
||
1559 | // if (this.getRecordset().getDriver() instanceof WithDefaultLegend) {
|
||
1560 | // WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
||
1561 | // this.setLegend((IVectorLegend) aux.getDefaultLegend());
|
||
1562 | // this.setLabelingStrategy(aux.getDefaultLabelingStrategy());
|
||
1563 | // } else {
|
||
1564 | // this.setLegend(LegendFactory.createSingleSymbolLegend(
|
||
1565 | // this.getShapeType()));
|
||
1566 | // }
|
||
1567 | // }
|
||
1568 | //
|
||
1569 | // } catch (LegendLayerException e) {
|
||
1570 | // this.setAvailable(false);
|
||
1571 | // throw new ReloadLayerException(getName(),e);
|
||
1572 | // } catch (ReadException e) {
|
||
1573 | // this.setAvailable(false);
|
||
1574 | // throw new ReloadLayerException(getName(),e);
|
||
1575 | // }
|
||
1576 | 9010 | caballero | |
1577 | 12349 | jaume | } |
1578 | 9010 | caballero | |
1579 | 12349 | jaume | protected void setLoadSelection(XMLEntity xml) { |
1580 | this.loadSelection = xml;
|
||
1581 | } |
||
1582 | 5793 | fjp | |
1583 | 13884 | jaume | protected void setLoadLegend(IVectorLegend legend) { |
1584 | 12349 | jaume | this.loadLegend = legend;
|
1585 | } |
||
1586 | 6534 | jmvivo | |
1587 | 12349 | jaume | protected void putLoadSelection() throws XMLException { |
1588 | 21104 | vcaballero | // if (this.loadSelection == null) return;
|
1589 | // try {
|
||
1590 | // this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection);
|
||
1591 | // } catch (ReadDriverException e) {
|
||
1592 | // throw new XMLException(e);
|
||
1593 | // }
|
||
1594 | // this.loadSelection = null;
|
||
1595 | 9010 | caballero | |
1596 | 12349 | jaume | } |
1597 | protected void putLoadLegend() throws LegendLayerException { |
||
1598 | if (this.loadLegend == null) return; |
||
1599 | this.setLegend(this.loadLegend); |
||
1600 | this.loadLegend = null; |
||
1601 | } |
||
1602 | 6761 | jmvivo | |
1603 | 12349 | jaume | protected void cleanLoadOptions() { |
1604 | this.loadLegend = null; |
||
1605 | this.loadSelection = null; |
||
1606 | } |
||
1607 | 6761 | jmvivo | |
1608 | 12349 | jaume | public boolean isWritable() { |
1609 | 21104 | vcaballero | return getDataStore().isEditable();
|
1610 | // VectorialDriver drv = getSource().getDriver();
|
||
1611 | // if (!drv.isWritable())
|
||
1612 | // return false;
|
||
1613 | // if (drv instanceof IWriteable)
|
||
1614 | // {
|
||
1615 | // IWriter writer = ((IWriteable)drv).getWriter();
|
||
1616 | // if (writer != null)
|
||
1617 | // {
|
||
1618 | // if (writer instanceof ISpatialWriter)
|
||
1619 | // return true;
|
||
1620 | // }
|
||
1621 | // }
|
||
1622 | // return false;
|
||
1623 | 6856 | fjp | |
1624 | 12349 | jaume | } |
1625 | 6856 | fjp | |
1626 | 12349 | jaume | public FLayer cloneLayer() throws Exception { |
1627 | FLyrVect clonedLayer = new FLyrVect();
|
||
1628 | 21104 | vcaballero | clonedLayer.setDataStore(getDataStore()); |
1629 | 13445 | caballero | if (isJoined()) {
|
1630 | clonedLayer.setIsJoined(true);
|
||
1631 | 21104 | vcaballero | // clonedLayer.setRecordset(getRecordset());
|
1632 | 13445 | caballero | } |
1633 | 12349 | jaume | clonedLayer.setVisible(isVisible()); |
1634 | 21104 | vcaballero | // clonedLayer.setISpatialIndex(getISpatialIndex());
|
1635 | 12349 | jaume | clonedLayer.setName(getName()); |
1636 | clonedLayer.setCoordTrans(getCoordTrans()); |
||
1637 | 10627 | caballero | |
1638 | 13884 | jaume | clonedLayer.setLegend((IVectorLegend)getLegend().cloneLegend()); |
1639 | 10679 | jaume | |
1640 | 12349 | jaume | clonedLayer.setIsLabeled(isLabeled()); |
1641 | clonedLayer.setLabelingStrategy(getLabelingStrategy()); |
||
1642 | 10679 | jaume | |
1643 | 12349 | jaume | return clonedLayer;
|
1644 | } |
||
1645 | 9923 | fjp | |
1646 | 12657 | jaume | |
1647 | 21104 | vcaballero | private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, double dpi, CartographicSupport csSym, Geometry geom, int[] xyCoords) { |
1648 | 14409 | vcaballero | return isOnePoint(graphicsTransform, viewPort, geom, xyCoords) && csSym.getCartographicSize(viewPort, dpi, null) <= 1; |
1649 | 12466 | jaume | } |
1650 | |||
1651 | 21104 | vcaballero | private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, Geometry geom, int[] xyCoords) { |
1652 | 12466 | jaume | boolean onePoint = false; |
1653 | 21104 | vcaballero | int type=geom.getType() % Geometry.TYPES.Z;
|
1654 | if (type!=Geometry.TYPES.POINT && type!=Geometry.TYPES.MULTIPOINT) {
|
||
1655 | 12466 | jaume | |
1656 | Rectangle2D geomBounds = geom.getBounds2D();
|
||
1657 | |||
1658 | 20704 | vcaballero | ICoordTrans ct = getCoordTrans(); |
1659 | 12466 | jaume | |
1660 | 20704 | vcaballero | if (ct!=null) { |
1661 | // geomBounds = ct.getInverted().convert(geomBounds);
|
||
1662 | geomBounds = ct.convert(geomBounds); |
||
1663 | } |
||
1664 | 12466 | jaume | |
1665 | double dist1Pixel = viewPort.getDist1pixel();
|
||
1666 | |||
1667 | onePoint = (geomBounds.getWidth() <= dist1Pixel |
||
1668 | && geomBounds.getHeight() <= dist1Pixel); |
||
1669 | |||
1670 | if (onePoint) {
|
||
1671 | // avoid out of range exceptions
|
||
1672 | 21104 | vcaballero | org.gvsig.fmap.geom.primitive.Point2D p = new org.gvsig.fmap.geom.primitive.Point2D(geomBounds.getMinX(), geomBounds.getMinY());
|
1673 | 12466 | jaume | p.transform(viewPort.getAffineTransform()); |
1674 | 14409 | vcaballero | p.transform(graphicsTransform); |
1675 | 12466 | jaume | xyCoords[0] = (int) p.getX(); |
1676 | xyCoords[1] = (int) p.getY(); |
||
1677 | |||
1678 | } |
||
1679 | |||
1680 | 14409 | vcaballero | } |
1681 | 12466 | jaume | return onePoint;
|
1682 | } |
||
1683 | 12349 | jaume | /*
|
1684 | * jaume. Stuff from ILabeled.
|
||
1685 | */
|
||
1686 | private boolean isLabeled; |
||
1687 | private ILabelingStrategy strategy;
|
||
1688 | 10679 | jaume | |
1689 | 12349 | jaume | public boolean isLabeled() { |
1690 | return isLabeled;
|
||
1691 | } |
||
1692 | 10679 | jaume | |
1693 | 12349 | jaume | public void setIsLabeled(boolean isLabeled) { |
1694 | this.isLabeled = isLabeled;
|
||
1695 | } |
||
1696 | 10679 | jaume | |
1697 | 12349 | jaume | public ILabelingStrategy getLabelingStrategy() {
|
1698 | return strategy;
|
||
1699 | } |
||
1700 | 10679 | jaume | |
1701 | 12349 | jaume | public void setLabelingStrategy(ILabelingStrategy strategy) { |
1702 | this.strategy = strategy;
|
||
1703 | } |
||
1704 | 10679 | jaume | |
1705 | 12820 | jaume | public void drawLabels(BufferedImage image, Graphics2D g, ViewPort viewPort, |
1706 | 21104 | vcaballero | Cancellable cancel, double scale, double dpi) throws ReadException { |
1707 | 14450 | vcaballero | if (strategy!=null && isWithinScale(scale)) { |
1708 | 18621 | jdominguez | strategy.draw(image, g, viewPort, cancel, dpi); |
1709 | 12349 | jaume | } |
1710 | } |
||
1711 | 10679 | jaume | |
1712 | 13558 | evercher | |
1713 | |||
1714 | //M?todos para el uso de HyperLinks en capas FLyerVect
|
||
1715 | |||
1716 | /**
|
||
1717 | * Return true, because a Vectorial Layer supports HyperLink
|
||
1718 | */
|
||
1719 | public boolean allowLinks() |
||
1720 | { |
||
1721 | return true; |
||
1722 | } |
||
1723 | |||
1724 | /**
|
||
1725 | * Returns an instance of AbstractLinkProperties that contains the information
|
||
1726 | * of the HyperLink
|
||
1727 | * @return Abstra
|
||
1728 | */
|
||
1729 | public AbstractLinkProperties getLinkProperties()
|
||
1730 | { |
||
1731 | return linkProperties;
|
||
1732 | } |
||
1733 | |||
1734 | /**
|
||
1735 | * Provides an array with URIs. Returns one URI by geometry that includes the point
|
||
1736 | * in its own geometry limits with a allowed tolerance.
|
||
1737 | * @param layer, the layer
|
||
1738 | * @param point, the point to check that is contained or not in the geometries in the layer
|
||
1739 | * @param tolerance, the tolerance allowed. Allowed margin of error to detect if the point
|
||
1740 | * is contained in some geometries of the layer
|
||
1741 | * @return
|
||
1742 | 21114 | vcaballero | * @throws BehaviorException
|
1743 | 13558 | evercher | */
|
1744 | 21114 | vcaballero | public URI[] getLink(Point2D point, double tolerance) throws BehaviorException |
1745 | 13558 | evercher | { |
1746 | //return linkProperties.getLink(this)
|
||
1747 | return linkProperties.getLink(this,point,tolerance); |
||
1748 | } |
||
1749 | 21104 | vcaballero | // /**
|
1750 | // * @deprecated Don?t use Strategy, you should be use iterators.
|
||
1751 | // */
|
||
1752 | // public boolean isUseStrategy() {
|
||
1753 | // return useStrategy;
|
||
1754 | // }
|
||
1755 | // /**
|
||
1756 | // * @deprecated Don?t use Strategy, you should be use iterators.
|
||
1757 | // */
|
||
1758 | // public void setUseStrategy(boolean useStrategy) {
|
||
1759 | // this.useStrategy = useStrategy;
|
||
1760 | // }
|
||
1761 | 13558 | evercher | |
1762 | 16254 | vcaballero | public void load() throws LoadLayerException { |
1763 | super.load();
|
||
1764 | 21104 | vcaballero | // useStrategy=forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD;
|
1765 | 16254 | vcaballero | } |
1766 | |||
1767 | 21104 | vcaballero | public FeatureStore getFeatureStore() throws ReadException { |
1768 | return (FeatureStore)getDataStore();
|
||
1769 | } |
||
1770 | |||
1771 | 21155 | vcaballero | public FeatureCollection queryByPoint(Point2D mapPoint, double tol) { |
1772 | // TODO Auto-generated method stub
|
||
1773 | return null; |
||
1774 | } |
||
1775 | |||
1776 | public FeatureCollection queryByShape(Geometry geom) {
|
||
1777 | // TODO Auto-generated method stub
|
||
1778 | return null; |
||
1779 | } |
||
1780 | |||
1781 | public FeatureCollection queryByRect(Rectangle2D rect) { |
||
1782 | // TODO Auto-generated method stub
|
||
1783 | return null; |
||
1784 | } |
||
1785 | |||
1786 | 13749 | jaume | } |