Revision 47669 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/store/simplereader/SimpleReaderStoreProvider.java
SimpleReaderStoreProvider.java | ||
---|---|---|
93 | 93 |
import org.gvsig.tools.exception.BaseException; |
94 | 94 |
import org.gvsig.tools.exception.NotYetImplemented; |
95 | 95 |
import org.gvsig.tools.i18n.I18nManager; |
96 |
import org.gvsig.tools.logger.FilteredLogger; |
|
96 | 97 |
import org.gvsig.tools.persistence.PersistentState; |
97 | 98 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
98 | 99 |
import org.gvsig.tools.task.SimpleTaskStatus; |
... | ... | |
100 | 101 |
import org.gvsig.tools.task.UserCancelTaskException; |
101 | 102 |
import org.gvsig.tools.util.GetItemWithSize64; |
102 | 103 |
import org.gvsig.tools.visitor.VisitCanceledException; |
103 |
import org.gvsig.tools.visitor.Visitor; |
|
104 | 104 |
import org.slf4j.Logger; |
105 | 105 |
import org.slf4j.LoggerFactory; |
106 | 106 |
|
... | ... | |
109 | 109 |
ResourceConsumer { |
110 | 110 |
|
111 | 111 |
protected static final Logger LOGGER = LoggerFactory.getLogger(SimpleReaderStoreProvider.class); |
112 |
|
|
113 |
private static FilteredLogger timedLogger; |
|
112 | 114 |
|
113 | 115 |
protected final ResourceProvider resource; |
114 | 116 |
|
... | ... | |
267 | 269 |
} |
268 | 270 |
} |
269 | 271 |
|
272 |
@Override |
|
270 | 273 |
public Envelope getEnvelope(String geomName) throws DataException { |
271 | 274 |
this.open(); |
272 | 275 |
if(geomName == null){ |
... | ... | |
290 | 293 |
if (!this.need_calculate_envelope) { |
291 | 294 |
return null; |
292 | 295 |
} |
296 |
final Envelope theEnv; |
|
293 | 297 |
try { |
294 | 298 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
295 | 299 |
this.taskStatus.add(); |
... | ... | |
298 | 302 |
FeatureType ft = fs.getDefaultFeatureType(); |
299 | 303 |
FeatureAttributeDescriptor fad = ft.getAttributeDescriptor(ft.getDefaultGeometryAttributeIndex()); |
300 | 304 |
this.taskStatus.setRangeOfValues(0, fs.getFeatureCount()); |
301 |
env = GeometryLocator.getGeometryManager().createEnvelope(fad.getGeomType().getSubType()); |
|
302 |
fs.accept(new Visitor() { |
|
303 |
@Override |
|
304 |
public void visit(Object obj) throws VisitCanceledException, BaseException { |
|
305 |
taskStatus.incrementCurrentValue(); |
|
306 |
if(taskStatus.isCancellationRequested()){ |
|
307 |
taskStatus.cancel(); |
|
308 |
throw new VisitCanceledException(); |
|
305 |
theEnv = GeometryLocator.getGeometryManager().createEnvelope(fad.getGeomType().getSubType()); |
|
306 |
final String theGeomName = geomName; |
|
307 |
fs.accept((Object obj) -> { |
|
308 |
taskStatus.incrementCurrentValue(); |
|
309 |
if(taskStatus.isCancellationRequested()){ |
|
310 |
taskStatus.cancel(); |
|
311 |
throw new VisitCanceledException(); |
|
312 |
} |
|
313 |
Feature f = (Feature) obj; |
|
314 |
Geometry geom = f.getGeometry(theGeomName); |
|
315 |
if (geom != null) { |
|
316 |
try { |
|
317 |
Envelope envelope = geom.getEnvelope(); |
|
318 |
theEnv.add(envelope); |
|
319 |
} catch(Exception ex) { |
|
320 |
LOGGER.warn("Can't calculate envelop of geometry in feature '"+Objects.toString(f.getReference())+"'.",ex); |
|
309 | 321 |
} |
310 |
Feature f = (Feature) obj; |
|
311 |
Geometry geom = f.getDefaultGeometry(); |
|
312 |
if (geom != null) { |
|
313 |
try { |
|
314 |
Envelope env = geom.getEnvelope(); |
|
315 |
env.add(env); |
|
316 |
} catch(Exception ex) { |
|
317 |
LOGGER.warn("Can't calculate envelop of geometry in feature '"+Objects.toString(f.getReference())+"'.",ex); |
|
318 |
} |
|
319 |
} |
|
320 | 322 |
} |
321 | 323 |
}); |
322 |
bboxFileSave("_"+geomName,env);
|
|
324 |
bboxFileSave("_"+theGeomName,theEnv);
|
|
323 | 325 |
taskStatus.terminate(); |
324 | 326 |
} catch (VisitCanceledException e) { |
325 | 327 |
return null; |
... | ... | |
330 | 332 |
} |
331 | 333 |
|
332 | 334 |
this.need_calculate_envelope = false; |
333 |
return env;
|
|
335 |
return theEnv;
|
|
334 | 336 |
|
335 | 337 |
} |
336 | 338 |
|
... | ... | |
534 | 536 |
protected void loadFeatures() { |
535 | 537 |
InputStreamReader in = null; |
536 | 538 |
SimpleReader reader = null; |
539 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
540 |
|
|
537 | 541 |
try { |
538 | 542 |
taskStatus.setTitle(this.getProviderName()+" "+this.getName()); |
539 | 543 |
taskStatus.add(); |
... | ... | |
573 | 577 |
throw new UserCancelTaskException(); |
574 | 578 |
} |
575 | 579 |
if (this.virtualrows == null) { |
580 |
this.spatialIndexes = new HashMap<>(); |
|
576 | 581 |
|
577 | 582 |
taskStatus.message(i18n.getTranslation("_Loading")); |
578 | 583 |
taskStatus.setIndeterminate(); |
... | ... | |
592 | 597 |
} |
593 | 598 |
FeatureProvider feature = this.createFeatureProvider(ftype); |
594 | 599 |
this.rowToFeatureTranslator.translate(reader.getLine(), row, feature); |
600 |
|
|
601 |
if (feature != null) { |
|
602 |
for (FeatureAttributeDescriptor geomdesc : this.featureType) { |
|
603 |
if (geomdesc.getType() != DataTypes.GEOMETRY) { |
|
604 |
continue; |
|
605 |
} |
|
606 |
String geomName = geomdesc.getName(); |
|
607 |
Envelope theEnvelope = this.envelopes.get(geomName); |
|
608 |
if (theEnvelope == null) { |
|
609 |
theEnvelope = geomManager.createEnvelope(geomdesc.getGeomType().getSubType()); |
|
610 |
this.envelopes.put(geomName, theEnvelope); |
|
611 |
} |
|
612 |
SpatialIndex theSpatialIndex = this.spatialIndexes.get(geomName); |
|
613 |
if (theSpatialIndex == null) { |
|
614 |
String indexTypeName = GeometryManager.SPATIALINDEX_DEFAULT_QUADTREE; |
|
615 |
String extname = "qtree"; |
|
616 |
File indexfile = this.getAuxFile("_"+geomName, extname); |
|
595 | 617 |
|
618 |
SpatialIndexFactory indexfactory = geomManager.getSpatialIndexFactory(indexTypeName); |
|
619 |
DynObject params = indexfactory.createParameters(); |
|
620 |
params.setDynValue("file", indexfile); |
|
621 |
theSpatialIndex = geomManager.createSpatialIndex(indexTypeName, params); |
|
622 |
this.spatialIndexes.put(geomName, theSpatialIndex); |
|
623 |
} |
|
624 |
Object oid = null; |
|
625 |
try { |
|
626 |
oid = feature.getOID(); |
|
627 |
Geometry geom = (Geometry) feature.get(geomdesc.getName()); |
|
628 |
if (geom != null) { |
|
629 |
theEnvelope.add(geom); |
|
630 |
theSpatialIndex.insert(geom, oid); |
|
631 |
} |
|
632 |
} catch (Throwable ex) { |
|
633 |
LOGGER.debug("Can't insert feature '" + Objects.toString(oid) + "' in spatial index.", ex); |
|
634 |
} |
|
635 |
} |
|
636 |
} |
|
637 |
|
|
596 | 638 |
this.addFeatureProvider(feature); |
597 | 639 |
if (limit > 0) { |
598 | 640 |
if (limit < this.data.size()) { |
... | ... | |
601 | 643 |
} |
602 | 644 |
row = reader.read(); |
603 | 645 |
} |
646 |
for (SpatialIndex index : this.spatialIndexes.values()) { |
|
647 |
index.flush(); |
|
648 |
} |
|
649 |
bboxFileSave(envelopes); |
|
604 | 650 |
for (int i = 0; i < ftype.size(); i++) { |
605 | 651 |
if (this.rowToFeatureTranslator.getColumnSize(i) > 0) { |
606 | 652 |
EditableFeatureAttributeDescriptor efad = ((EditableFeatureAttributeDescriptor) edftype.getAttributeDescriptor(i)); |
... | ... | |
827 | 873 |
if (createIndex) { |
828 | 874 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
829 | 875 |
this.taskStatus.add(); |
830 |
taskStatus.message(i18n.getTranslation("_Creating_spatial_index")); |
|
876 |
taskStatus.message(i18n.getTranslation("_Creating_spatial_index")+" ("+geomName+")");
|
|
831 | 877 |
taskStatus.setRangeOfValues(0, this.virtualrows.size64()); |
832 | 878 |
taskStatus.setCurValue(0); |
833 | 879 |
Envelope theEnvelope = geomManager.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
... | ... | |
933 | 979 |
} |
934 | 980 |
|
935 | 981 |
protected void bboxFileSave(File bboxfile, Envelope envelope) { |
936 |
if( envelope == null ) { |
|
982 |
if( envelope == null || envelope.isEmpty() ) {
|
|
937 | 983 |
bboxfile.delete(); |
938 | 984 |
return; |
939 | 985 |
} |
... | ... | |
970 | 1016 |
} |
971 | 1017 |
|
972 | 1018 |
protected abstract SimpleReader getSimpleReader(SimpleReaderStoreParameters parameters, Reader in) throws IOException ; |
1019 |
|
|
1020 |
public FilteredLogger getTimedLogger() { |
|
1021 |
if(timedLogger == null){ |
|
1022 |
timedLogger = new FilteredLogger(LOGGER, "AbstractFeatureProviderLoadedOnDemand", 5000L); |
|
1023 |
} |
|
1024 |
return timedLogger; |
|
1025 |
} |
|
973 | 1026 |
|
974 | 1027 |
} |
Also available in: Unified diff