svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / main / java / org / gvsig / fmap / mapcontext / layers / vectorial / FLyrVect.java @ 43020
History | View | Annotate | Download (42 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | 42289 | jjdelcerro | * This program is free software; you can redistribute it and/or modify it under
|
7 | * the terms of the GNU General Public License as published by the Free Software
|
||
8 | * Foundation; either version 3 of the License, or (at your option) any later
|
||
9 | * version.
|
||
10 | 40435 | jjdelcerro | *
|
11 | 42289 | jjdelcerro | * This program is distributed in the hope that it will be useful, but WITHOUT
|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
14 | * details.
|
||
15 | 40435 | jjdelcerro | *
|
16 | 42289 | jjdelcerro | * You should have received a copy of the GNU General Public License along with
|
17 | * this program; if not, write to the Free Software Foundation, Inc., 51
|
||
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
19 | 40435 | jjdelcerro | *
|
20 | 42289 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
23 | package org.gvsig.fmap.mapcontext.layers.vectorial; |
||
24 | |||
25 | import java.awt.Graphics2D; |
||
26 | import java.awt.Point; |
||
27 | import java.awt.geom.AffineTransform; |
||
28 | import java.awt.geom.Point2D; |
||
29 | import java.awt.image.BufferedImage; |
||
30 | 42293 | jjdelcerro | import java.util.Iterator; |
31 | 40435 | jjdelcerro | import java.util.Set; |
32 | import java.util.TreeSet; |
||
33 | 42972 | jjdelcerro | import java.util.logging.Level; |
34 | import java.util.logging.Logger; |
||
35 | 40435 | jjdelcerro | |
36 | import org.cresques.cts.ICoordTrans; |
||
37 | import org.cresques.cts.IProjection; |
||
38 | import org.slf4j.LoggerFactory; |
||
39 | |||
40 | import org.gvsig.compat.print.PrintAttributes; |
||
41 | 42972 | jjdelcerro | import org.gvsig.fmap.dal.DALLocator; |
42 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
43 | import org.gvsig.fmap.dal.exception.DataException; |
||
44 | 42972 | jjdelcerro | import org.gvsig.fmap.dal.exception.InitializeException; |
45 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.exception.ReadException; |
46 | 42877 | fdiaz | import org.gvsig.fmap.dal.exception.ReadRuntimeException; |
47 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
48 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
49 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
50 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
51 | import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
||
52 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
53 | import org.gvsig.fmap.dal.feature.exception.CreateGeometryException; |
||
54 | import org.gvsig.fmap.geom.Geometry; |
||
55 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
56 | import org.gvsig.fmap.geom.Geometry.TYPES; |
||
57 | import org.gvsig.fmap.geom.GeometryLocator; |
||
58 | import org.gvsig.fmap.geom.GeometryManager; |
||
59 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
60 | import org.gvsig.fmap.geom.primitive.Circle; |
||
61 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
62 | import org.gvsig.fmap.geom.type.GeometryType; |
||
63 | import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
||
64 | import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
||
65 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
66 | import org.gvsig.fmap.mapcontext.MapContextManager; |
||
67 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
68 | import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
||
69 | import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
||
70 | import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException; |
||
71 | import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException; |
||
72 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
73 | import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
||
74 | import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
||
75 | import org.gvsig.fmap.mapcontext.layers.SpatialCache; |
||
76 | import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
||
77 | import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
||
78 | import org.gvsig.fmap.mapcontext.rendering.legend.LegendException; |
||
79 | import org.gvsig.fmap.mapcontext.rendering.legend.events.FeatureDrawnNotification; |
||
80 | import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent; |
||
81 | import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent; |
||
82 | import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
||
83 | 42802 | jjdelcerro | import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendEvent; |
84 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
85 | import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
||
86 | import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
||
87 | import org.gvsig.metadata.exceptions.MetadataException; |
||
88 | import org.gvsig.tools.ToolsLocator; |
||
89 | import org.gvsig.tools.dynobject.DynObjectSet; |
||
90 | import org.gvsig.tools.dynobject.DynStruct; |
||
91 | 42820 | dmartinezizquierdo | import org.gvsig.tools.evaluator.Evaluator; |
92 | 40435 | jjdelcerro | import org.gvsig.tools.exception.BaseException; |
93 | 42877 | fdiaz | import org.gvsig.tools.exception.BaseRuntimeException; |
94 | 40435 | jjdelcerro | import org.gvsig.tools.locator.LocatorException; |
95 | import org.gvsig.tools.observer.Observable; |
||
96 | import org.gvsig.tools.observer.Observer; |
||
97 | import org.gvsig.tools.persistence.PersistenceManager; |
||
98 | import org.gvsig.tools.persistence.PersistentState; |
||
99 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
100 | import org.gvsig.tools.task.Cancellable; |
||
101 | 41840 | jjdelcerro | import org.gvsig.tools.util.Callable; |
102 | 40435 | jjdelcerro | |
103 | /**
|
||
104 | * Capa b?sica Vectorial.
|
||
105 | 42289 | jjdelcerro | *
|
106 | 40435 | jjdelcerro | */
|
107 | public class FLyrVect extends FLyrDefault implements VectorLayer, |
||
108 | 42289 | jjdelcerro | LegendContentsChangedListener, Observer {
|
109 | 40435 | jjdelcerro | |
110 | 42289 | jjdelcerro | final static private org.slf4j.Logger logger |
111 | = LoggerFactory.getLogger(FLyrVect.class); |
||
112 | private final GeometryManager geomManager |
||
113 | = GeometryLocator.getGeometryManager(); |
||
114 | 40435 | jjdelcerro | |
115 | 42289 | jjdelcerro | /**
|
116 | * Leyenda de la capa vectorial
|
||
117 | */
|
||
118 | 40435 | jjdelcerro | private IVectorLegend legend;
|
119 | private int typeShape = -1; |
||
120 | private FeatureStore featureStore = null; |
||
121 | private SpatialCache spatialCache = new SpatialCache(); |
||
122 | |||
123 | /**
|
||
124 | * An implementation of gvSIG spatial index
|
||
125 | */
|
||
126 | // protected ISpatialIndex spatialIndex = null;
|
||
127 | private IVectorLegend loadLegend = null; |
||
128 | |||
129 | private boolean isLabeled; |
||
130 | protected ILabelingStrategy strategy;
|
||
131 | // private ReprojectDefaultGeometry reprojectTransform;
|
||
132 | 42775 | jjdelcerro | private FeatureQuery baseQuery = null; |
133 | 40435 | jjdelcerro | |
134 | public FLyrVect() {
|
||
135 | super();
|
||
136 | } |
||
137 | 42289 | jjdelcerro | |
138 | public String getTocImageIcon() { |
||
139 | if (this.isAvailable()) { |
||
140 | 40435 | jjdelcerro | return MapContextLocator.getMapContextManager().getIconLayer(this.getDataStore()); |
141 | 42289 | jjdelcerro | } else {
|
142 | /*
|
||
143 | * data store can be be null,
|
||
144 | * for example, a layer not loaded from persistence
|
||
145 | */
|
||
146 | 40435 | jjdelcerro | return "layer-icon-unavailable"; |
147 | 42289 | jjdelcerro | } |
148 | 40435 | jjdelcerro | |
149 | 42289 | jjdelcerro | } |
150 | |||
151 | 40435 | jjdelcerro | /**
|
152 | * Devuelve el VectorialAdapater de la capa.
|
||
153 | 42289 | jjdelcerro | *
|
154 | 40435 | jjdelcerro | * @return VectorialAdapter.
|
155 | */
|
||
156 | public DataStore getDataStore() {
|
||
157 | 42811 | jjdelcerro | // if (!this.isAvailable()) {
|
158 | // return null;
|
||
159 | // }
|
||
160 | 40435 | jjdelcerro | return featureStore;
|
161 | } |
||
162 | 42289 | jjdelcerro | |
163 | 40435 | jjdelcerro | /**
|
164 | 42289 | jjdelcerro | * Asigna el data-store a la capa. Esta operacion no se deneria poder hacer
|
165 | * desde fuera de la clase.
|
||
166 | *
|
||
167 | 40435 | jjdelcerro | * @param dataStore
|
168 | * @throws LoadLayerException
|
||
169 | * @deprecated use {@link #bindToDataStore(DataStore)}
|
||
170 | */
|
||
171 | public void setDataStore(DataStore dataStore) throws LoadLayerException { |
||
172 | 42289 | jjdelcerro | bindToDataStore(dataStore); |
173 | 40435 | jjdelcerro | } |
174 | 42289 | jjdelcerro | |
175 | 40435 | jjdelcerro | /**
|
176 | * Enlaza la capa con el DataStore indicado.
|
||
177 | 42289 | jjdelcerro | *
|
178 | 40435 | jjdelcerro | * @param dataStore
|
179 | * @throws LoadLayerException
|
||
180 | */
|
||
181 | protected void bindToDataStore(DataStore dataStore) throws LoadLayerException { |
||
182 | if (this.featureStore != null && this.featureStore != dataStore) { |
||
183 | this.featureStore.deleteObserver(this); |
||
184 | } |
||
185 | |||
186 | featureStore = (FeatureStore) dataStore; |
||
187 | |||
188 | 42289 | jjdelcerro | MapContextManager mapContextManager |
189 | = MapContextLocator.getMapContextManager(); |
||
190 | |||
191 | 40435 | jjdelcerro | //Set the legend
|
192 | 42289 | jjdelcerro | IVectorLegend legend |
193 | = (IVectorLegend) mapContextManager.getLegend(dataStore); |
||
194 | 40435 | jjdelcerro | |
195 | if (legend == null) { |
||
196 | throw new LegendLayerException(this.getName()); |
||
197 | } |
||
198 | |||
199 | this.setLegend(legend);
|
||
200 | |||
201 | //Set the labeling strategy
|
||
202 | 42289 | jjdelcerro | ILabelingStrategy labeler |
203 | = (ILabelingStrategy) mapContextManager.getLabelingStrategy(dataStore); |
||
204 | 40435 | jjdelcerro | |
205 | if (labeler != null) { |
||
206 | labeler.setLayer(this);
|
||
207 | this.setLabelingStrategy(labeler);
|
||
208 | this.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? |
||
209 | 42289 | jjdelcerro | // etiquetes?????
|
210 | 40435 | jjdelcerro | } |
211 | |||
212 | this.delegate(dataStore);
|
||
213 | |||
214 | dataStore.addObserver(this);
|
||
215 | |||
216 | ToolsLocator.getDisposableManager().bind(dataStore); |
||
217 | } |
||
218 | |||
219 | public Envelope getFullEnvelope() throws ReadException { |
||
220 | Envelope rAux; |
||
221 | try {
|
||
222 | rAux = getFeatureStore().getEnvelope(); |
||
223 | } catch (BaseException e) {
|
||
224 | throw new ReadException(getName(), e); |
||
225 | } |
||
226 | |||
227 | // Esto es para cuando se crea una capa nueva con el fullExtent de ancho
|
||
228 | // y alto 0.
|
||
229 | if (rAux == null || rAux.isEmpty() || rAux.getMaximum(0) - rAux.getMinimum(0) == 0 |
||
230 | 42289 | jjdelcerro | && rAux.getMaximum(1) - rAux.getMinimum(1) == 0) { |
231 | 40435 | jjdelcerro | try {
|
232 | 42289 | jjdelcerro | rAux |
233 | = geomManager.createEnvelope(0, 0, 90, 90, SUBTYPES.GEOM2D); |
||
234 | 40435 | jjdelcerro | } catch (CreateEnvelopeException e) {
|
235 | logger.error("Error creating the envelope", e);
|
||
236 | e.printStackTrace(); |
||
237 | } |
||
238 | } |
||
239 | // Si existe reproyecci?n, reproyectar el extent
|
||
240 | ICoordTrans ct = getCoordTrans(); |
||
241 | if (ct != null) { |
||
242 | 42877 | fdiaz | boolean originalEnvelopeIsEmpty = rAux.isEmpty();
|
243 | 42289 | jjdelcerro | rAux = rAux.convert(ct); |
244 | 42877 | fdiaz | if(!originalEnvelopeIsEmpty && rAux.isEmpty()){
|
245 | try {
|
||
246 | this.setAvailable(false); |
||
247 | throw new EnvelopeCantBeInitializedException(); |
||
248 | } catch(EnvelopeCantBeInitializedException e){
|
||
249 | this.addError(e);
|
||
250 | } |
||
251 | } |
||
252 | 40435 | jjdelcerro | } |
253 | return rAux;
|
||
254 | |||
255 | } |
||
256 | 42820 | dmartinezizquierdo | |
257 | 42775 | jjdelcerro | public void setBaseQuery(FeatureQuery baseQuery) { |
258 | this.baseQuery = baseQuery;
|
||
259 | } |
||
260 | 40435 | jjdelcerro | |
261 | 42775 | jjdelcerro | @Override
|
262 | public FeatureQuery getBaseQuery() {
|
||
263 | return this.baseQuery; |
||
264 | } |
||
265 | |||
266 | 42820 | dmartinezizquierdo | public void addBaseFilter(Evaluator filter) { |
267 | if( this.baseQuery == null ) { |
||
268 | this.baseQuery = this.getFeatureStore().createFeatureQuery(); |
||
269 | } |
||
270 | this.baseQuery.addFilter(filter);
|
||
271 | } |
||
272 | |||
273 | 42972 | jjdelcerro | public void addBaseFilter(String filter) { |
274 | try {
|
||
275 | this.addBaseFilter( DALLocator.getDataManager().createExpresion(filter));
|
||
276 | } catch (InitializeException ex) {
|
||
277 | throw new RuntimeException("Can't create filter with '"+filter+"'", ex); |
||
278 | } |
||
279 | } |
||
280 | |||
281 | 40435 | jjdelcerro | /**
|
282 | * Draws using IFeatureIterator. This method will replace the old draw(...)
|
||
283 | * one.
|
||
284 | 42289 | jjdelcerro | *
|
285 | 40435 | jjdelcerro | * @autor jaume dominguez faus - jaume.dominguez@iver.es
|
286 | * @param image
|
||
287 | * @param g
|
||
288 | * @param viewPort
|
||
289 | * @param cancel
|
||
290 | * @param scale
|
||
291 | * @throws ReadDriverException
|
||
292 | */
|
||
293 | public void draw(BufferedImage image, |
||
294 | 42289 | jjdelcerro | Graphics2D g,
|
295 | ViewPort viewPort, |
||
296 | Cancellable cancel, |
||
297 | double scale) throws ReadException { |
||
298 | 40435 | jjdelcerro | |
299 | if (legend == null) { |
||
300 | return;
|
||
301 | } |
||
302 | |||
303 | if (!this.isWithinScale(scale)) { |
||
304 | return;
|
||
305 | } |
||
306 | if (cancel.isCanceled()) {
|
||
307 | return;
|
||
308 | } |
||
309 | |||
310 | if (spatialCache.isEnabled()) {
|
||
311 | spatialCache.clearAll(); |
||
312 | legend.addDrawingObserver(this);
|
||
313 | } |
||
314 | |||
315 | 42809 | jbadia | FeatureQuery featureQuery = createFeatureQuery(); |
316 | 42775 | jjdelcerro | |
317 | 40435 | jjdelcerro | try {
|
318 | 42289 | jjdelcerro | FeatureAttributeDescriptor featureAttributeDescriptor |
319 | = getFeatureStore().getDefaultFeatureType().getDefaultTimeAttribute(); |
||
320 | 40435 | jjdelcerro | |
321 | 42289 | jjdelcerro | if ((viewPort.getTime() != null) && (featureAttributeDescriptor != null)) { |
322 | IntersectsTimeEvaluator intersectsTimeEvaluator |
||
323 | = new IntersectsTimeEvaluator(viewPort.getTime(), featureAttributeDescriptor.getName());
|
||
324 | 40435 | jjdelcerro | featureQuery.addFilter(intersectsTimeEvaluator); |
325 | } |
||
326 | } catch (DataException e1) {
|
||
327 | logger.error("Impossible to get the temporal filter", e1);
|
||
328 | } |
||
329 | |||
330 | try {
|
||
331 | 42289 | jjdelcerro | |
332 | 40435 | jjdelcerro | long tini = System.currentTimeMillis(); |
333 | 42289 | jjdelcerro | |
334 | 40435 | jjdelcerro | legend.draw(image, |
335 | 42289 | jjdelcerro | g, |
336 | viewPort, |
||
337 | cancel, |
||
338 | scale, |
||
339 | null,
|
||
340 | getCoordTrans(), |
||
341 | getFeatureStore(), |
||
342 | featureQuery); |
||
343 | 40435 | jjdelcerro | |
344 | 42289 | jjdelcerro | logger.debug("Layer " + this.getName() + " drawn in " |
345 | + (System.currentTimeMillis() - tini) + " milliseconds."); |
||
346 | |||
347 | 40435 | jjdelcerro | } catch (LegendException e) {
|
348 | 42811 | jjdelcerro | this.setAvailable(false); |
349 | this.setError(e);
|
||
350 | 40435 | jjdelcerro | throw new ReadException(getName(), e); |
351 | } finally {
|
||
352 | if (spatialCache.isEnabled()) {
|
||
353 | legend.deleteDrawingObserver(this);
|
||
354 | } |
||
355 | } |
||
356 | } |
||
357 | |||
358 | public void print(Graphics2D g, |
||
359 | 42289 | jjdelcerro | ViewPort viewPort, |
360 | Cancellable cancel, |
||
361 | double scale,
|
||
362 | PrintAttributes properties) throws ReadException {
|
||
363 | 40435 | jjdelcerro | if (!this.isWithinScale(scale)) { |
364 | return;
|
||
365 | } |
||
366 | if (cancel.isCanceled()) {
|
||
367 | return;
|
||
368 | } |
||
369 | 42775 | jjdelcerro | FeatureQuery featureQuery = createFeatureQuery(); |
370 | 40435 | jjdelcerro | |
371 | try {
|
||
372 | legend.print(g, |
||
373 | 42289 | jjdelcerro | viewPort, |
374 | cancel, |
||
375 | scale, |
||
376 | null,
|
||
377 | getCoordTrans(), |
||
378 | getFeatureStore(), |
||
379 | 42775 | jjdelcerro | featureQuery, |
380 | 42289 | jjdelcerro | properties); |
381 | 40435 | jjdelcerro | |
382 | } catch (LegendException e) {
|
||
383 | this.setVisible(false); |
||
384 | this.setActive(false); |
||
385 | throw new ReadException(getName(), e); |
||
386 | } |
||
387 | } |
||
388 | |||
389 | public void setLegend(IVectorLegend legend) throws LegendLayerException { |
||
390 | if (this.legend == legend) { |
||
391 | return;
|
||
392 | } |
||
393 | if (this.legend != null && this.legend.equals(legend)) { |
||
394 | return;
|
||
395 | } |
||
396 | IVectorLegend oldLegend = this.legend;
|
||
397 | this.legend = legend;
|
||
398 | if (oldLegend != null) { |
||
399 | oldLegend.removeLegendListener(this);
|
||
400 | oldLegend.deleteDrawingObserver(this);
|
||
401 | } |
||
402 | if (legend != null) { |
||
403 | this.legend.addDrawingObserver(this); |
||
404 | this.legend.addLegendListener(this); |
||
405 | } |
||
406 | 42802 | jjdelcerro | LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(oldLegend, this.legend);
|
407 | 40435 | jjdelcerro | e.setLayer(this);
|
408 | updateDrawVersion(); |
||
409 | callLegendChanged(e); |
||
410 | } |
||
411 | |||
412 | /**
|
||
413 | * Devuelve la Leyenda de la capa.
|
||
414 | 42289 | jjdelcerro | *
|
415 | 40435 | jjdelcerro | * @return Leyenda.
|
416 | */
|
||
417 | public ILegend getLegend() {
|
||
418 | return legend;
|
||
419 | } |
||
420 | |||
421 | public int getShapeType() throws ReadException { |
||
422 | 42289 | jjdelcerro | if (typeShape == -1) { |
423 | FeatureType featureType = null;
|
||
424 | try {
|
||
425 | if (getDataStore() != null) { |
||
426 | featureType |
||
427 | = (((FeatureStore) getDataStore()).getDefaultFeatureType()); |
||
428 | } |
||
429 | } catch (DataException e) {
|
||
430 | throw new ReadException(getName(), e); |
||
431 | } |
||
432 | if (featureType != null) { |
||
433 | int indexGeom = featureType.getDefaultGeometryAttributeIndex();
|
||
434 | typeShape |
||
435 | = featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
||
436 | } |
||
437 | } |
||
438 | return typeShape;
|
||
439 | 40435 | jjdelcerro | } |
440 | |||
441 | /**
|
||
442 | * Returns the layer's geometry type
|
||
443 | 42289 | jjdelcerro | *
|
444 | 40435 | jjdelcerro | * @return the geometry type
|
445 | 42289 | jjdelcerro | *
|
446 | * @throws ReadException if there is an error getting the geometry type
|
||
447 | 40435 | jjdelcerro | */
|
448 | public GeometryType getGeometryType() throws ReadException { |
||
449 | FeatureType featureType = null;
|
||
450 | try {
|
||
451 | if (getDataStore() != null) { |
||
452 | 42289 | jjdelcerro | featureType |
453 | = (((FeatureStore) getDataStore()).getDefaultFeatureType()); |
||
454 | 40435 | jjdelcerro | } |
455 | } catch (DataException e) {
|
||
456 | throw new ReadException(getName(), e); |
||
457 | } |
||
458 | return featureType == null ? null : featureType |
||
459 | 42289 | jjdelcerro | .getDefaultGeometryAttribute().getGeomType(); |
460 | 40435 | jjdelcerro | } |
461 | |||
462 | public void saveToState(PersistentState state) throws PersistenceException { |
||
463 | |||
464 | 41807 | jjdelcerro | FeatureStore featureStore = null;
|
465 | |||
466 | 42289 | jjdelcerro | if (!this.isAvailable()) { |
467 | 41807 | jjdelcerro | logger.info("The '" + this.getName() + "' layer is not available, it will persist not."); |
468 | 40435 | jjdelcerro | return;
|
469 | } |
||
470 | 42289 | jjdelcerro | |
471 | 41807 | jjdelcerro | try {
|
472 | super.saveToState(state);
|
||
473 | 40435 | jjdelcerro | |
474 | 42289 | jjdelcerro | if (getLegend() != null) { |
475 | 41807 | jjdelcerro | state.set("legend", getLegend());
|
476 | } |
||
477 | 40435 | jjdelcerro | |
478 | 41807 | jjdelcerro | featureStore = getFeatureStore(); |
479 | 40435 | jjdelcerro | |
480 | 42289 | jjdelcerro | if (featureStore != null) { |
481 | 41807 | jjdelcerro | state.set("featureStore", featureStore);
|
482 | } |
||
483 | 40435 | jjdelcerro | |
484 | 41807 | jjdelcerro | state.set("isLabeled", isLabeled);
|
485 | 40435 | jjdelcerro | |
486 | 42289 | jjdelcerro | if (strategy != null) { |
487 | 41807 | jjdelcerro | state.set("labelingStrategy", strategy);
|
488 | } |
||
489 | 40435 | jjdelcerro | |
490 | 42289 | jjdelcerro | if (getLinkProperties() != null) { |
491 | 41807 | jjdelcerro | state.set("linkProperties", getLinkProperties());
|
492 | } |
||
493 | 40435 | jjdelcerro | |
494 | 41807 | jjdelcerro | state.set("typeShape", typeShape);
|
495 | } catch (PersistenceException ex) {
|
||
496 | logger.warn("Can't persist to state the layer '" + this.getName() + "'.", ex); |
||
497 | throw ex;
|
||
498 | } catch (RuntimeException ex) { |
||
499 | logger.warn("Can't persist to state the layer '" + this.getName() + "'.", ex); |
||
500 | throw ex;
|
||
501 | 40435 | jjdelcerro | } |
502 | |||
503 | } |
||
504 | |||
505 | public void loadFromState(PersistentState state) throws PersistenceException { |
||
506 | |||
507 | DataStore store = null;
|
||
508 | 41807 | jjdelcerro | IVectorLegend vectorLegend = null;
|
509 | ILabelingStrategy labelingStrategy = null;
|
||
510 | Boolean isLabeled = Boolean.FALSE; |
||
511 | 41146 | jldominguez | |
512 | 40435 | jjdelcerro | try {
|
513 | 42289 | jjdelcerro | super.loadFromState(state);
|
514 | store = (DataStore) state.get("featureStore");
|
||
515 | 40435 | jjdelcerro | |
516 | 41807 | jjdelcerro | try {
|
517 | this.bindToDataStore(store);
|
||
518 | } catch (LoadLayerException e) {
|
||
519 | 42289 | jjdelcerro | throw new PersistenceException("Can't bind layer '" + this.getName() + "' to store '" + store.getFullName() + "'.", e); |
520 | 41807 | jjdelcerro | } |
521 | 40435 | jjdelcerro | |
522 | 41807 | jjdelcerro | vectorLegend = (IVectorLegend) state.get("legend");
|
523 | |||
524 | try {
|
||
525 | this.setLegend(vectorLegend);
|
||
526 | } catch (LegendLayerException e) {
|
||
527 | throw new PersistenceException("Can't set vector legend to the layer.", e); |
||
528 | 40435 | jjdelcerro | } |
529 | |||
530 | 41807 | jjdelcerro | try {
|
531 | isLabeled = (Boolean) state.get("isLabeled"); |
||
532 | 42289 | jjdelcerro | if (isLabeled.booleanValue()) {
|
533 | 41807 | jjdelcerro | labelingStrategy = (ILabelingStrategy) state.get("labelingStrategy");
|
534 | } |
||
535 | } catch (Exception ex) { |
||
536 | throw new PersistenceException("Can't load labeling strategi from persistent state.", |
||
537 | ex); |
||
538 | } |
||
539 | 40435 | jjdelcerro | |
540 | 42289 | jjdelcerro | if (isLabeled.booleanValue()) {
|
541 | 41807 | jjdelcerro | this.setIsLabeled(true); |
542 | this.setLabelingStrategy(labelingStrategy);
|
||
543 | } else {
|
||
544 | this.setIsLabeled(false); |
||
545 | this.setLabelingStrategy(null); |
||
546 | } |
||
547 | 40435 | jjdelcerro | |
548 | 41807 | jjdelcerro | typeShape = state.getInt("typeShape");
|
549 | |||
550 | } catch (Throwable e) { |
||
551 | 42289 | jjdelcerro | String storeName = (store == null) ? "unknow" : store.getFullName(); |
552 | logger.warn("can't load layer '" + this.getName() + "' (store=" + storeName + ") from persisted state.", e); |
||
553 | 41807 | jjdelcerro | this.setAvailable(false); |
554 | return;
|
||
555 | } |
||
556 | |||
557 | 40435 | jjdelcerro | } |
558 | |||
559 | /**
|
||
560 | * Sobreimplementaci?n del m?todo toString para que las bases de datos
|
||
561 | * identifiquen la capa.
|
||
562 | 42289 | jjdelcerro | *
|
563 | 40435 | jjdelcerro | * @return DOCUMENT ME!
|
564 | */
|
||
565 | public String toString() { |
||
566 | /*
|
||
567 | * Se usa internamente para que la parte de datos identifique de forma
|
||
568 | * un?voca las tablas
|
||
569 | */
|
||
570 | String ret = super.toString(); |
||
571 | |||
572 | 42651 | jjdelcerro | return ret ; //"layer" + ret.substring(ret.indexOf('@') + 1); |
573 | 40435 | jjdelcerro | } |
574 | |||
575 | public boolean isEditing() { |
||
576 | FeatureStore fs = getFeatureStore(); |
||
577 | if (fs == null) { |
||
578 | /*
|
||
579 | * This happens when layer is not available, for example,
|
||
580 | * it was not possible to load from persistence
|
||
581 | */
|
||
582 | return false; |
||
583 | } else {
|
||
584 | return fs.isEditing();
|
||
585 | } |
||
586 | } |
||
587 | 42289 | jjdelcerro | |
588 | 40435 | jjdelcerro | public void setEditing(boolean b) throws StartEditionLayerException { |
589 | 42289 | jjdelcerro | |
590 | 40435 | jjdelcerro | try {
|
591 | throw new RuntimeException(); |
||
592 | } catch (Throwable th) { |
||
593 | logger.info("This method is deprecated. ", th);
|
||
594 | } |
||
595 | 42289 | jjdelcerro | |
596 | 40435 | jjdelcerro | if (b == super.isEditing()) { |
597 | return;
|
||
598 | } |
||
599 | 42289 | jjdelcerro | |
600 | 40435 | jjdelcerro | super.setEditing(b);
|
601 | FeatureStore fs = getFeatureStore(); |
||
602 | if (b) {
|
||
603 | try {
|
||
604 | fs.edit(); |
||
605 | } catch (DataException e) {
|
||
606 | throw new StartEditionLayerException(getName(), e); |
||
607 | } |
||
608 | } |
||
609 | setSpatialCacheEnabled(b); |
||
610 | callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
||
611 | } |
||
612 | |||
613 | /**
|
||
614 | * @deprecated Use {@link #getSpatialCache()}
|
||
615 | */
|
||
616 | public void clearSpatialCache() { |
||
617 | spatialCache.clearAll(); |
||
618 | } |
||
619 | |||
620 | /**
|
||
621 | * @deprecated Use {@link #getSpatialCache()}
|
||
622 | */
|
||
623 | public boolean isSpatialCacheEnabled() { |
||
624 | return spatialCache.isEnabled();
|
||
625 | } |
||
626 | |||
627 | /**
|
||
628 | * @deprecated Use {@link #getSpatialCache()}
|
||
629 | */
|
||
630 | public void setSpatialCacheEnabled(boolean spatialCacheEnabled) { |
||
631 | spatialCache.setEnabled(spatialCacheEnabled); |
||
632 | } |
||
633 | |||
634 | public SpatialCache getSpatialCache() {
|
||
635 | return spatialCache;
|
||
636 | } |
||
637 | |||
638 | /**
|
||
639 | * Siempre es un numero mayor de 1000
|
||
640 | 42289 | jjdelcerro | *
|
641 | 40435 | jjdelcerro | * @param maxFeatures
|
642 | */
|
||
643 | public void setMaxFeaturesInEditionCache(int maxFeatures) { |
||
644 | if (maxFeatures > spatialCache.getMaxFeatures()) {
|
||
645 | spatialCache.setMaxFeatures(maxFeatures); |
||
646 | } |
||
647 | |||
648 | } |
||
649 | |||
650 | /**
|
||
651 | 42289 | jjdelcerro | * This method returns a boolean that is used by the FPopMenu to make
|
652 | * visible the properties menu or not. It is visible by default, and if a
|
||
653 | * later don't have to show this menu only has to override this method.
|
||
654 | *
|
||
655 | * @return If the properties menu is visible (or not)
|
||
656 | 40435 | jjdelcerro | */
|
657 | public boolean isPropertiesMenuVisible() { |
||
658 | return true; |
||
659 | } |
||
660 | |||
661 | public void reload() throws ReloadLayerException { |
||
662 | super.reload();
|
||
663 | try {
|
||
664 | getFeatureStore().refresh(); |
||
665 | } catch (Exception e) { |
||
666 | throw new ReloadLayerException(getName(), e); |
||
667 | } |
||
668 | } |
||
669 | |||
670 | protected void setLoadSelection(Object xml) { |
||
671 | // this.loadSelection = xml;
|
||
672 | } |
||
673 | |||
674 | protected void setLoadLegend(IVectorLegend legend) { |
||
675 | this.loadLegend = legend;
|
||
676 | } |
||
677 | |||
678 | protected void putLoadSelection() { |
||
679 | // if (this.loadSelection == null) return;
|
||
680 | // try {
|
||
681 | // this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection);
|
||
682 | // } catch (ReadDriverException e) {
|
||
683 | // throw new XMLException(e);
|
||
684 | // }
|
||
685 | // this.loadSelection = null;
|
||
686 | |||
687 | } |
||
688 | |||
689 | protected void putLoadLegend() throws LegendLayerException { |
||
690 | if (this.loadLegend == null) { |
||
691 | return;
|
||
692 | } |
||
693 | this.setLegend(this.loadLegend); |
||
694 | this.loadLegend = null; |
||
695 | } |
||
696 | |||
697 | protected void cleanLoadOptions() { |
||
698 | this.loadLegend = null; |
||
699 | } |
||
700 | |||
701 | public boolean isWritable() { |
||
702 | return getFeatureStore().allowWrite();
|
||
703 | } |
||
704 | |||
705 | public FLayer cloneLayer() throws Exception { |
||
706 | FLyrVect clonedLayer = new FLyrVect();
|
||
707 | clonedLayer.bindToDataStore(getDataStore()); |
||
708 | // if (isJoined()) {
|
||
709 | // clonedLayer.setIsJoined(true);
|
||
710 | // }
|
||
711 | clonedLayer.setVisible(isVisible()); |
||
712 | // clonedLayer.setISpatialIndex(getISpatialIndex());
|
||
713 | clonedLayer.setName(getName()); |
||
714 | clonedLayer.setCoordTrans(getCoordTrans()); |
||
715 | |||
716 | clonedLayer.setLegend((IVectorLegend) getLegend().cloneLegend()); |
||
717 | |||
718 | clonedLayer.setIsLabeled(isLabeled()); |
||
719 | ILabelingStrategy labelingStrategy = getLabelingStrategy(); |
||
720 | if (labelingStrategy != null) { |
||
721 | clonedLayer.setLabelingStrategy(labelingStrategy); |
||
722 | } |
||
723 | |||
724 | return clonedLayer;
|
||
725 | } |
||
726 | |||
727 | protected boolean isOnePoint(AffineTransform graphicsTransform, |
||
728 | 42289 | jjdelcerro | ViewPort viewPort, |
729 | double dpi,
|
||
730 | CartographicSupport csSym, |
||
731 | Geometry geom, |
||
732 | int[] xyCoords) { |
||
733 | 40435 | jjdelcerro | return isOnePoint(graphicsTransform, viewPort, geom, xyCoords)
|
734 | 42289 | jjdelcerro | && csSym.getCartographicSize(viewPort, dpi, geom) <= 1;
|
735 | 40435 | jjdelcerro | } |
736 | |||
737 | private boolean isOnePoint(AffineTransform graphicsTransform, |
||
738 | 42289 | jjdelcerro | ViewPort viewPort, |
739 | Geometry geom, |
||
740 | int[] xyCoords) { |
||
741 | 40435 | jjdelcerro | boolean onePoint = false; |
742 | int type = geom.getType();
|
||
743 | if (type == Geometry.TYPES.NULL) {
|
||
744 | return false; |
||
745 | } |
||
746 | if (type != Geometry.TYPES.POINT && type != Geometry.TYPES.MULTIPOINT) {
|
||
747 | |||
748 | Envelope geomBounds = geom.getEnvelope(); |
||
749 | |||
750 | // ICoordTrans ct = getCoordTrans();
|
||
751 | // Se supone que la geometria ya esta reproyectada
|
||
752 | // if (ct!=null) {
|
||
753 | // // geomBounds = ct.getInverted().convert(geomBounds);
|
||
754 | // geomBounds = geomBounds.convert(ct);
|
||
755 | // }
|
||
756 | double dist1Pixel = viewPort.getDist1pixel();
|
||
757 | |||
758 | 42289 | jjdelcerro | onePoint |
759 | = (geomBounds.getLength(0) <= dist1Pixel && geomBounds.getLength(1) <= dist1Pixel); |
||
760 | 40435 | jjdelcerro | |
761 | if (onePoint) {
|
||
762 | // avoid out of range exceptions
|
||
763 | org.gvsig.fmap.geom.primitive.Point p; |
||
764 | try {
|
||
765 | 42289 | jjdelcerro | p |
766 | = geomManager.createPoint(geomBounds.getMinimum(0),
|
||
767 | geomBounds.getMinimum(1),
|
||
768 | SUBTYPES.GEOM2D); |
||
769 | 40435 | jjdelcerro | p.transform(viewPort.getAffineTransform()); |
770 | p.transform(graphicsTransform); |
||
771 | xyCoords[0] = (int) p.getX(); |
||
772 | xyCoords[1] = (int) p.getY(); |
||
773 | } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
||
774 | logger.error("Error creating a point", e);
|
||
775 | } |
||
776 | |||
777 | } |
||
778 | |||
779 | } |
||
780 | return onePoint;
|
||
781 | } |
||
782 | |||
783 | public boolean isLabeled() { |
||
784 | return isLabeled;
|
||
785 | } |
||
786 | |||
787 | public void setIsLabeled(boolean isLabeled) { |
||
788 | this.isLabeled = isLabeled;
|
||
789 | } |
||
790 | |||
791 | public ILabelingStrategy getLabelingStrategy() {
|
||
792 | return strategy;
|
||
793 | } |
||
794 | |||
795 | public void setLabelingStrategy(ILabelingStrategy strategy) { |
||
796 | this.strategy = strategy;
|
||
797 | if (strategy == null) { |
||
798 | return;
|
||
799 | } |
||
800 | strategy.setLayer(this);
|
||
801 | updateDrawVersion(); |
||
802 | } |
||
803 | |||
804 | public void drawLabels(BufferedImage image, |
||
805 | 42289 | jjdelcerro | Graphics2D g,
|
806 | ViewPort viewPort, |
||
807 | Cancellable cancel, |
||
808 | double scale,
|
||
809 | double dpi) throws ReadException { |
||
810 | 40435 | jjdelcerro | if (strategy != null && isWithinScale(scale)) { |
811 | 41676 | jjdelcerro | strategy.draw(image, g, scale, viewPort, cancel, dpi); |
812 | 40435 | jjdelcerro | } |
813 | } |
||
814 | |||
815 | public void printLabels(Graphics2D g, |
||
816 | 42289 | jjdelcerro | ViewPort viewPort, |
817 | Cancellable cancel, |
||
818 | double scale,
|
||
819 | PrintAttributes properties) throws ReadException {
|
||
820 | 40435 | jjdelcerro | if (strategy != null) { |
821 | 41676 | jjdelcerro | strategy.print(g, scale, viewPort, cancel, properties); |
822 | 40435 | jjdelcerro | } |
823 | } |
||
824 | |||
825 | /**
|
||
826 | * Return true, because a Vectorial Layer supports HyperLink
|
||
827 | 42289 | jjdelcerro | *
|
828 | 40435 | jjdelcerro | * @deprecated the hiperlink functionaliti is out the layer now
|
829 | */
|
||
830 | public boolean allowLinks() { |
||
831 | return false; |
||
832 | } |
||
833 | |||
834 | public void load() throws LoadLayerException { |
||
835 | super.load();
|
||
836 | } |
||
837 | |||
838 | public FeatureStore getFeatureStore() {
|
||
839 | return (FeatureStore) getDataStore();
|
||
840 | } |
||
841 | |||
842 | 42775 | jjdelcerro | public FeatureQuery createFeatureQuery() {
|
843 | if( this.baseQuery==null ) { |
||
844 | return this.getFeatureStore().createFeatureQuery(); |
||
845 | } |
||
846 | try {
|
||
847 | return (FeatureQuery) baseQuery.clone();
|
||
848 | } catch (CloneNotSupportedException ex) { |
||
849 | throw new RuntimeException(ex); |
||
850 | } |
||
851 | } |
||
852 | 42820 | dmartinezizquierdo | |
853 | 40435 | jjdelcerro | /**
|
854 | 42289 | jjdelcerro | * @deprecated use instead
|
855 | * {@link #queryByPoint(org.gvsig.fmap.geom.primitive.Point, double, FeatureType)}
|
||
856 | 40435 | jjdelcerro | */
|
857 | public FeatureSet queryByPoint(Point2D mapPoint, |
||
858 | 42289 | jjdelcerro | double tol,
|
859 | FeatureType featureType) throws DataException {
|
||
860 | 40435 | jjdelcerro | logger.warn("Deprecated use of queryByPoint.");
|
861 | GeometryManager manager = GeometryLocator.getGeometryManager(); |
||
862 | org.gvsig.fmap.geom.primitive.Point center; |
||
863 | try {
|
||
864 | 42289 | jjdelcerro | center |
865 | = (org.gvsig.fmap.geom.primitive.Point) manager.create(TYPES.POINT, |
||
866 | SUBTYPES.GEOM2D); |
||
867 | 40435 | jjdelcerro | center.setX(mapPoint.getX()); |
868 | center.setY(mapPoint.getY()); |
||
869 | 42289 | jjdelcerro | Circle circle |
870 | = (Circle) manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D); |
||
871 | 40435 | jjdelcerro | circle.setPoints(center, tol); |
872 | return queryByGeometry(circle, featureType);
|
||
873 | } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
||
874 | throw new CreateGeometryException(TYPES.CIRCLE, SUBTYPES.GEOM2D, e); |
||
875 | } |
||
876 | } |
||
877 | |||
878 | public FeatureSet queryByPoint(org.gvsig.fmap.geom.primitive.Point point,
|
||
879 | 42289 | jjdelcerro | double tol,
|
880 | FeatureType featureType) throws DataException {
|
||
881 | 40435 | jjdelcerro | GeometryManager manager = GeometryLocator.getGeometryManager(); |
882 | try {
|
||
883 | 42289 | jjdelcerro | Circle circle |
884 | = (Circle) manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D); |
||
885 | 40435 | jjdelcerro | circle.setPoints(point, tol); |
886 | return queryByGeometry(circle, featureType);
|
||
887 | } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
|
||
888 | throw new CreateGeometryException(TYPES.CIRCLE, SUBTYPES.GEOM2D, e); |
||
889 | } |
||
890 | } |
||
891 | |||
892 | 40941 | jldominguez | /**
|
893 | * Input geom must be in the CRS of the view.
|
||
894 | 42289 | jjdelcerro | *
|
895 | 40941 | jldominguez | * @param geom
|
896 | * @param featureType
|
||
897 | * @return
|
||
898 | * @throws DataException
|
||
899 | */
|
||
900 | 40435 | jjdelcerro | public FeatureSet queryByGeometry(Geometry geom, FeatureType featureType) throws DataException { |
901 | 42775 | jjdelcerro | FeatureQuery featureQuery = createFeatureQuery(); |
902 | 40435 | jjdelcerro | featureQuery.setFeatureType(featureType); |
903 | 42289 | jjdelcerro | |
904 | 41813 | jjdelcerro | Geometry query_geo = this.transformToSourceCRS(geom, true); |
905 | 40435 | jjdelcerro | IProjection query_proj = getMapContext().getProjection(); |
906 | if (this.getCoordTrans() != null) { |
||
907 | 42289 | jjdelcerro | query_proj = this.getCoordTrans().getPOrig();
|
908 | 40435 | jjdelcerro | } |
909 | 43020 | jjdelcerro | Evaluator iee = SpatialEvaluatorsFactory.getInstance().intersects( |
910 | query_geo, |
||
911 | query_proj, |
||
912 | featureStore |
||
913 | ); |
||
914 | 40435 | jjdelcerro | featureQuery.setFilter(iee); |
915 | featureQuery.setAttributeNames(null);
|
||
916 | return getFeatureStore().getFeatureSet(featureQuery);
|
||
917 | |||
918 | } |
||
919 | |||
920 | /**
|
||
921 | * It return the {@link FeatureSet} that intersects with the envelope.
|
||
922 | 42289 | jjdelcerro | *
|
923 | * @param envelope envelope that defines the area for the query.
|
||
924 | * @param featureType only the features with this feature type are used in
|
||
925 | * the query.
|
||
926 | * @return the set of features that intersect with the envelope.
|
||
927 | 40435 | jjdelcerro | * @throws DataException
|
928 | */
|
||
929 | public FeatureSet queryByEnvelope(Envelope envelope, FeatureType featureType) throws DataException { |
||
930 | return queryByEnvelope(envelope, featureType, null); |
||
931 | } |
||
932 | |||
933 | /**
|
||
934 | * It return the {@link FeatureSet} that intersects with the envelope.
|
||
935 | 42289 | jjdelcerro | *
|
936 | * @param envelope envelope that defines the area for the query in viewport
|
||
937 | * CRS
|
||
938 | * @param featureType only the features with this feature type are used in
|
||
939 | * the query.
|
||
940 | * @param names the feature attributes that have to be checked.
|
||
941 | * @return the set of features that intersect with the envelope.
|
||
942 | 40435 | jjdelcerro | * @throws DataException
|
943 | */
|
||
944 | public FeatureSet queryByEnvelope(Envelope envelope,
|
||
945 | 42289 | jjdelcerro | FeatureType featureType, |
946 | String[] names) throws DataException { |
||
947 | 42775 | jjdelcerro | FeatureQuery featureQuery = createFeatureQuery(); |
948 | 40435 | jjdelcerro | if (names == null) { |
949 | featureQuery.setFeatureType(featureType); |
||
950 | } else {
|
||
951 | featureQuery.setAttributeNames(names); |
||
952 | featureQuery.setFeatureTypeId(featureType.getId()); |
||
953 | } |
||
954 | 42289 | jjdelcerro | |
955 | 40435 | jjdelcerro | Envelope query_env = fromViewPortCRSToSourceCRS(this, envelope);
|
956 | IProjection query_proj = getMapContext().getProjection(); |
||
957 | if (this.getCoordTrans() != null) { |
||
958 | 42289 | jjdelcerro | query_proj = this.getCoordTrans().getPOrig();
|
959 | 40435 | jjdelcerro | } |
960 | 42289 | jjdelcerro | |
961 | 43020 | jjdelcerro | Evaluator iee = SpatialEvaluatorsFactory.getInstance().intersects( |
962 | query_env.getGeometry(), |
||
963 | query_proj, |
||
964 | featureStore |
||
965 | ); |
||
966 | 40435 | jjdelcerro | featureQuery.setFilter(iee); |
967 | return getFeatureStore().getFeatureSet(featureQuery);
|
||
968 | |||
969 | } |
||
970 | |||
971 | public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel) throws LoadLayerException, |
||
972 | 42289 | jjdelcerro | DataException { |
973 | 40435 | jjdelcerro | |
974 | return getInfo(p, tolerance, cancel, true); |
||
975 | } |
||
976 | |||
977 | public DynObjectSet getInfo(Point p, |
||
978 | 42289 | jjdelcerro | double tolerance,
|
979 | Cancellable cancel, |
||
980 | boolean fast) throws LoadLayerException, DataException { |
||
981 | 40435 | jjdelcerro | Point2D infop = new Point2D.Double(p.x, p.y); |
982 | Point2D pReal = this.getMapContext().getViewPort().toMapPoint(infop); |
||
983 | return queryByPoint(pReal,
|
||
984 | 42289 | jjdelcerro | tolerance, |
985 | getFeatureStore().getDefaultFeatureType()).getDynObjectSet(fast); |
||
986 | 40435 | jjdelcerro | } |
987 | |||
988 | public DynObjectSet getInfo(org.gvsig.fmap.geom.primitive.Point p,
|
||
989 | 42289 | jjdelcerro | double tolerance) throws LoadLayerException, DataException { |
990 | return queryByPoint(p, tolerance, getFeatureStore().getDefaultFeatureType()).getDynObjectSet(false); |
||
991 | 40435 | jjdelcerro | } |
992 | 42289 | jjdelcerro | |
993 | 42802 | jjdelcerro | @Override
|
994 | 40435 | jjdelcerro | public void legendCleared(LegendClearEvent event) { |
995 | this.updateDrawVersion();
|
||
996 | 42802 | jjdelcerro | LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(legend,event); |
997 | 40435 | jjdelcerro | this.callLegendChanged(e);
|
998 | } |
||
999 | |||
1000 | 42802 | jjdelcerro | @Override
|
1001 | 40435 | jjdelcerro | public boolean symbolChanged(SymbolLegendEvent e) { |
1002 | this.updateDrawVersion();
|
||
1003 | 42802 | jjdelcerro | LegendChangedEvent ev = LegendChangedEvent.createLegendChangedEvent(legend, e); |
1004 | 40435 | jjdelcerro | this.callLegendChanged(ev);
|
1005 | return true; |
||
1006 | } |
||
1007 | |||
1008 | public void update(Observable observable, Object notification) { |
||
1009 | if (observable.equals(this.featureStore)) { |
||
1010 | if (notification instanceof FeatureStoreNotification) { |
||
1011 | 42289 | jjdelcerro | FeatureStoreNotification event |
1012 | = (FeatureStoreNotification) notification; |
||
1013 | 40435 | jjdelcerro | if (event.getType() == FeatureStoreNotification.AFTER_DELETE
|
1014 | 42289 | jjdelcerro | || event.getType() == FeatureStoreNotification.AFTER_UNDO |
1015 | || event.getType() == FeatureStoreNotification.AFTER_REDO |
||
1016 | || event.getType() == FeatureStoreNotification.AFTER_REFRESH |
||
1017 | || event.getType() == FeatureStoreNotification.AFTER_UPDATE |
||
1018 | || event.getType() == FeatureStoreNotification.AFTER_UPDATE_TYPE |
||
1019 | || event.getType() == FeatureStoreNotification.SELECTION_CHANGE |
||
1020 | || event.getType() == FeatureStoreNotification.AFTER_INSERT) { |
||
1021 | 40435 | jjdelcerro | this.updateDrawVersion();
|
1022 | 42289 | jjdelcerro | |
1023 | 40435 | jjdelcerro | } else if (event.getType() == FeatureStoreNotification.AFTER_CANCELEDITING) { |
1024 | 42289 | jjdelcerro | |
1025 | 40435 | jjdelcerro | setSpatialCacheEnabled(false);
|
1026 | callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
||
1027 | this.updateDrawVersion();
|
||
1028 | 42289 | jjdelcerro | |
1029 | 40435 | jjdelcerro | } else if (event.getType() == FeatureStoreNotification.AFTER_STARTEDITING) { |
1030 | 42289 | jjdelcerro | |
1031 | 40435 | jjdelcerro | setSpatialCacheEnabled(true);
|
1032 | callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
||
1033 | |||
1034 | 42289 | jjdelcerro | } else if (event.getType() == FeatureStoreNotification.TRANSFORM_CHANGE) { |
1035 | 40435 | jjdelcerro | //If a transform has to be applied, try to reload the layer.
|
1036 | try {
|
||
1037 | reload(); |
||
1038 | } catch (ReloadLayerException e) {
|
||
1039 | 41132 | jldominguez | logger.info("While reloading layer.", e);
|
1040 | 40435 | jjdelcerro | this.setAvailable(false); |
1041 | } |
||
1042 | } else if (event.getType() == FeatureStoreNotification.RESOURCE_CHANGED) { |
||
1043 | this.setAvailable(false); |
||
1044 | 42289 | jjdelcerro | } else if (event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING) { |
1045 | 40435 | jjdelcerro | this.setAvailable(true); |
1046 | setSpatialCacheEnabled(false);
|
||
1047 | callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
||
1048 | this.updateDrawVersion();
|
||
1049 | } |
||
1050 | } |
||
1051 | 42289 | jjdelcerro | } else if (notification instanceof FeatureDrawnNotification |
1052 | && (isEditing() || isLayerToSnap())) { |
||
1053 | 40614 | jldominguez | // This code is needed in editing mode
|
1054 | 42289 | jjdelcerro | // for all layers involved in snapping
|
1055 | // (including the layer being edited)
|
||
1056 | Geometry geometry |
||
1057 | = ((FeatureDrawnNotification) notification).getDrawnGeometry(); |
||
1058 | 40435 | jjdelcerro | spatialCache.insert(geometry.getEnvelope(), geometry); |
1059 | } |
||
1060 | } |
||
1061 | |||
1062 | 40614 | jldominguez | private boolean isLayerToSnap() { |
1063 | 41223 | jldominguez | |
1064 | if (this.getMapContext() == null) { |
||
1065 | /*
|
||
1066 | * This happens with the graphics layer because it has no parent
|
||
1067 | */
|
||
1068 | return false; |
||
1069 | } else {
|
||
1070 | return this.getMapContext().getLayersToSnap().contains(this); |
||
1071 | } |
||
1072 | 40614 | jldominguez | |
1073 | 42289 | jjdelcerro | /*
|
1074 | Iterator itersnap = this.getMapContext().getLayersToSnap().iterator();
|
||
1075 | Object item = null;
|
||
1076 | while (itersnap.hasNext()) {
|
||
1077 | item = itersnap.next();
|
||
1078 | if (item == this) {
|
||
1079 | return true;
|
||
1080 | }
|
||
1081 | }
|
||
1082 | return false;
|
||
1083 | */
|
||
1084 | } |
||
1085 | |||
1086 | /*
|
||
1087 | 40435 | jjdelcerro | * (non-Javadoc)
|
1088 | 42820 | dmartinezizquierdo | *
|
1089 | 40435 | jjdelcerro | * @see org.gvsig.metadata.Metadata#getMetadataChildren()
|
1090 | */
|
||
1091 | public Set getMetadataChildren() { |
||
1092 | Set ret = new TreeSet(); |
||
1093 | ret.add(this.featureStore);
|
||
1094 | return ret;
|
||
1095 | } |
||
1096 | |||
1097 | /*
|
||
1098 | * (non-Javadoc)
|
||
1099 | 42820 | dmartinezizquierdo | *
|
1100 | 40435 | jjdelcerro | * @see org.gvsig.metadata.Metadata#getMetadataID()
|
1101 | */
|
||
1102 | public Object getMetadataID() throws MetadataException { |
||
1103 | return "Layer(" + this.getName() + "):" |
||
1104 | 42289 | jjdelcerro | + this.featureStore.getMetadataID();
|
1105 | 40435 | jjdelcerro | } |
1106 | |||
1107 | public GeometryType getTypeVectorLayer() throws DataException, |
||
1108 | 42289 | jjdelcerro | LocatorException, |
1109 | GeometryTypeNotSupportedException, |
||
1110 | GeometryTypeNotValidException { |
||
1111 | 40435 | jjdelcerro | // FIXME Esto deberia de pedirse a FType!!!!
|
1112 | FeatureStore fs = this.getFeatureStore();
|
||
1113 | FeatureType fType = fs.getDefaultFeatureType(); |
||
1114 | 42289 | jjdelcerro | FeatureAttributeDescriptor attr |
1115 | = fType.getAttributeDescriptor(fType.getDefaultGeometryAttributeIndex()); |
||
1116 | GeometryType geomType |
||
1117 | = GeometryLocator.getGeometryManager() |
||
1118 | 40435 | jjdelcerro | .getGeometryType(attr.getGeometryType(), |
1119 | 42289 | jjdelcerro | attr.getGeometrySubType()); |
1120 | 40435 | jjdelcerro | return geomType;
|
1121 | } |
||
1122 | |||
1123 | 41840 | jjdelcerro | public static class RegisterPersistence implements Callable { |
1124 | 40435 | jjdelcerro | |
1125 | 41840 | jjdelcerro | public Object call() { |
1126 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
1127 | 40435 | jjdelcerro | |
1128 | 41840 | jjdelcerro | DynStruct definition |
1129 | = manager.addDefinition(FLyrVect.class, |
||
1130 | "FLyrVect",
|
||
1131 | "FLyrVect Persistence definition",
|
||
1132 | null,
|
||
1133 | null);
|
||
1134 | definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, |
||
1135 | "FLyrDefault");
|
||
1136 | |||
1137 | definition.addDynFieldObject("legend")
|
||
1138 | .setClassOfValue(IVectorLegend.class) |
||
1139 | .setMandatory(true);
|
||
1140 | definition.addDynFieldObject("featureStore")
|
||
1141 | .setClassOfValue(FeatureStore.class) |
||
1142 | .setMandatory(true);
|
||
1143 | definition.addDynFieldBoolean("isLabeled").setMandatory(true); |
||
1144 | definition.addDynFieldInt("typeShape").setMandatory(true); |
||
1145 | definition.addDynFieldObject("labelingStrategy")
|
||
1146 | .setClassOfValue(ILabelingStrategy.class) |
||
1147 | .setMandatory(false);
|
||
1148 | |||
1149 | return Boolean.TRUE; |
||
1150 | } |
||
1151 | 40435 | jjdelcerro | } |
1152 | |||
1153 | protected void doDispose() throws BaseException { |
||
1154 | dispose(featureStore); |
||
1155 | spatialCache.clearAll(); |
||
1156 | } |
||
1157 | 42289 | jjdelcerro | |
1158 | 40435 | jjdelcerro | /**
|
1159 | 42289 | jjdelcerro | * Returns envelope in layer's data source CRS from envelope provided in
|
1160 | * viewport CRS
|
||
1161 | *
|
||
1162 | 40435 | jjdelcerro | * @param lyr
|
1163 | * @param env
|
||
1164 | * @return
|
||
1165 | */
|
||
1166 | public static Envelope fromViewPortCRSToSourceCRS(FLayer lyr, Envelope env) { |
||
1167 | |||
1168 | if (lyr == null || env == null) { |
||
1169 | return null; |
||
1170 | } |
||
1171 | |||
1172 | ICoordTrans ct = lyr.getCoordTrans(); |
||
1173 | if (ct == null) { |
||
1174 | return env;
|
||
1175 | } else {
|
||
1176 | return env.convert(ct.getInverted());
|
||
1177 | } |
||
1178 | } |
||
1179 | |||
1180 | 41813 | jjdelcerro | public Geometry transformToSourceCRS(Geometry geom, boolean clone) { |
1181 | 42289 | jjdelcerro | return fromViewPortCRSToSourceCRS(this, geom, clone); |
1182 | 41813 | jjdelcerro | } |
1183 | 42289 | jjdelcerro | |
1184 | 40435 | jjdelcerro | /**
|
1185 | 42289 | jjdelcerro | * Returns geometry in layer's data source CRS from geometry provided in
|
1186 | * viewport CRS
|
||
1187 | *
|
||
1188 | 40435 | jjdelcerro | * @param lyr
|
1189 | * @param geo
|
||
1190 | * @param clone
|
||
1191 | * @return
|
||
1192 | 41813 | jjdelcerro | * @deprecated use the transformToSourceCRS method of layer.
|
1193 | 40435 | jjdelcerro | */
|
1194 | public static Geometry fromViewPortCRSToSourceCRS( |
||
1195 | 42289 | jjdelcerro | FLayer lyr, |
1196 | Geometry geo, |
||
1197 | boolean clone) {
|
||
1198 | |||
1199 | 40435 | jjdelcerro | if (lyr == null || geo == null) { |
1200 | return null; |
||
1201 | } |
||
1202 | ICoordTrans ct = lyr.getCoordTrans(); |
||
1203 | Geometry resp = geo; |
||
1204 | if (clone) {
|
||
1205 | resp = resp.cloneGeometry(); |
||
1206 | } |
||
1207 | if (ct != null) { |
||
1208 | resp.reProject(ct.getInverted()); |
||
1209 | } |
||
1210 | return resp;
|
||
1211 | } |
||
1212 | |||
1213 | 42293 | jjdelcerro | public Iterator iterator() { |
1214 | return this.getFeatureStore().iterator(); |
||
1215 | } |
||
1216 | 42877 | fdiaz | |
1217 | protected class EnvelopeCantBeInitializedException extends BaseException { |
||
1218 | |||
1219 | /**
|
||
1220 | *
|
||
1221 | */
|
||
1222 | private static final long serialVersionUID = 4572797479347381552L; |
||
1223 | private final static String MESSAGE_FORMAT = "The envelope can't be initialized, maybe the layer has a wrong projection. Change the projection in layer properties of the add layer dialog to try fix it."; |
||
1224 | private final static String MESSAGE_KEY = "_EnvelopeCantBeInitializedException"; |
||
1225 | |||
1226 | public EnvelopeCantBeInitializedException() {
|
||
1227 | super(MESSAGE_FORMAT, null, MESSAGE_KEY, serialVersionUID); |
||
1228 | } |
||
1229 | } |
||
1230 | |||
1231 | 40435 | jjdelcerro | } |