Revision 44461
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 | ||
---|---|---|
106 | 106 |
* |
107 | 107 |
*/ |
108 | 108 |
public class FLyrVect |
109 |
extends FLyrDefault |
|
110 |
implements VectorLayer, |
|
111 |
LegendContentsChangedListener, Observer { |
|
109 |
extends FLyrDefault
|
|
110 |
implements VectorLayer,
|
|
111 |
LegendContentsChangedListener, Observer {
|
|
112 | 112 |
|
113 | 113 |
final static private org.slf4j.Logger logger |
114 |
= LoggerFactory.getLogger(FLyrVect.class); |
|
114 |
= LoggerFactory.getLogger(FLyrVect.class);
|
|
115 | 115 |
private final GeometryManager geomManager |
116 |
= GeometryLocator.getGeometryManager(); |
|
116 |
= GeometryLocator.getGeometryManager();
|
|
117 | 117 |
|
118 | 118 |
/** |
119 | 119 |
* Leyenda de la capa vectorial |
... | ... | |
172 | 172 |
* @throws LoadLayerException |
173 | 173 |
*/ |
174 | 174 |
protected void bindToDataStore(DataStore dataStore) throws LoadLayerException { |
175 |
if( this.featureStore != null && this.featureStore != dataStore ) {
|
|
175 |
if (this.featureStore != null && this.featureStore != dataStore) {
|
|
176 | 176 |
this.featureStore.deleteObserver(this); |
177 | 177 |
} |
178 | 178 |
|
179 | 179 |
featureStore = (FeatureStore) dataStore; |
180 | 180 |
|
181 | 181 |
MapContextManager mapContextManager |
182 |
= MapContextLocator.getMapContextManager(); |
|
182 |
= MapContextLocator.getMapContextManager();
|
|
183 | 183 |
|
184 | 184 |
//Set the legend |
185 | 185 |
IVectorLegend legend |
186 |
= (IVectorLegend) mapContextManager.getLegend(dataStore); |
|
186 |
= (IVectorLegend) mapContextManager.getLegend(dataStore);
|
|
187 | 187 |
|
188 |
if( legend == null ) {
|
|
188 |
if (legend == null) {
|
|
189 | 189 |
throw new LegendLayerException(this.getName()); |
190 | 190 |
} |
191 | 191 |
|
... | ... | |
193 | 193 |
|
194 | 194 |
//Set the labeling strategy |
195 | 195 |
ILabelingStrategy labeler |
196 |
= (ILabelingStrategy) mapContextManager.getLabelingStrategy(dataStore); |
|
196 |
= (ILabelingStrategy) mapContextManager.getLabelingStrategy(dataStore);
|
|
197 | 197 |
|
198 |
if( labeler != null ) {
|
|
198 |
if (labeler != null) {
|
|
199 | 199 |
labeler.setLayer(this); |
200 | 200 |
this.setLabelingStrategy(labeler); |
201 | 201 |
this.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? |
... | ... | |
211 | 211 |
|
212 | 212 |
public Envelope getFullEnvelope() throws ReadException { |
213 | 213 |
Envelope rAux; |
214 |
if( getFeatureStore() == null ) {
|
|
214 |
if (getFeatureStore() == null) {
|
|
215 | 215 |
return null; |
216 | 216 |
} |
217 | 217 |
try { |
... | ... | |
222 | 222 |
|
223 | 223 |
// Esto es para cuando se crea una capa nueva con el fullExtent de ancho |
224 | 224 |
// y alto 0. |
225 |
if( rAux == null || rAux.isEmpty() || rAux.getMaximum(0) - rAux.getMinimum(0) == 0
|
|
226 |
&& rAux.getMaximum(1) - rAux.getMinimum(1) == 0 ) {
|
|
225 |
if (rAux == null || rAux.isEmpty() || rAux.getMaximum(0) - rAux.getMinimum(0) == 0
|
|
226 |
&& rAux.getMaximum(1) - rAux.getMinimum(1) == 0) {
|
|
227 | 227 |
try { |
228 | 228 |
rAux |
229 |
= geomManager.createEnvelope(0, 0, 90, 90, SUBTYPES.GEOM2D); |
|
229 |
= geomManager.createEnvelope(0, 0, 90, 90, SUBTYPES.GEOM2D);
|
|
230 | 230 |
} catch (CreateEnvelopeException e) { |
231 | 231 |
logger.error("Error creating the envelope", e); |
232 | 232 |
e.printStackTrace(); |
... | ... | |
234 | 234 |
} |
235 | 235 |
// Si existe reproyecci?n, reproyectar el extent |
236 | 236 |
ICoordTrans ct = getCoordTrans(); |
237 |
if( ct != null ) {
|
|
237 |
if (ct != null) {
|
|
238 | 238 |
boolean originalEnvelopeIsEmpty = rAux.isEmpty(); |
239 | 239 |
rAux = rAux.convert(ct); |
240 |
if( !originalEnvelopeIsEmpty && rAux.isEmpty() ) {
|
|
240 |
if (!originalEnvelopeIsEmpty && rAux.isEmpty()) {
|
|
241 | 241 |
try { |
242 | 242 |
this.setAvailable(false); |
243 | 243 |
throw new EnvelopeCantBeInitializedException(); |
... | ... | |
260 | 260 |
} |
261 | 261 |
|
262 | 262 |
public void addBaseFilter(Evaluator filter) { |
263 |
if( this.baseQuery == null ) {
|
|
263 |
if (this.baseQuery == null) {
|
|
264 | 264 |
this.baseQuery = this.getFeatureStore().createFeatureQuery(); |
265 | 265 |
} |
266 | 266 |
this.baseQuery.addFilter(filter); |
... | ... | |
287 | 287 |
* @throws ReadDriverException |
288 | 288 |
*/ |
289 | 289 |
public void draw(BufferedImage image, |
290 |
Graphics2D g, |
|
291 |
ViewPort viewPort, |
|
292 |
Cancellable cancel, |
|
293 |
double scale) throws ReadException { |
|
290 |
Graphics2D g,
|
|
291 |
ViewPort viewPort,
|
|
292 |
Cancellable cancel,
|
|
293 |
double scale) throws ReadException {
|
|
294 | 294 |
|
295 |
if( legend == null ) {
|
|
295 |
if (legend == null) {
|
|
296 | 296 |
return; |
297 | 297 |
} |
298 | 298 |
|
299 |
if( !this.isWithinScale(scale) ) {
|
|
299 |
if (!this.isWithinScale(scale)) {
|
|
300 | 300 |
return; |
301 | 301 |
} |
302 |
if( cancel.isCanceled() ) {
|
|
302 |
if (cancel.isCanceled()) {
|
|
303 | 303 |
return; |
304 | 304 |
} |
305 | 305 |
|
306 |
if( spatialCache.isEnabled() ) {
|
|
306 |
if (spatialCache.isEnabled()) {
|
|
307 | 307 |
spatialCache.clearAll(); |
308 | 308 |
legend.addDrawingObserver(this); |
309 | 309 |
} |
... | ... | |
312 | 312 |
|
313 | 313 |
try { |
314 | 314 |
FeatureAttributeDescriptor featureAttributeDescriptor |
315 |
= getFeatureStore().getDefaultFeatureType().getDefaultTimeAttribute(); |
|
315 |
= getFeatureStore().getDefaultFeatureType().getDefaultTimeAttribute();
|
|
316 | 316 |
|
317 |
if( (viewPort.getTime() != null) && (featureAttributeDescriptor != null) ) {
|
|
317 |
if ((viewPort.getTime() != null) && (featureAttributeDescriptor != null)) {
|
|
318 | 318 |
IntersectsTimeEvaluator intersectsTimeEvaluator |
319 |
= new IntersectsTimeEvaluator(viewPort.getTime(), featureAttributeDescriptor.getName()); |
|
319 |
= new IntersectsTimeEvaluator(viewPort.getTime(), featureAttributeDescriptor.getName());
|
|
320 | 320 |
featureQuery.addFilter(intersectsTimeEvaluator); |
321 | 321 |
} |
322 | 322 |
} catch (DataException e1) { |
... | ... | |
328 | 328 |
long tini = System.currentTimeMillis(); |
329 | 329 |
|
330 | 330 |
legend.draw(image, |
331 |
g, |
|
332 |
viewPort, |
|
333 |
cancel, |
|
334 |
scale, |
|
335 |
null, |
|
336 |
getCoordTrans(), |
|
337 |
getFeatureStore(), |
|
338 |
featureQuery); |
|
331 |
g,
|
|
332 |
viewPort,
|
|
333 |
cancel,
|
|
334 |
scale,
|
|
335 |
null,
|
|
336 |
getCoordTrans(),
|
|
337 |
getFeatureStore(),
|
|
338 |
featureQuery);
|
|
339 | 339 |
|
340 | 340 |
logger.debug("Layer " + this.getName() + " drawn in " |
341 |
+ (System.currentTimeMillis() - tini) + " milliseconds."); |
|
341 |
+ (System.currentTimeMillis() - tini) + " milliseconds.");
|
|
342 | 342 |
|
343 | 343 |
} catch (LegendException e) { |
344 | 344 |
this.setAvailable(false); |
345 | 345 |
this.setError(e); |
346 | 346 |
throw new ReadException(getName(), e); |
347 | 347 |
} finally { |
348 |
if( spatialCache.isEnabled() ) {
|
|
348 |
if (spatialCache.isEnabled()) {
|
|
349 | 349 |
legend.deleteDrawingObserver(this); |
350 | 350 |
} |
351 | 351 |
} |
352 | 352 |
} |
353 | 353 |
|
354 | 354 |
public void print(Graphics2D g, |
355 |
ViewPort viewPort, |
|
356 |
Cancellable cancel, |
|
357 |
double scale, |
|
358 |
PrintAttributes properties) throws ReadException { |
|
359 |
if( !this.isWithinScale(scale) ) {
|
|
355 |
ViewPort viewPort,
|
|
356 |
Cancellable cancel,
|
|
357 |
double scale,
|
|
358 |
PrintAttributes properties) throws ReadException {
|
|
359 |
if (!this.isWithinScale(scale)) {
|
|
360 | 360 |
return; |
361 | 361 |
} |
362 |
if( cancel.isCanceled() ) {
|
|
362 |
if (cancel.isCanceled()) {
|
|
363 | 363 |
return; |
364 | 364 |
} |
365 | 365 |
FeatureQuery featureQuery = createFeatureQuery(); |
366 | 366 |
|
367 | 367 |
try { |
368 | 368 |
legend.print(g, |
369 |
viewPort, |
|
370 |
cancel, |
|
371 |
scale, |
|
372 |
null, |
|
373 |
getCoordTrans(), |
|
374 |
getFeatureStore(), |
|
375 |
featureQuery, |
|
376 |
properties); |
|
369 |
viewPort,
|
|
370 |
cancel,
|
|
371 |
scale,
|
|
372 |
null,
|
|
373 |
getCoordTrans(),
|
|
374 |
getFeatureStore(),
|
|
375 |
featureQuery,
|
|
376 |
properties);
|
|
377 | 377 |
|
378 | 378 |
} catch (LegendException e) { |
379 | 379 |
this.setVisible(false); |
... | ... | |
383 | 383 |
} |
384 | 384 |
|
385 | 385 |
public void setLegend(IVectorLegend legend) throws LegendLayerException { |
386 |
if( this.legend == legend ) {
|
|
386 |
if (this.legend == legend) {
|
|
387 | 387 |
return; |
388 | 388 |
} |
389 |
if( this.legend != null && this.legend.equals(legend) ) {
|
|
389 |
if (this.legend != null && this.legend.equals(legend)) {
|
|
390 | 390 |
return; |
391 | 391 |
} |
392 | 392 |
IVectorLegend oldLegend = this.legend; |
393 | 393 |
this.legend = legend; |
394 |
if( oldLegend != null ) {
|
|
394 |
if (oldLegend != null) {
|
|
395 | 395 |
oldLegend.removeLegendListener(this); |
396 | 396 |
oldLegend.deleteDrawingObserver(this); |
397 | 397 |
} |
398 |
if( legend != null ) {
|
|
398 |
if (legend != null) {
|
|
399 | 399 |
this.legend.addDrawingObserver(this); |
400 | 400 |
this.legend.addLegendListener(this); |
401 | 401 |
} |
... | ... | |
415 | 415 |
} |
416 | 416 |
|
417 | 417 |
public int getShapeType() throws ReadException { |
418 |
if( typeShape == -1 ) {
|
|
418 |
if (typeShape == -1) {
|
|
419 | 419 |
FeatureType featureType = null; |
420 | 420 |
try { |
421 |
if( getDataStore() != null ) {
|
|
421 |
if (getDataStore() != null) {
|
|
422 | 422 |
featureType |
423 |
= (((FeatureStore) getDataStore()).getDefaultFeatureType()); |
|
423 |
= (((FeatureStore) getDataStore()).getDefaultFeatureType());
|
|
424 | 424 |
} |
425 | 425 |
} catch (DataException e) { |
426 | 426 |
throw new ReadException(getName(), e); |
427 | 427 |
} |
428 |
if( featureType != null ) {
|
|
428 |
if (featureType != null) {
|
|
429 | 429 |
int indexGeom = featureType.getDefaultGeometryAttributeIndex(); |
430 | 430 |
typeShape |
431 |
= featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
|
431 |
= featureType.getAttributeDescriptor(indexGeom).getGeometryType();
|
|
432 | 432 |
} |
433 | 433 |
} |
434 | 434 |
return typeShape; |
... | ... | |
444 | 444 |
public GeometryType getGeometryType() throws ReadException { |
445 | 445 |
FeatureType featureType = null; |
446 | 446 |
try { |
447 |
if( getDataStore() != null ) {
|
|
447 |
if (getDataStore() != null) {
|
|
448 | 448 |
featureType |
449 |
= (((FeatureStore) getDataStore()).getDefaultFeatureType()); |
|
449 |
= (((FeatureStore) getDataStore()).getDefaultFeatureType());
|
|
450 | 450 |
} |
451 | 451 |
} catch (DataException e) { |
452 | 452 |
throw new ReadException(getName(), e); |
453 | 453 |
} |
454 | 454 |
return featureType == null ? null : featureType |
455 |
.getDefaultGeometryAttribute().getGeomType(); |
|
455 |
.getDefaultGeometryAttribute().getGeomType();
|
|
456 | 456 |
} |
457 | 457 |
|
458 | 458 |
public void saveToState(PersistentState state) throws PersistenceException { |
459 | 459 |
|
460 | 460 |
FeatureStore featureStore = null; |
461 | 461 |
|
462 |
if( !this.isAvailable() ) {
|
|
462 |
if (!this.isAvailable()) {
|
|
463 | 463 |
logger.info("The '" + this.getName() + "' layer is not available, it will persist not."); |
464 | 464 |
return; |
465 | 465 |
} |
... | ... | |
467 | 467 |
try { |
468 | 468 |
super.saveToState(state); |
469 | 469 |
|
470 |
if( getLegend() != null ) {
|
|
470 |
if (getLegend() != null) {
|
|
471 | 471 |
state.set("legend", getLegend()); |
472 | 472 |
} |
473 | 473 |
|
474 | 474 |
featureStore = getFeatureStore(); |
475 | 475 |
|
476 |
if( featureStore != null ) {
|
|
476 |
if (featureStore != null) {
|
|
477 | 477 |
state.set("featureStore", featureStore); |
478 | 478 |
} |
479 | 479 |
|
480 | 480 |
state.set("isLabeled", isLabeled); |
481 | 481 |
|
482 |
if( strategy != null ) {
|
|
482 |
if (strategy != null) {
|
|
483 | 483 |
state.set("labelingStrategy", strategy); |
484 | 484 |
} |
485 | 485 |
|
486 |
if( getLinkProperties() != null ) {
|
|
486 |
if (getLinkProperties() != null) {
|
|
487 | 487 |
state.set("linkProperties", getLinkProperties()); |
488 | 488 |
} |
489 | 489 |
|
... | ... | |
511 | 511 |
typeShape = state.getInt("typeShape", Geometry.TYPES.GEOMETRY); |
512 | 512 |
|
513 | 513 |
store = (FeatureStore) state.get("featureStore"); |
514 |
if( store == null ) { // Averiguar como puede llegar aqui un null.
|
|
514 |
if (store == null) { // Averiguar como puede llegar aqui un null.
|
|
515 | 515 |
this.setAvailable(false); |
516 | 516 |
this.addError(new RuntimeException("Can't retrieve store information.")); |
517 | 517 |
} else { |
518 |
if( store.isBroken() ) {
|
|
518 |
if (store.isBroken()) {
|
|
519 | 519 |
this.setAvailable(false); |
520 | 520 |
this.addError(store.getBreakingsCause()); |
521 | 521 |
} |
... | ... | |
536 | 536 |
} |
537 | 537 |
|
538 | 538 |
try { |
539 |
if( state.getBoolean("isLabeled", false) ) {
|
|
539 |
if (state.getBoolean("isLabeled", false)) {
|
|
540 | 540 |
this.setIsLabeled(true); |
541 | 541 |
ILabelingStrategy labelingStrategy = (ILabelingStrategy) state.get("labelingStrategy"); |
542 | 542 |
this.setLabelingStrategy(labelingStrategy); |
... | ... | |
573 | 573 |
|
574 | 574 |
public boolean isEditing() { |
575 | 575 |
FeatureStore fs = getFeatureStore(); |
576 |
if( fs == null ) {
|
|
576 |
if (fs == null) {
|
|
577 | 577 |
/* |
578 | 578 |
* This happens when layer is not available, for example, |
579 | 579 |
* it was not possible to load from persistence |
... | ... | |
592 | 592 |
logger.info("This method is deprecated. ", th); |
593 | 593 |
} |
594 | 594 |
|
595 |
if( b == super.isEditing() ) {
|
|
595 |
if (b == super.isEditing()) {
|
|
596 | 596 |
return; |
597 | 597 |
} |
598 | 598 |
|
599 | 599 |
super.setEditing(b); |
600 | 600 |
FeatureStore fs = getFeatureStore(); |
601 |
if( b ) {
|
|
601 |
if (b) {
|
|
602 | 602 |
try { |
603 | 603 |
fs.edit(); |
604 | 604 |
} catch (DataException e) { |
... | ... | |
640 | 640 |
* @param maxFeatures |
641 | 641 |
*/ |
642 | 642 |
public void setMaxFeaturesInEditionCache(int maxFeatures) { |
643 |
if( maxFeatures > spatialCache.getMaxFeatures() ) {
|
|
643 |
if (maxFeatures > spatialCache.getMaxFeatures()) {
|
|
644 | 644 |
spatialCache.setMaxFeatures(maxFeatures); |
645 | 645 |
} |
646 | 646 |
|
... | ... | |
686 | 686 |
} |
687 | 687 |
|
688 | 688 |
protected void putLoadLegend() throws LegendLayerException { |
689 |
if( this.loadLegend == null ) {
|
|
689 |
if (this.loadLegend == null) {
|
|
690 | 690 |
return; |
691 | 691 |
} |
692 | 692 |
this.setLegend(this.loadLegend); |
... | ... | |
716 | 716 |
|
717 | 717 |
clonedLayer.setIsLabeled(isLabeled()); |
718 | 718 |
ILabelingStrategy labelingStrategy = getLabelingStrategy(); |
719 |
if( labelingStrategy != null ) {
|
|
719 |
if (labelingStrategy != null) {
|
|
720 | 720 |
clonedLayer.setLabelingStrategy(labelingStrategy); |
721 | 721 |
} |
722 | 722 |
|
... | ... | |
724 | 724 |
} |
725 | 725 |
|
726 | 726 |
protected boolean isOnePoint(AffineTransform graphicsTransform, |
727 |
ViewPort viewPort, |
|
728 |
double dpi, |
|
729 |
CartographicSupport csSym, |
|
730 |
Geometry geom, |
|
731 |
int[] xyCoords) { |
|
727 |
ViewPort viewPort,
|
|
728 |
double dpi,
|
|
729 |
CartographicSupport csSym,
|
|
730 |
Geometry geom,
|
|
731 |
int[] xyCoords) {
|
|
732 | 732 |
return isOnePoint(graphicsTransform, viewPort, geom, xyCoords) |
733 |
&& csSym.getCartographicSize(viewPort, dpi, geom) <= 1; |
|
733 |
&& csSym.getCartographicSize(viewPort, dpi, geom) <= 1;
|
|
734 | 734 |
} |
735 | 735 |
|
736 | 736 |
private boolean isOnePoint(AffineTransform graphicsTransform, |
737 |
ViewPort viewPort, |
|
738 |
Geometry geom, |
|
739 |
int[] xyCoords) { |
|
737 |
ViewPort viewPort,
|
|
738 |
Geometry geom,
|
|
739 |
int[] xyCoords) {
|
|
740 | 740 |
boolean onePoint = false; |
741 | 741 |
int type = geom.getType(); |
742 |
if( type == Geometry.TYPES.NULL ) {
|
|
742 |
if (type == Geometry.TYPES.NULL) {
|
|
743 | 743 |
return false; |
744 | 744 |
} |
745 |
if( type != Geometry.TYPES.POINT && type != Geometry.TYPES.MULTIPOINT ) {
|
|
745 |
if (type != Geometry.TYPES.POINT && type != Geometry.TYPES.MULTIPOINT) {
|
|
746 | 746 |
|
747 | 747 |
Envelope geomBounds = geom.getEnvelope(); |
748 | 748 |
|
... | ... | |
755 | 755 |
double dist1Pixel = viewPort.getDist1pixel(); |
756 | 756 |
|
757 | 757 |
onePoint |
758 |
= (geomBounds.getLength(0) <= dist1Pixel && geomBounds.getLength(1) <= dist1Pixel); |
|
758 |
= (geomBounds.getLength(0) <= dist1Pixel && geomBounds.getLength(1) <= dist1Pixel);
|
|
759 | 759 |
|
760 |
if( onePoint ) {
|
|
760 |
if (onePoint) {
|
|
761 | 761 |
// avoid out of range exceptions |
762 | 762 |
org.gvsig.fmap.geom.primitive.Point p; |
763 | 763 |
try { |
764 | 764 |
p |
765 |
= geomManager.createPoint(geomBounds.getMinimum(0), |
|
766 |
geomBounds.getMinimum(1), |
|
767 |
SUBTYPES.GEOM2D); |
|
765 |
= geomManager.createPoint(geomBounds.getMinimum(0),
|
|
766 |
geomBounds.getMinimum(1),
|
|
767 |
SUBTYPES.GEOM2D);
|
|
768 | 768 |
p.transform(viewPort.getAffineTransform()); |
769 | 769 |
p.transform(graphicsTransform); |
770 | 770 |
xyCoords[0] = (int) p.getX(); |
... | ... | |
793 | 793 |
|
794 | 794 |
public void setLabelingStrategy(ILabelingStrategy strategy) { |
795 | 795 |
this.strategy = strategy; |
796 |
if( strategy == null ) {
|
|
796 |
if (strategy == null) {
|
|
797 | 797 |
return; |
798 | 798 |
} |
799 | 799 |
strategy.setLayer(this); |
... | ... | |
801 | 801 |
} |
802 | 802 |
|
803 | 803 |
public void drawLabels(BufferedImage image, |
804 |
Graphics2D g, |
|
805 |
ViewPort viewPort, |
|
806 |
Cancellable cancel, |
|
807 |
double scale, |
|
808 |
double dpi) throws ReadException { |
|
809 |
if( strategy != null && isWithinScale(scale) ) {
|
|
804 |
Graphics2D g,
|
|
805 |
ViewPort viewPort,
|
|
806 |
Cancellable cancel,
|
|
807 |
double scale,
|
|
808 |
double dpi) throws ReadException {
|
|
809 |
if (strategy != null && isWithinScale(scale)) {
|
|
810 | 810 |
strategy.draw(image, g, scale, viewPort, cancel, dpi); |
811 | 811 |
} |
812 | 812 |
} |
813 | 813 |
|
814 | 814 |
public void printLabels(Graphics2D g, |
815 |
ViewPort viewPort, |
|
816 |
Cancellable cancel, |
|
817 |
double scale, |
|
818 |
PrintAttributes properties) throws ReadException { |
|
819 |
if( strategy != null ) {
|
|
815 |
ViewPort viewPort,
|
|
816 |
Cancellable cancel,
|
|
817 |
double scale,
|
|
818 |
PrintAttributes properties) throws ReadException {
|
|
819 |
if (strategy != null) {
|
|
820 | 820 |
strategy.print(g, scale, viewPort, cancel, properties); |
821 | 821 |
} |
822 | 822 |
} |
... | ... | |
839 | 839 |
} |
840 | 840 |
|
841 | 841 |
public FeatureQuery createFeatureQuery() { |
842 |
if( this.baseQuery == null ) {
|
|
842 |
if (this.baseQuery == null) {
|
|
843 | 843 |
return this.getFeatureStore().createFeatureQuery(); |
844 | 844 |
} |
845 | 845 |
try { |
... | ... | |
854 | 854 |
* {@link #queryByPoint(org.gvsig.fmap.geom.primitive.Point, double, FeatureType)} |
855 | 855 |
*/ |
856 | 856 |
public FeatureSet queryByPoint(Point2D mapPoint, |
857 |
double tol, |
|
858 |
FeatureType featureType) throws DataException { |
|
857 |
double tol,
|
|
858 |
FeatureType featureType) throws DataException {
|
|
859 | 859 |
logger.warn("Deprecated use of queryByPoint."); |
860 | 860 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
861 | 861 |
org.gvsig.fmap.geom.primitive.Point center; |
862 | 862 |
try { |
863 | 863 |
center |
864 |
= (org.gvsig.fmap.geom.primitive.Point) manager.create(TYPES.POINT, |
|
865 |
SUBTYPES.GEOM2D); |
|
864 |
= (org.gvsig.fmap.geom.primitive.Point) manager.create(TYPES.POINT,
|
|
865 |
SUBTYPES.GEOM2D);
|
|
866 | 866 |
center.setX(mapPoint.getX()); |
867 | 867 |
center.setY(mapPoint.getY()); |
868 | 868 |
Circle circle |
869 |
= (Circle) manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D); |
|
869 |
= (Circle) manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
|
|
870 | 870 |
circle.setPoints(center, tol); |
871 | 871 |
return queryByGeometry(circle, featureType); |
872 | 872 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) { |
... | ... | |
875 | 875 |
} |
876 | 876 |
|
877 | 877 |
public FeatureSet queryByPoint(org.gvsig.fmap.geom.primitive.Point point, |
878 |
double tol, |
|
879 |
FeatureType featureType) throws DataException { |
|
878 |
double tol,
|
|
879 |
FeatureType featureType) throws DataException {
|
|
880 | 880 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
881 | 881 |
try { |
882 | 882 |
Circle circle |
883 |
= (Circle) manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D); |
|
883 |
= (Circle) manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
|
|
884 | 884 |
circle.setPoints(point, tol); |
885 | 885 |
return queryByGeometry(circle, featureType); |
886 | 886 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) { |
... | ... | |
902 | 902 |
|
903 | 903 |
Geometry query_geo = this.transformToSourceCRS(geom, true); |
904 | 904 |
IProjection query_proj = getMapContext().getProjection(); |
905 |
if( this.getCoordTrans() != null ) {
|
|
905 |
if (this.getCoordTrans() != null) {
|
|
906 | 906 |
query_proj = this.getCoordTrans().getPOrig(); |
907 | 907 |
} |
908 | 908 |
Evaluator iee = SpatialEvaluatorsFactory.getInstance().intersects( |
909 |
query_geo, |
|
910 |
query_proj, |
|
911 |
featureStore |
|
909 |
query_geo,
|
|
910 |
query_proj,
|
|
911 |
featureStore
|
|
912 | 912 |
); |
913 | 913 |
featureQuery.setFilter(iee); |
914 | 914 |
featureQuery.setAttributeNames(null); |
... | ... | |
941 | 941 |
* @throws DataException |
942 | 942 |
*/ |
943 | 943 |
public FeatureSet queryByEnvelope(Envelope envelope, |
944 |
FeatureType featureType, |
|
945 |
String[] names) throws DataException { |
|
944 |
FeatureType featureType,
|
|
945 |
String[] names) throws DataException {
|
|
946 | 946 |
FeatureQuery featureQuery = createFeatureQuery(); |
947 |
if( names == null ) {
|
|
947 |
if (names == null) {
|
|
948 | 948 |
featureQuery.setFeatureType(featureType); |
949 | 949 |
} else { |
950 | 950 |
featureQuery.setAttributeNames(names); |
... | ... | |
953 | 953 |
|
954 | 954 |
Envelope query_env = fromViewPortCRSToSourceCRS(this, envelope); |
955 | 955 |
IProjection query_proj = getMapContext().getProjection(); |
956 |
if( this.getCoordTrans() != null ) {
|
|
956 |
if (this.getCoordTrans() != null) {
|
|
957 | 957 |
query_proj = this.getCoordTrans().getPOrig(); |
958 | 958 |
} |
959 | 959 |
|
960 | 960 |
Evaluator iee = SpatialEvaluatorsFactory.getInstance().intersects( |
961 |
query_env.getGeometry(), |
|
962 |
query_proj, |
|
963 |
featureStore |
|
961 |
query_env.getGeometry(),
|
|
962 |
query_proj,
|
|
963 |
featureStore
|
|
964 | 964 |
); |
965 | 965 |
featureQuery.setFilter(iee); |
966 | 966 |
return getFeatureStore().getFeatureSet(featureQuery); |
... | ... | |
968 | 968 |
} |
969 | 969 |
|
970 | 970 |
public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel) throws LoadLayerException, |
971 |
DataException { |
|
971 |
DataException {
|
|
972 | 972 |
|
973 | 973 |
return getInfo(p, tolerance, cancel, true); |
974 | 974 |
} |
975 | 975 |
|
976 | 976 |
public DynObjectSet getInfo(Point p, |
977 |
double tolerance, |
|
978 |
Cancellable cancel, |
|
979 |
boolean fast) throws LoadLayerException, DataException { |
|
977 |
double tolerance,
|
|
978 |
Cancellable cancel,
|
|
979 |
boolean fast) throws LoadLayerException, DataException {
|
|
980 | 980 |
Point2D infop = new Point2D.Double(p.x, p.y); |
981 | 981 |
Point2D pReal = this.getMapContext().getViewPort().toMapPoint(infop); |
982 | 982 |
return queryByPoint(pReal, |
983 |
tolerance, |
|
984 |
getFeatureStore().getDefaultFeatureType()).getDynObjectSet(fast); |
|
983 |
tolerance,
|
|
984 |
getFeatureStore().getDefaultFeatureType()).getDynObjectSet(fast);
|
|
985 | 985 |
} |
986 | 986 |
|
987 | 987 |
public DynObjectSet getInfo(org.gvsig.fmap.geom.primitive.Point p, |
988 |
double tolerance) throws LoadLayerException, DataException { |
|
988 |
double tolerance) throws LoadLayerException, DataException {
|
|
989 | 989 |
return queryByPoint(p, tolerance, getFeatureStore().getDefaultFeatureType()).getDynObjectSet(false); |
990 | 990 |
} |
991 | 991 |
|
... | ... | |
1005 | 1005 |
} |
1006 | 1006 |
|
1007 | 1007 |
public void update(Observable observable, Object notification) { |
1008 |
if( observable.equals(this.featureStore) ) {
|
|
1009 |
if( notification instanceof FeatureStoreNotification ) {
|
|
1008 |
if (observable.equals(this.featureStore)) {
|
|
1009 |
if (notification instanceof FeatureStoreNotification) {
|
|
1010 | 1010 |
FeatureStoreNotification event |
1011 |
= (FeatureStoreNotification) notification; |
|
1012 |
if( event.getType() == FeatureStoreNotification.AFTER_DELETE
|
|
1013 |
|| event.getType() == FeatureStoreNotification.AFTER_UNDO |
|
1014 |
|| event.getType() == FeatureStoreNotification.AFTER_REDO |
|
1015 |
|| event.getType() == FeatureStoreNotification.AFTER_REFRESH |
|
1016 |
|| event.getType() == FeatureStoreNotification.AFTER_UPDATE |
|
1017 |
|| event.getType() == FeatureStoreNotification.AFTER_UPDATE_TYPE |
|
1018 |
|| event.getType() == FeatureStoreNotification.SELECTION_CHANGE |
|
1019 |
|| event.getType() == FeatureStoreNotification.AFTER_INSERT ) {
|
|
1011 |
= (FeatureStoreNotification) notification;
|
|
1012 |
if (event.getType() == FeatureStoreNotification.AFTER_DELETE
|
|
1013 |
|| event.getType() == FeatureStoreNotification.AFTER_UNDO
|
|
1014 |
|| event.getType() == FeatureStoreNotification.AFTER_REDO
|
|
1015 |
|| event.getType() == FeatureStoreNotification.AFTER_REFRESH
|
|
1016 |
|| event.getType() == FeatureStoreNotification.AFTER_UPDATE
|
|
1017 |
|| event.getType() == FeatureStoreNotification.AFTER_UPDATE_TYPE
|
|
1018 |
|| event.getType() == FeatureStoreNotification.SELECTION_CHANGE
|
|
1019 |
|| event.getType() == FeatureStoreNotification.AFTER_INSERT) {
|
|
1020 | 1020 |
this.updateDrawVersion(); |
1021 | 1021 |
|
1022 |
} else if( event.getType() == FeatureStoreNotification.AFTER_CANCELEDITING ) {
|
|
1022 |
} else if (event.getType() == FeatureStoreNotification.AFTER_CANCELEDITING) {
|
|
1023 | 1023 |
|
1024 | 1024 |
setSpatialCacheEnabled(false); |
1025 | 1025 |
callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
1026 | 1026 |
this.updateDrawVersion(); |
1027 | 1027 |
|
1028 |
} else if( event.getType() == FeatureStoreNotification.AFTER_STARTEDITING ) {
|
|
1028 |
} else if (event.getType() == FeatureStoreNotification.AFTER_STARTEDITING) {
|
|
1029 | 1029 |
|
1030 | 1030 |
setSpatialCacheEnabled(true); |
1031 | 1031 |
callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
1032 | 1032 |
|
1033 |
} else if( event.getType() == FeatureStoreNotification.TRANSFORM_CHANGE ) {
|
|
1033 |
} else if (event.getType() == FeatureStoreNotification.TRANSFORM_CHANGE) {
|
|
1034 | 1034 |
//If a transform has to be applied, try to reload the layer. |
1035 | 1035 |
try { |
1036 | 1036 |
reload(); |
... | ... | |
1038 | 1038 |
logger.info("While reloading layer.", e); |
1039 | 1039 |
this.setAvailable(false); |
1040 | 1040 |
} |
1041 |
} else if( event.getType() == FeatureStoreNotification.RESOURCE_CHANGED ) {
|
|
1041 |
} else if (event.getType() == FeatureStoreNotification.RESOURCE_CHANGED) {
|
|
1042 | 1042 |
this.setAvailable(false); |
1043 |
} else if( event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING ) {
|
|
1043 |
} else if (event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING) {
|
|
1044 | 1044 |
this.setAvailable(true); |
1045 | 1045 |
setSpatialCacheEnabled(false); |
1046 | 1046 |
callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
1047 | 1047 |
this.updateDrawVersion(); |
1048 | 1048 |
} |
1049 | 1049 |
} |
1050 |
} else if( notification instanceof FeatureDrawnNotification
|
|
1051 |
&& (isEditing() || isLayerToSnap()) ) {
|
|
1050 |
} else if (notification instanceof FeatureDrawnNotification
|
|
1051 |
&& (isEditing() || isLayerToSnap())) {
|
|
1052 | 1052 |
// This code is needed in editing mode |
1053 | 1053 |
// for all layers involved in snapping |
1054 | 1054 |
// (including the layer being edited) |
1055 | 1055 |
Geometry geometry |
1056 |
= ((FeatureDrawnNotification) notification).getDrawnGeometry(); |
|
1056 |
= ((FeatureDrawnNotification) notification).getDrawnGeometry();
|
|
1057 | 1057 |
spatialCache.insert(geometry.getEnvelope(), geometry); |
1058 | 1058 |
} |
1059 | 1059 |
} |
1060 | 1060 |
|
1061 | 1061 |
private boolean isLayerToSnap() { |
1062 | 1062 |
|
1063 |
if( this.getMapContext() == null ) {
|
|
1063 |
if (this.getMapContext() == null) {
|
|
1064 | 1064 |
/* |
1065 | 1065 |
* This happens with the graphics layer because it has no parent |
1066 | 1066 |
*/ |
... | ... | |
1100 | 1100 |
*/ |
1101 | 1101 |
public Object getMetadataID() throws MetadataException { |
1102 | 1102 |
return "Layer(" + this.getName() + "):" |
1103 |
+ this.featureStore.getMetadataID(); |
|
1103 |
+ this.featureStore.getMetadataID();
|
|
1104 | 1104 |
} |
1105 | 1105 |
|
1106 | 1106 |
public GeometryType getTypeVectorLayer() throws DataException, |
1107 |
LocatorException, |
|
1108 |
GeometryTypeNotSupportedException, |
|
1109 |
GeometryTypeNotValidException { |
|
1107 |
LocatorException,
|
|
1108 |
GeometryTypeNotSupportedException,
|
|
1109 |
GeometryTypeNotValidException {
|
|
1110 | 1110 |
// FIXME Esto deberia de pedirse a FType!!!! |
1111 | 1111 |
FeatureStore fs = this.getFeatureStore(); |
1112 | 1112 |
FeatureType fType = fs.getDefaultFeatureType(); |
1113 | 1113 |
FeatureAttributeDescriptor attr |
1114 |
= fType.getAttributeDescriptor(fType.getDefaultGeometryAttributeIndex()); |
|
1114 |
= fType.getAttributeDescriptor(fType.getDefaultGeometryAttributeIndex());
|
|
1115 | 1115 |
GeometryType geomType |
1116 |
= GeometryLocator.getGeometryManager() |
|
1117 |
.getGeometryType(attr.getGeometryType(), |
|
1118 |
attr.getGeometrySubType()); |
|
1116 |
= GeometryLocator.getGeometryManager()
|
|
1117 |
.getGeometryType(attr.getGeometryType(),
|
|
1118 |
attr.getGeometrySubType());
|
|
1119 | 1119 |
return geomType; |
1120 | 1120 |
} |
1121 | 1121 |
|
1122 | 1122 |
public static class RegisterPersistence |
1123 |
implements Callable { |
|
1123 |
implements Callable {
|
|
1124 | 1124 |
|
1125 | 1125 |
public Object call() { |
1126 | 1126 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
1127 | 1127 |
|
1128 | 1128 |
DynStruct definition |
1129 |
= manager.addDefinition(FLyrVect.class, |
|
1130 |
"FLyrVect", |
|
1131 |
"FLyrVect Persistence definition", |
|
1132 |
null, |
|
1133 |
null); |
|
1129 |
= manager.addDefinition(FLyrVect.class,
|
|
1130 |
"FLyrVect",
|
|
1131 |
"FLyrVect Persistence definition",
|
|
1132 |
null,
|
|
1133 |
null);
|
|
1134 | 1134 |
definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, |
1135 |
"FLyrDefault"); |
|
1135 |
"FLyrDefault");
|
|
1136 | 1136 |
|
1137 | 1137 |
definition.addDynFieldObject("legend") |
1138 |
.setClassOfValue(IVectorLegend.class) |
|
1139 |
.setMandatory(true); |
|
1138 |
.setClassOfValue(IVectorLegend.class)
|
|
1139 |
.setMandatory(true);
|
|
1140 | 1140 |
definition.addDynFieldObject("featureStore") |
1141 |
.setClassOfValue(FeatureStore.class) |
|
1142 |
.setMandatory(true); |
|
1141 |
.setClassOfValue(FeatureStore.class)
|
|
1142 |
.setMandatory(true);
|
|
1143 | 1143 |
definition.addDynFieldBoolean("isLabeled").setMandatory(true); |
1144 | 1144 |
definition.addDynFieldInt("typeShape").setMandatory(true); |
1145 | 1145 |
definition.addDynFieldObject("labelingStrategy") |
1146 |
.setClassOfValue(ILabelingStrategy.class) |
|
1147 |
.setMandatory(false); |
|
1146 |
.setClassOfValue(ILabelingStrategy.class)
|
|
1147 |
.setMandatory(false);
|
|
1148 | 1148 |
|
1149 | 1149 |
return Boolean.TRUE; |
1150 | 1150 |
} |
... | ... | |
1165 | 1165 |
*/ |
1166 | 1166 |
public static Envelope fromViewPortCRSToSourceCRS(FLayer lyr, Envelope env) { |
1167 | 1167 |
|
1168 |
if( lyr == null || env == null ) {
|
|
1168 |
if (lyr == null || env == null) {
|
|
1169 | 1169 |
return null; |
1170 | 1170 |
} |
1171 | 1171 |
|
1172 | 1172 |
ICoordTrans ct = lyr.getCoordTrans(); |
1173 |
if( ct == null ) {
|
|
1173 |
if (ct == null) {
|
|
1174 | 1174 |
return env; |
1175 | 1175 |
} else { |
1176 | 1176 |
return env.convert(ct.getInverted()); |
... | ... | |
1192 | 1192 |
* @deprecated use the transformToSourceCRS method of layer. |
1193 | 1193 |
*/ |
1194 | 1194 |
public static Geometry fromViewPortCRSToSourceCRS( |
1195 |
FLayer lyr, |
|
1196 |
Geometry geo, |
|
1197 |
boolean clone) { |
|
1195 |
FLayer lyr,
|
|
1196 |
Geometry geo,
|
|
1197 |
boolean clone) {
|
|
1198 | 1198 |
|
1199 |
if( lyr == null || geo == null ) {
|
|
1199 |
if (lyr == null || geo == null) {
|
|
1200 | 1200 |
return null; |
1201 | 1201 |
} |
1202 | 1202 |
ICoordTrans ct = lyr.getCoordTrans(); |
1203 | 1203 |
Geometry resp = geo; |
1204 |
if( clone ) {
|
|
1204 |
if (clone) {
|
|
1205 | 1205 |
resp = resp.cloneGeometry(); |
1206 | 1206 |
} |
1207 |
if( ct != null ) {
|
|
1207 |
if (ct != null) {
|
|
1208 | 1208 |
resp.reProject(ct.getInverted()); |
1209 | 1209 |
} |
1210 | 1210 |
return resp; |
... | ... | |
1215 | 1215 |
} |
1216 | 1216 |
|
1217 | 1217 |
protected class EnvelopeCantBeInitializedException |
1218 |
extends BaseException { |
|
1218 |
extends BaseException {
|
|
1219 | 1219 |
|
1220 | 1220 |
/** |
1221 | 1221 |
* |
... | ... | |
1233 | 1233 |
public String getInfoString() { |
1234 | 1234 |
LayerInformationBuilder builder = MapContextLocator.getMapContextManager().createLayerInformationBuilder(); |
1235 | 1235 |
|
1236 |
if( !this.isAvailable() ) {
|
|
1236 |
if (!this.isAvailable()) {
|
|
1237 | 1237 |
builder.title().labelkey("Warning"); |
1238 | 1238 |
builder.text().value("The layer is not available."); |
1239 | 1239 |
} |
1240 |
|
|
1240 |
|
|
1241 | 1241 |
Envelope env = null; |
1242 | 1242 |
FeatureAttributeDescriptor attrgeom = null; |
1243 |
|
|
1243 |
|
|
1244 | 1244 |
try { |
1245 | 1245 |
env = this.getFullEnvelope(); |
1246 | 1246 |
} catch (Exception ex) { |
... | ... | |
1255 | 1255 |
builder.title().labelkey("Data_source"); |
1256 | 1256 |
builder.property().labelkey("Source_type").value(store.getProviderName()); |
1257 | 1257 |
builder.property().labelkey("origen").value(store.getFullName()); |
1258 |
if( store.getParameters() instanceof FilesystemStoreParameters ) {
|
|
1258 |
if (store.getParameters() instanceof FilesystemStoreParameters) {
|
|
1259 | 1259 |
File f = ((FilesystemStoreParameters) (store.getParameters())).getFile(); |
1260 |
if( f != null && f.exists() ) {
|
|
1260 |
if (f != null && f.exists()) {
|
|
1261 | 1261 |
builder.property().labelkey("_Size").value("%d bytes", f.length()); |
1262 | 1262 |
} |
1263 | 1263 |
} |
1264 |
if( attrgeom != null ) {
|
|
1264 |
if (attrgeom != null) {
|
|
1265 | 1265 |
builder.property().labelkey("_Geometry_column").value(attrgeom.getName()); |
1266 | 1266 |
builder.property().labelkey("_Geometry_type").value(attrgeom.getGeomType().getFullName()); |
1267 | 1267 |
} |
1268 | 1268 |
|
1269 | 1269 |
builder.title().labelkey("_Coordenadas_geograficas"); |
1270 |
if( this.isAvailable() ) {
|
|
1270 |
if (this.isAvailable()) {
|
|
1271 | 1271 |
builder.envelope().value(env); |
1272 | 1272 |
} |
1273 | 1273 |
|
1274 | 1274 |
builder.title().labelkey("_Projection"); |
1275 |
if( this.isAvailable() ) {
|
|
1275 |
if (this.isAvailable()) {
|
|
1276 | 1276 |
builder.property().value(this.getProjection()); |
1277 | 1277 |
builder.text().asWKT(this.getProjection()); |
1278 | 1278 |
} |
1279 | 1279 |
return builder.toString(); |
1280 | 1280 |
} |
1281 | 1281 |
|
1282 |
@Override |
|
1283 |
public boolean isTemporary() { |
|
1284 |
if (this.featureStore != null) { |
|
1285 |
if (this.featureStore.isTemporary()) { |
|
1286 |
return true; |
|
1287 |
} |
|
1288 |
} |
|
1289 |
return super.isTemporary(); |
|
1290 |
} |
|
1282 | 1291 |
} |
Also available in: Unified diff