112 |
112 |
import org.gvsig.tools.persistence.exception.PersistenceException;
|
113 |
113 |
import org.gvsig.tools.task.Cancellable;
|
114 |
114 |
|
115 |
|
|
116 |
115 |
/**
|
117 |
116 |
* Capa b?sica Vectorial.
|
118 |
|
*
|
|
117 |
*
|
119 |
118 |
* @author Fernando Gonz?lez Cort?s
|
120 |
119 |
*/
|
121 |
120 |
|
122 |
|
public class FLyrVect extends FLyrDefault implements VectorLayer, LegendContentsChangedListener,
|
123 |
|
Observer {
|
124 |
|
final static private org.slf4j.Logger logger = LoggerFactory.getLogger(FLyrVect.class);
|
125 |
|
private final GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
|
121 |
public class FLyrVect extends FLyrDefault implements VectorLayer,
|
|
122 |
LegendContentsChangedListener, Observer {
|
126 |
123 |
|
127 |
|
/** Leyenda de la capa vectorial */
|
128 |
|
private IVectorLegend legend;
|
129 |
|
private int typeShape = -1;
|
130 |
|
private FeatureStore featureStore=null;
|
131 |
|
private SpatialCache spatialCache = new SpatialCache();
|
|
124 |
final static private org.slf4j.Logger logger =
|
|
125 |
LoggerFactory.getLogger(FLyrVect.class);
|
|
126 |
private final GeometryManager geomManager =
|
|
127 |
GeometryLocator.getGeometryManager();
|
132 |
128 |
|
133 |
|
/**
|
134 |
|
* An implementation of gvSIG spatial index
|
135 |
|
*/
|
136 |
|
// protected ISpatialIndex spatialIndex = null;
|
137 |
|
private IVectorLegend loadLegend = null;
|
|
129 |
/** Leyenda de la capa vectorial */
|
|
130 |
private IVectorLegend legend;
|
|
131 |
private int typeShape = -1;
|
|
132 |
private FeatureStore featureStore = null;
|
|
133 |
private SpatialCache spatialCache = new SpatialCache();
|
138 |
134 |
|
139 |
|
private boolean isLabeled;
|
140 |
|
protected ILabelingStrategy strategy;
|
141 |
|
|
142 |
|
public FLyrVect() {
|
143 |
|
super();
|
144 |
|
}
|
145 |
|
/**
|
146 |
|
* Devuelve el VectorialAdapater de la capa.
|
147 |
|
*
|
148 |
|
* @return VectorialAdapter.
|
149 |
|
*/
|
150 |
|
public DataStore getDataStore() {
|
151 |
|
if (!this.isAvailable()) {
|
152 |
|
return null;
|
153 |
|
}
|
154 |
|
return featureStore;
|
155 |
|
}
|
|
135 |
/**
|
|
136 |
* An implementation of gvSIG spatial index
|
|
137 |
*/
|
|
138 |
// protected ISpatialIndex spatialIndex = null;
|
|
139 |
private IVectorLegend loadLegend = null;
|
156 |
140 |
|
157 |
|
/**
|
158 |
|
* If we use a persistent spatial index associated with this layer, and the
|
159 |
|
* index is not intrisic to the layer (for example spatial databases) this
|
160 |
|
* method looks for existent spatial index, and loads it.
|
161 |
|
*
|
162 |
|
*/
|
163 |
|
// private void loadSpatialIndex() {
|
164 |
|
// //FIXME: Al abrir el indice en fichero...
|
165 |
|
// //?C?mo lo liberamos? un metodo Layer.shutdown()
|
166 |
|
//
|
167 |
|
//
|
168 |
|
// ReadableVectorial source = getSource();
|
169 |
|
// //REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
|
170 |
|
// //PUES SON VECTORIALFILEADAPTER
|
171 |
|
// if (!(source instanceof VectorialFileAdapter)) {
|
172 |
|
// // we are not interested in db adapters
|
173 |
|
// return;
|
174 |
|
// }
|
175 |
|
// VectorialDriver driver = source.getDriver();
|
176 |
|
// if (!(driver instanceof BoundedShapes)) {
|
177 |
|
// // we dont spatially index layers that are not bounded
|
178 |
|
// return;
|
179 |
|
// }
|
180 |
|
// File file = ((VectorialFileAdapter) source).getFile();
|
181 |
|
// String fileName = file.getAbsolutePath();
|
182 |
|
// File sptFile = new File(fileName + ".qix");
|
183 |
|
// if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
184 |
|
// // before to exit, look for it in temp path
|
185 |
|
// String tempPath = System.getProperty("java.io.tmpdir");
|
186 |
|
// fileName = tempPath + File.separator + sptFile.getName();
|
187 |
|
// sptFile = new File(fileName);
|
188 |
|
// // it doesnt exists, must to create
|
189 |
|
// if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
190 |
|
// return;
|
191 |
|
// }// if
|
192 |
|
// }// if
|
193 |
|
//
|
194 |
|
// try {
|
195 |
|
// source.start();
|
196 |
|
// spatialIndex = new QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
|
197 |
|
// "NM", source.getFullExtent(), source.getShapeCount(), false);
|
198 |
|
// source.setSpatialIndex(spatialIndex);
|
199 |
|
// } catch (SpatialIndexException e) {
|
200 |
|
// spatialIndex = null;
|
201 |
|
// e.printStackTrace();
|
202 |
|
// return;
|
203 |
|
// } catch (ReadDriverException e) {
|
204 |
|
// spatialIndex = null;
|
205 |
|
// e.printStackTrace();
|
206 |
|
// return;
|
207 |
|
// }
|
208 |
|
//
|
209 |
|
// }
|
|
141 |
private boolean isLabeled;
|
|
142 |
protected ILabelingStrategy strategy;
|
210 |
143 |
|
211 |
|
/**
|
212 |
|
* Checks if it has associated an external spatial index
|
213 |
|
* (an spatial index file).
|
214 |
|
*
|
215 |
|
* It looks for it in main file path, or in temp system path.
|
216 |
|
* If main file is rivers.shp, it looks for a file called
|
217 |
|
* rivers.shp.qix.
|
|
144 |
public FLyrVect() {
|
|
145 |
super();
|
|
146 |
}
|
218 |
147 |
|
219 |
|
* @return
|
220 |
|
*/
|
221 |
|
// public boolean isExternallySpatiallyIndexed() {
|
222 |
|
// /*
|
223 |
|
// * FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
|
224 |
|
// * con el que se trabaje (ahora mismo considera la extension .qix,
|
225 |
|
// * pero esto depender? del tipo de ?ndice)
|
226 |
|
// * */
|
227 |
|
// ReadableVectorial source = getSource();
|
228 |
|
// if (!(source instanceof VectorialFileAdapter)) {
|
229 |
|
// // we are not interested in db adapters.
|
230 |
|
// // think in non spatial dbs, like HSQLDB
|
231 |
|
// return false;
|
232 |
|
// }
|
233 |
|
// File file = ((VectorialFileAdapter) source).getFile();
|
234 |
|
// String fileName = file.getAbsolutePath();
|
235 |
|
// File sptFile = new File(fileName + ".qix");
|
236 |
|
// if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
237 |
|
// // before to exit, look for it in temp path
|
238 |
|
// // it doesnt exists, must to create
|
239 |
|
// String tempPath = System.getProperty("java.io.tmpdir");
|
240 |
|
// fileName = tempPath + File.separator + sptFile.getName();
|
241 |
|
// sptFile = new File(fileName);
|
242 |
|
// if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
243 |
|
// return false;
|
244 |
|
// }// if
|
245 |
|
// }// if
|
246 |
|
// return true;
|
247 |
|
// }
|
248 |
|
/**
|
249 |
|
* Inserta el VectorialAdapter a la capa.
|
250 |
|
*
|
251 |
|
* @param va
|
252 |
|
* VectorialAdapter.
|
253 |
|
*
|
254 |
|
* @deprecated esto deber?a se ser protected
|
255 |
|
*/
|
256 |
|
public void setDataStore(DataStore dataStore) throws LoadLayerException {
|
257 |
|
if (this.featureStore != null && this.featureStore != dataStore){
|
258 |
|
this.featureStore.deleteObserver(this);
|
259 |
|
}
|
|
148 |
/**
|
|
149 |
* Devuelve el VectorialAdapater de la capa.
|
|
150 |
*
|
|
151 |
* @return VectorialAdapter.
|
|
152 |
*/
|
|
153 |
public DataStore getDataStore() {
|
|
154 |
if (!this.isAvailable()) {
|
|
155 |
return null;
|
|
156 |
}
|
|
157 |
return featureStore;
|
|
158 |
}
|
260 |
159 |
|
261 |
|
featureStore = (FeatureStore)dataStore;
|
|
160 |
/**
|
|
161 |
* If we use a persistent spatial index associated with this layer, and the
|
|
162 |
* index is not intrisic to the layer (for example spatial databases) this
|
|
163 |
* method looks for existent spatial index, and loads it.
|
|
164 |
*
|
|
165 |
*/
|
|
166 |
// private void loadSpatialIndex() {
|
|
167 |
// //FIXME: Al abrir el indice en fichero...
|
|
168 |
// //?C?mo lo liberamos? un metodo Layer.shutdown()
|
|
169 |
//
|
|
170 |
//
|
|
171 |
// ReadableVectorial source = getSource();
|
|
172 |
// //REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
|
|
173 |
// //PUES SON VECTORIALFILEADAPTER
|
|
174 |
// if (!(source instanceof VectorialFileAdapter)) {
|
|
175 |
// // we are not interested in db adapters
|
|
176 |
// return;
|
|
177 |
// }
|
|
178 |
// VectorialDriver driver = source.getDriver();
|
|
179 |
// if (!(driver instanceof BoundedShapes)) {
|
|
180 |
// // we dont spatially index layers that are not bounded
|
|
181 |
// return;
|
|
182 |
// }
|
|
183 |
// File file = ((VectorialFileAdapter) source).getFile();
|
|
184 |
// String fileName = file.getAbsolutePath();
|
|
185 |
// File sptFile = new File(fileName + ".qix");
|
|
186 |
// if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
|
187 |
// // before to exit, look for it in temp path
|
|
188 |
// String tempPath = System.getProperty("java.io.tmpdir");
|
|
189 |
// fileName = tempPath + File.separator + sptFile.getName();
|
|
190 |
// sptFile = new File(fileName);
|
|
191 |
// // it doesnt exists, must to create
|
|
192 |
// if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
|
193 |
// return;
|
|
194 |
// }// if
|
|
195 |
// }// if
|
|
196 |
//
|
|
197 |
// try {
|
|
198 |
// source.start();
|
|
199 |
// spatialIndex = new
|
|
200 |
// QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
|
|
201 |
// "NM", source.getFullExtent(), source.getShapeCount(), false);
|
|
202 |
// source.setSpatialIndex(spatialIndex);
|
|
203 |
// } catch (SpatialIndexException e) {
|
|
204 |
// spatialIndex = null;
|
|
205 |
// e.printStackTrace();
|
|
206 |
// return;
|
|
207 |
// } catch (ReadDriverException e) {
|
|
208 |
// spatialIndex = null;
|
|
209 |
// e.printStackTrace();
|
|
210 |
// return;
|
|
211 |
// }
|
|
212 |
//
|
|
213 |
// }
|
262 |
214 |
|
263 |
|
ILegend legend = MapContextLocator.getMapContextManager().getLegend(dataStore);
|
|
215 |
/**
|
|
216 |
* Checks if it has associated an external spatial index
|
|
217 |
* (an spatial index file).
|
|
218 |
*
|
|
219 |
* It looks for it in main file path, or in temp system path.
|
|
220 |
* If main file is rivers.shp, it looks for a file called
|
|
221 |
* rivers.shp.qix.
|
|
222 |
*
|
|
223 |
* @return
|
|
224 |
*/
|
|
225 |
// public boolean isExternallySpatiallyIndexed() {
|
|
226 |
// /*
|
|
227 |
// * FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
|
|
228 |
// * con el que se trabaje (ahora mismo considera la extension .qix,
|
|
229 |
// * pero esto depender? del tipo de ?ndice)
|
|
230 |
// * */
|
|
231 |
// ReadableVectorial source = getSource();
|
|
232 |
// if (!(source instanceof VectorialFileAdapter)) {
|
|
233 |
// // we are not interested in db adapters.
|
|
234 |
// // think in non spatial dbs, like HSQLDB
|
|
235 |
// return false;
|
|
236 |
// }
|
|
237 |
// File file = ((VectorialFileAdapter) source).getFile();
|
|
238 |
// String fileName = file.getAbsolutePath();
|
|
239 |
// File sptFile = new File(fileName + ".qix");
|
|
240 |
// if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
|
241 |
// // before to exit, look for it in temp path
|
|
242 |
// // it doesnt exists, must to create
|
|
243 |
// String tempPath = System.getProperty("java.io.tmpdir");
|
|
244 |
// fileName = tempPath + File.separator + sptFile.getName();
|
|
245 |
// sptFile = new File(fileName);
|
|
246 |
// if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
|
247 |
// return false;
|
|
248 |
// }// if
|
|
249 |
// }// if
|
|
250 |
// return true;
|
|
251 |
// }
|
|
252 |
/**
|
|
253 |
* Inserta el VectorialAdapter a la capa.
|
|
254 |
*
|
|
255 |
* @param va
|
|
256 |
* VectorialAdapter.
|
|
257 |
*
|
|
258 |
* @deprecated esto deber?a se ser protected
|
|
259 |
*/
|
|
260 |
public void setDataStore(DataStore dataStore) throws LoadLayerException {
|
|
261 |
if (this.featureStore != null && this.featureStore != dataStore) {
|
|
262 |
this.featureStore.deleteObserver(this);
|
|
263 |
}
|
264 |
264 |
|
265 |
|
if( legend == null ) {
|
266 |
|
throw new LegendLayerException(this.getName());
|
267 |
|
}
|
268 |
|
|
269 |
|
this.setLegend((IVectorLegend)legend);
|
|
265 |
featureStore = (FeatureStore) dataStore;
|
270 |
266 |
|
|
267 |
ILegend legend =
|
|
268 |
MapContextLocator.getMapContextManager().getLegend(dataStore);
|
271 |
269 |
|
272 |
|
ILabelingStrategy labeler = null;
|
273 |
|
try {
|
274 |
|
labeler = (ILabelingStrategy) dataStore.invokeDynMethod(
|
275 |
|
"getLabeling", null);
|
276 |
|
} catch (DynMethodNotSupportedException e1) {
|
277 |
|
labeler = null;
|
278 |
|
} catch (DynMethodException e1) {
|
279 |
|
logger.error("Can't load the specific lebeling strategy provided for the layer {}.", this.getName(), e1);
|
280 |
|
}
|
|
270 |
if (legend == null) {
|
|
271 |
throw new LegendLayerException(this.getName());
|
|
272 |
}
|
281 |
273 |
|
282 |
|
if (labeler != null) {
|
283 |
|
labeler.setLayer(this);
|
284 |
|
this.setLabelingStrategy(labeler);
|
285 |
|
this.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? etiquetes?????
|
286 |
|
}
|
|
274 |
this.setLegend((IVectorLegend) legend);
|
287 |
275 |
|
288 |
|
this.delegate(dataStore);
|
|
276 |
ILabelingStrategy labeler = null;
|
|
277 |
try {
|
|
278 |
labeler =
|
|
279 |
(ILabelingStrategy) dataStore.invokeDynMethod("getLabeling",
|
|
280 |
null);
|
|
281 |
} catch (DynMethodNotSupportedException e1) {
|
|
282 |
labeler = null;
|
|
283 |
} catch (DynMethodException e1) {
|
|
284 |
logger.error("Can't load the specific lebeling strategy provided for the layer {}.",
|
|
285 |
this.getName(),
|
|
286 |
e1);
|
|
287 |
}
|
289 |
288 |
|
290 |
|
dataStore.addObserver(this);
|
|
289 |
if (labeler != null) {
|
|
290 |
labeler.setLayer(this);
|
|
291 |
this.setLabelingStrategy(labeler);
|
|
292 |
this.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t?
|
|
293 |
// etiquetes?????
|
|
294 |
}
|
291 |
295 |
|
292 |
|
// azabala: we check if this layer could have a file spatial index
|
293 |
|
// and load it if it exists
|
294 |
|
// loadSpatialIndex();
|
295 |
|
}
|
|
296 |
this.delegate(dataStore);
|
296 |
297 |
|
297 |
|
public Envelope getFullEnvelope() throws ReadException {
|
298 |
|
Envelope rAux;
|
299 |
|
try {
|
300 |
|
rAux = getFeatureStore().getEnvelope();
|
301 |
|
} catch (BaseException e) {
|
302 |
|
throw new ReadException(getName(),e);
|
303 |
|
}
|
|
298 |
dataStore.addObserver(this);
|
304 |
299 |
|
305 |
|
//Esto es para cuando se crea una capa nueva con el fullExtent de ancho y alto 0.
|
306 |
|
if (rAux == null || rAux.getMaximum(0)-rAux.getMinimum(0)==0 && rAux.getMaximum(1)-rAux.getMinimum(1)==0) {
|
307 |
|
try {
|
308 |
|
rAux= geomManager.createEnvelope(0,0,100,100, SUBTYPES.GEOM2D);
|
309 |
|
} catch (CreateEnvelopeException e) {
|
310 |
|
logger.error("Error creating the envelope", e);
|
311 |
|
e.printStackTrace();
|
312 |
|
}
|
313 |
|
}
|
314 |
|
// Si existe reproyecci?n, reproyectar el extent
|
315 |
|
ICoordTrans ct = getCoordTrans();
|
316 |
|
try{
|
317 |
|
if (ct != null) {
|
318 |
|
Point2D pt1 = new Point2D.Double(rAux.getMinimum(0), rAux.getMinimum(1));
|
319 |
|
Point2D pt2 = new Point2D.Double(rAux.getMaximum(0), rAux.getMaximum(1));
|
320 |
|
pt1 = ct.convert(pt1, null);
|
321 |
|
pt2 = ct.convert(pt2, null);
|
322 |
|
try {
|
323 |
|
rAux = geomManager.createEnvelope(pt1.getX(),pt1.getY(),pt2.getX(),pt2.getY(), SUBTYPES.GEOM2D);
|
324 |
|
} catch (CreateEnvelopeException e) {
|
325 |
|
logger.error("Error creating the envelope", e);
|
326 |
|
e.printStackTrace();
|
327 |
|
}//new Rectangle2D.Double();
|
328 |
|
}
|
329 |
|
}catch (IllegalStateException e) {
|
330 |
|
this.setAvailable(false);
|
331 |
|
this.addError(new ReprojectLayerException(getName(), e));
|
332 |
|
}
|
333 |
|
return rAux;
|
|
300 |
// azabala: we check if this layer could have a file spatial index
|
|
301 |
// and load it if it exists
|
|
302 |
// loadSpatialIndex();
|
|
303 |
}
|
334 |
304 |
|
335 |
|
}
|
|
305 |
public Envelope getFullEnvelope() throws ReadException {
|
|
306 |
Envelope rAux;
|
|
307 |
try {
|
|
308 |
rAux = getFeatureStore().getEnvelope();
|
|
309 |
} catch (BaseException e) {
|
|
310 |
throw new ReadException(getName(), e);
|
|
311 |
}
|
336 |
312 |
|
337 |
|
/**
|
338 |
|
* Draws using IFeatureIterator. This method will replace the old draw(...) one.
|
339 |
|
* @autor jaume dominguez faus - jaume.dominguez@iver.es
|
340 |
|
* @param image
|
341 |
|
* @param g
|
342 |
|
* @param viewPort
|
343 |
|
* @param cancel
|
344 |
|
* @param scale
|
345 |
|
* @throws ReadDriverException
|
346 |
|
*/
|
347 |
|
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
|
348 |
|
Cancellable cancel, double scale) throws ReadException {
|
349 |
|
|
350 |
|
if (legend == null) {
|
351 |
|
return;
|
352 |
|
}
|
353 |
|
|
354 |
|
if (!this.isWithinScale(scale)) {
|
355 |
|
return;
|
356 |
|
}
|
357 |
|
if (cancel.isCanceled()) {
|
358 |
|
return;
|
359 |
|
}
|
|
313 |
// Esto es para cuando se crea una capa nueva con el fullExtent de ancho
|
|
314 |
// y alto 0.
|
|
315 |
if (rAux == null || rAux.getMaximum(0) - rAux.getMinimum(0) == 0
|
|
316 |
&& rAux.getMaximum(1) - rAux.getMinimum(1) == 0) {
|
|
317 |
try {
|
|
318 |
rAux =
|
|
319 |
geomManager.createEnvelope(0, 0, 100, 100, SUBTYPES.GEOM2D);
|
|
320 |
} catch (CreateEnvelopeException e) {
|
|
321 |
logger.error("Error creating the envelope", e);
|
|
322 |
e.printStackTrace();
|
|
323 |
}
|
|
324 |
}
|
|
325 |
// Si existe reproyecci?n, reproyectar el extent
|
|
326 |
ICoordTrans ct = getCoordTrans();
|
|
327 |
try {
|
|
328 |
if (ct != null) {
|
|
329 |
Point2D pt1 =
|
|
330 |
new Point2D.Double(rAux.getMinimum(0), rAux.getMinimum(1));
|
|
331 |
Point2D pt2 =
|
|
332 |
new Point2D.Double(rAux.getMaximum(0), rAux.getMaximum(1));
|
|
333 |
pt1 = ct.convert(pt1, null);
|
|
334 |
pt2 = ct.convert(pt2, null);
|
|
335 |
try {
|
|
336 |
rAux =
|
|
337 |
geomManager.createEnvelope(pt1.getX(),
|
|
338 |
pt1.getY(),
|
|
339 |
pt2.getX(),
|
|
340 |
pt2.getY(),
|
|
341 |
SUBTYPES.GEOM2D);
|
|
342 |
} catch (CreateEnvelopeException e) {
|
|
343 |
logger.error("Error creating the envelope", e);
|
|
344 |
e.printStackTrace();
|
|
345 |
}// new Rectangle2D.Double();
|
|
346 |
}
|
|
347 |
} catch (IllegalStateException e) {
|
|
348 |
this.setAvailable(false);
|
|
349 |
this.addError(new ReprojectLayerException(getName(), e));
|
|
350 |
}
|
|
351 |
return rAux;
|
360 |
352 |
|
361 |
|
if (spatialCache.isEnabled()) {
|
362 |
|
spatialCache.clearAll();
|
363 |
|
legend.addDrawingObserver(this);
|
364 |
|
}
|
|
353 |
}
|
365 |
354 |
|
366 |
|
try {
|
367 |
|
legend.draw(image, g, viewPort, cancel, scale, null,
|
368 |
|
getCoordTrans(), getFeatureStore());
|
|
355 |
/**
|
|
356 |
* Draws using IFeatureIterator. This method will replace the old draw(...)
|
|
357 |
* one.
|
|
358 |
*
|
|
359 |
* @autor jaume dominguez faus - jaume.dominguez@iver.es
|
|
360 |
* @param image
|
|
361 |
* @param g
|
|
362 |
* @param viewPort
|
|
363 |
* @param cancel
|
|
364 |
* @param scale
|
|
365 |
* @throws ReadDriverException
|
|
366 |
*/
|
|
367 |
public void draw(BufferedImage image,
|
|
368 |
Graphics2D g,
|
|
369 |
ViewPort viewPort,
|
|
370 |
Cancellable cancel,
|
|
371 |
double scale) throws ReadException {
|
369 |
372 |
|
370 |
|
} catch (LegendException e) {
|
371 |
|
this.setVisible(false);
|
372 |
|
this.setActive(false);
|
373 |
|
throw new ReadException(getName(), e);
|
374 |
|
} finally {
|
375 |
|
if (spatialCache.isEnabled()) {
|
376 |
|
legend.deleteDrawingObserver(this);
|
377 |
|
}
|
378 |
|
}
|
379 |
|
}
|
380 |
|
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
|
381 |
|
double scale, PrintAttributes properties) throws ReadException {
|
382 |
|
if (!this.isWithinScale(scale)) {
|
383 |
|
return;
|
384 |
|
}
|
385 |
|
if (cancel.isCanceled()) {
|
386 |
|
return;
|
387 |
|
}
|
|
373 |
if (legend == null) {
|
|
374 |
return;
|
|
375 |
}
|
388 |
376 |
|
389 |
|
try {
|
390 |
|
legend.print( g, viewPort, cancel, scale, null,
|
391 |
|
getCoordTrans(), getFeatureStore(), properties);
|
|
377 |
if (!this.isWithinScale(scale)) {
|
|
378 |
return;
|
|
379 |
}
|
|
380 |
if (cancel.isCanceled()) {
|
|
381 |
return;
|
|
382 |
}
|
392 |
383 |
|
393 |
|
} catch (LegendException e) {
|
394 |
|
this.setVisible(false);
|
395 |
|
this.setActive(false);
|
396 |
|
throw new ReadException(getName(), e);
|
397 |
|
}
|
398 |
|
}
|
|
384 |
if (spatialCache.isEnabled()) {
|
|
385 |
spatialCache.clearAll();
|
|
386 |
legend.addDrawingObserver(this);
|
|
387 |
}
|
399 |
388 |
|
400 |
|
/**
|
401 |
|
* <p>
|
402 |
|
* Creates an spatial index associated to this layer.
|
403 |
|
* The spatial index will used
|
404 |
|
* the native projection of the layer, so if the layer is reprojected, it will
|
405 |
|
* be ignored.
|
406 |
|
* </p>
|
407 |
|
* @param cancelMonitor instance of CancellableMonitorable that allows
|
408 |
|
* to monitor progress of spatial index creation, and cancel the process
|
409 |
|
*/
|
410 |
|
// public void createSpatialIndex(CancellableMonitorable cancelMonitor){
|
411 |
|
// // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
412 |
|
// // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
413 |
|
// // para que acepten recorrer sin geometria, solo con rectangulos.
|
414 |
|
//
|
415 |
|
// //If this vectorial layer is based in a spatial database, the spatial
|
416 |
|
// //index is already implicit. We only will index file drivers
|
417 |
|
// ReadableVectorial va = getSource();
|
418 |
|
// //We must think in non spatial databases, like HSQLDB
|
419 |
|
// if(!(va instanceof VectorialFileAdapter)){
|
420 |
|
// return;
|
421 |
|
// }
|
422 |
|
// if (!(va.getDriver() instanceof BoundedShapes)) {
|
423 |
|
// return;
|
424 |
|
// }
|
425 |
|
// File file = ((VectorialFileAdapter) va).getFile();
|
426 |
|
// String fileName = file.getAbsolutePath();
|
427 |
|
// ISpatialIndex localCopy = null;
|
428 |
|
// try {
|
429 |
|
// va.start();
|
430 |
|
// localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(),
|
431 |
|
// va.getShapeCount(), true);
|
432 |
|
//
|
433 |
|
// } catch (SpatialIndexException e1) {
|
434 |
|
// // Probably we dont have writing permissions
|
435 |
|
// String directoryName = System.getProperty("java.io.tmpdir");
|
436 |
|
// File newFile = new File(directoryName +
|
437 |
|
// File.separator +
|
438 |
|
// file.getName());
|
439 |
|
// String newFileName = newFile.getName();
|
440 |
|
// try {
|
441 |
|
// localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(),
|
442 |
|
// va.getShapeCount(), true);
|
443 |
|
// } catch (SpatialIndexException e) {
|
444 |
|
// // if we cant build a file based spatial index, we'll build
|
445 |
|
// // a pure memory spatial index
|
446 |
|
// localCopy = new QuadtreeJts();
|
447 |
|
// } catch (ReadException e) {
|
448 |
|
// localCopy = new QuadtreeJts();
|
449 |
|
// }
|
450 |
|
//
|
451 |
|
// } catch(Exception e){
|
452 |
|
// e.printStackTrace();
|
453 |
|
// }//try
|
454 |
|
// BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
|
455 |
|
// try {
|
456 |
|
// for (int i=0; i < va.getShapeCount(); i++)
|
457 |
|
// {
|
458 |
|
// if(cancelMonitor != null){
|
459 |
|
// if(cancelMonitor.isCanceled())
|
460 |
|
// return;
|
461 |
|
// cancelMonitor.reportStep();
|
462 |
|
// }
|
463 |
|
// Rectangle2D r = shapeBounds.getShapeBounds(i);
|
464 |
|
// if(r != null)
|
465 |
|
// localCopy.insert(r, i);
|
466 |
|
// } // for
|
467 |
|
// va.stop();
|
468 |
|
// if(localCopy instanceof IPersistentSpatialIndex)
|
469 |
|
// ((IPersistentSpatialIndex) localCopy).flush();
|
470 |
|
// spatialIndex = localCopy;
|
471 |
|
// //vectorial adapter needs a reference to the spatial index, to solve
|
472 |
|
// //request for feature iteration based in spatial queries
|
473 |
|
// source.setSpatialIndex(spatialIndex);
|
474 |
|
// } catch (ReadException e) {
|
475 |
|
// // TODO Auto-generated catch block
|
476 |
|
// e.printStackTrace();
|
477 |
|
// }
|
478 |
|
// }
|
|
389 |
try {
|
|
390 |
legend.draw(image,
|
|
391 |
g,
|
|
392 |
viewPort,
|
|
393 |
cancel,
|
|
394 |
scale,
|
|
395 |
null,
|
|
396 |
getCoordTrans(),
|
|
397 |
getFeatureStore());
|
479 |
398 |
|
480 |
|
// public void createSpatialIndex() {
|
481 |
|
// createSpatialIndex(null);
|
482 |
|
// }
|
|
399 |
} catch (LegendException e) {
|
|
400 |
this.setVisible(false);
|
|
401 |
this.setActive(false);
|
|
402 |
throw new ReadException(getName(), e);
|
|
403 |
} finally {
|
|
404 |
if (spatialCache.isEnabled()) {
|
|
405 |
legend.deleteDrawingObserver(this);
|
|
406 |
}
|
|
407 |
}
|
|
408 |
}
|
483 |
409 |
|
|
410 |
public void print(Graphics2D g,
|
|
411 |
ViewPort viewPort,
|
|
412 |
Cancellable cancel,
|
|
413 |
double scale,
|
|
414 |
PrintAttributes properties) throws ReadException {
|
|
415 |
if (!this.isWithinScale(scale)) {
|
|
416 |
return;
|
|
417 |
}
|
|
418 |
if (cancel.isCanceled()) {
|
|
419 |
return;
|
|
420 |
}
|
484 |
421 |
|
485 |
|
public void setLegend(IVectorLegend legend) throws LegendLayerException {
|
486 |
|
if (this.legend == legend){
|
487 |
|
return;
|
488 |
|
}
|
489 |
|
if (this.legend != null && this.legend.equals(legend)){
|
490 |
|
return;
|
491 |
|
}
|
492 |
|
IVectorLegend oldLegend = this.legend;
|
493 |
|
this.legend = legend;
|
494 |
|
if (oldLegend != null) {
|
495 |
|
oldLegend.removeLegendListener(this);
|
496 |
|
oldLegend.deleteDrawingObserver(this);
|
497 |
|
}
|
498 |
|
if (legend != null) {
|
499 |
|
this.legend.addDrawingObserver(this);
|
500 |
|
this.legend.addLegendListener(this);
|
501 |
|
}
|
502 |
|
LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(
|
503 |
|
oldLegend, this.legend);
|
504 |
|
e.setLayer(this);
|
505 |
|
callLegendChanged(e);
|
506 |
|
}
|
|
422 |
try {
|
|
423 |
legend.print(g,
|
|
424 |
viewPort,
|
|
425 |
cancel,
|
|
426 |
scale,
|
|
427 |
null,
|
|
428 |
getCoordTrans(),
|
|
429 |
getFeatureStore(),
|
|
430 |
properties);
|
507 |
431 |
|
508 |
|
/**
|
509 |
|
* Devuelve la Leyenda de la capa.
|
510 |
|
*
|
511 |
|
* @return Leyenda.
|
512 |
|
*/
|
513 |
|
public ILegend getLegend() {
|
514 |
|
return legend;
|
515 |
|
}
|
|
432 |
} catch (LegendException e) {
|
|
433 |
this.setVisible(false);
|
|
434 |
this.setActive(false);
|
|
435 |
throw new ReadException(getName(), e);
|
|
436 |
}
|
|
437 |
}
|
516 |
438 |
|
517 |
|
/**
|
518 |
|
* Devuelve el tipo de shape que contiene la capa.
|
519 |
|
*
|
520 |
|
* @return tipo de shape.
|
521 |
|
*
|
522 |
|
* @throws ReadException
|
523 |
|
*/
|
524 |
|
public int getShapeType() throws ReadException {
|
525 |
|
if (typeShape == -1) {
|
526 |
|
FeatureType featureType;
|
527 |
|
try {
|
528 |
|
featureType = (((FeatureStore)getDataStore()).getDefaultFeatureType());
|
529 |
|
} catch (DataException e) {
|
530 |
|
throw new ReadException(getName(),e);
|
531 |
|
}
|
532 |
|
int indexGeom=featureType.getDefaultGeometryAttributeIndex();
|
533 |
|
typeShape=featureType.getAttributeDescriptor(indexGeom).getGeometryType();
|
534 |
|
}
|
535 |
|
return typeShape;
|
536 |
|
}
|
537 |
|
|
538 |
|
public void saveToState(PersistentState state) throws PersistenceException {
|
|
439 |
/**
|
|
440 |
* <p>
|
|
441 |
* Creates an spatial index associated to this layer. The spatial index will
|
|
442 |
* used the native projection of the layer, so if the layer is reprojected,
|
|
443 |
* it will be ignored.
|
|
444 |
* </p>
|
|
445 |
*
|
|
446 |
* @param cancelMonitor
|
|
447 |
* instance of CancellableMonitorable that allows
|
|
448 |
* to monitor progress of spatial index creation, and cancel the
|
|
449 |
* process
|
|
450 |
*/
|
|
451 |
// public void createSpatialIndex(CancellableMonitorable cancelMonitor){
|
|
452 |
// // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
|
453 |
// // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
|
454 |
// // para que acepten recorrer sin geometria, solo con rectangulos.
|
|
455 |
//
|
|
456 |
// //If this vectorial layer is based in a spatial database, the spatial
|
|
457 |
// //index is already implicit. We only will index file drivers
|
|
458 |
// ReadableVectorial va = getSource();
|
|
459 |
// //We must think in non spatial databases, like HSQLDB
|
|
460 |
// if(!(va instanceof VectorialFileAdapter)){
|
|
461 |
// return;
|
|
462 |
// }
|
|
463 |
// if (!(va.getDriver() instanceof BoundedShapes)) {
|
|
464 |
// return;
|
|
465 |
// }
|
|
466 |
// File file = ((VectorialFileAdapter) va).getFile();
|
|
467 |
// String fileName = file.getAbsolutePath();
|
|
468 |
// ISpatialIndex localCopy = null;
|
|
469 |
// try {
|
|
470 |
// va.start();
|
|
471 |
// localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(),
|
|
472 |
// va.getShapeCount(), true);
|
|
473 |
//
|
|
474 |
// } catch (SpatialIndexException e1) {
|
|
475 |
// // Probably we dont have writing permissions
|
|
476 |
// String directoryName = System.getProperty("java.io.tmpdir");
|
|
477 |
// File newFile = new File(directoryName +
|
|
478 |
// File.separator +
|
|
479 |
// file.getName());
|
|
480 |
// String newFileName = newFile.getName();
|
|
481 |
// try {
|
|
482 |
// localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(),
|
|
483 |
// va.getShapeCount(), true);
|
|
484 |
// } catch (SpatialIndexException e) {
|
|
485 |
// // if we cant build a file based spatial index, we'll build
|
|
486 |
// // a pure memory spatial index
|
|
487 |
// localCopy = new QuadtreeJts();
|
|
488 |
// } catch (ReadException e) {
|
|
489 |
// localCopy = new QuadtreeJts();
|
|
490 |
// }
|
|
491 |
//
|
|
492 |
// } catch(Exception e){
|
|
493 |
// e.printStackTrace();
|
|
494 |
// }//try
|
|
495 |
// BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
|
|
496 |
// try {
|
|
497 |
// for (int i=0; i < va.getShapeCount(); i++)
|
|
498 |
// {
|
|
499 |
// if(cancelMonitor != null){
|
|
500 |
// if(cancelMonitor.isCanceled())
|
|
501 |
// return;
|
|
502 |
// cancelMonitor.reportStep();
|
|
503 |
// }
|
|
504 |
// Rectangle2D r = shapeBounds.getShapeBounds(i);
|
|
505 |
// if(r != null)
|
|
506 |
// localCopy.insert(r, i);
|
|
507 |
// } // for
|
|
508 |
// va.stop();
|
|
509 |
// if(localCopy instanceof IPersistentSpatialIndex)
|
|
510 |
// ((IPersistentSpatialIndex) localCopy).flush();
|
|
511 |
// spatialIndex = localCopy;
|
|
512 |
// //vectorial adapter needs a reference to the spatial index, to solve
|
|
513 |
// //request for feature iteration based in spatial queries
|
|
514 |
// source.setSpatialIndex(spatialIndex);
|
|
515 |
// } catch (ReadException e) {
|
|
516 |
// // TODO Auto-generated catch block
|
|
517 |
// e.printStackTrace();
|
|
518 |
// }
|
|
519 |
// }
|
539 |
520 |
|
540 |
|
if (!this.isAvailable()) {
|
541 |
|
return;
|
542 |
|
}
|
543 |
|
|
544 |
|
super.saveToState(state);
|
|
521 |
// public void createSpatialIndex() {
|
|
522 |
// createSpatialIndex(null);
|
|
523 |
// }
|
545 |
524 |
|
546 |
|
if (getLegend()!=null) {
|
547 |
|
state.set("legend", getLegend());
|
548 |
|
}
|
549 |
|
|
550 |
|
FeatureStore fst = null;
|
551 |
|
fst = getFeatureStore();
|
|
525 |
public void setLegend(IVectorLegend legend) throws LegendLayerException {
|
|
526 |
if (this.legend == legend) {
|
|
527 |
return;
|
|
528 |
}
|
|
529 |
if (this.legend != null && this.legend.equals(legend)) {
|
|
530 |
return;
|
|
531 |
}
|
|
532 |
IVectorLegend oldLegend = this.legend;
|
|
533 |
this.legend = legend;
|
|
534 |
if (oldLegend != null) {
|
|
535 |
oldLegend.removeLegendListener(this);
|
|
536 |
oldLegend.deleteDrawingObserver(this);
|
|
537 |
}
|
|
538 |
if (legend != null) {
|
|
539 |
this.legend.addDrawingObserver(this);
|
|
540 |
this.legend.addLegendListener(this);
|
|
541 |
}
|
|
542 |
LegendChangedEvent e =
|
|
543 |
LegendChangedEvent.createLegendChangedEvent(oldLegend, this.legend);
|
|
544 |
e.setLayer(this);
|
|
545 |
callLegendChanged(e);
|
|
546 |
}
|
552 |
547 |
|
553 |
|
if (fst != null) {
|
554 |
|
state.set("featureStore", fst);
|
555 |
|
}
|
556 |
|
|
557 |
|
state.set("isLabeled", isLabeled);
|
558 |
|
|
559 |
|
if (strategy != null) {
|
560 |
|
state.set("labelingStrategy", strategy);
|
561 |
|
}
|
562 |
|
|
563 |
|
if (getLinkProperties() != null) {
|
564 |
|
state.set("linkProperties", getLinkProperties());
|
565 |
|
}
|
566 |
|
|
567 |
|
// state.set("bHasJoin", bHasJoin);
|
568 |
|
state.set("typeShape", typeShape);
|
569 |
|
}
|
|
548 |
/**
|
|
549 |
* Devuelve la Leyenda de la capa.
|
|
550 |
*
|
|
551 |
* @return Leyenda.
|
|
552 |
*/
|
|
553 |
public ILegend getLegend() {
|
|
554 |
return legend;
|
|
555 |
}
|
570 |
556 |
|
571 |
|
// public XMLEntity getXMLEntity() throws XMLException {
|
572 |
|
//
|
573 |
|
// if (!this.isAvailable() && this.orgXMLEntity != null) {
|
574 |
|
// return this.orgXMLEntity;
|
575 |
|
// }
|
576 |
|
// XMLEntity xml = super.getXMLEntity();
|
577 |
|
// if (getLegend()!=null){
|
578 |
|
// XMLEntity xmlLegend=getLegend().getXMLEntity();
|
579 |
|
// xmlLegend.putProperty("tagName","legend");
|
580 |
|
// xml.addChild(xmlLegend);
|
581 |
|
// }
|
582 |
|
// try {
|
583 |
|
// PersistenceManager manager = ToolsLocator.getPersistenceManager();
|
584 |
|
// PersistentState stateFeatureStore=manager.getState(getFeatureStore());
|
585 |
|
// stateFeatureStore.set("tagName","featureStore");
|
586 |
|
// xml.addChild(((XMLEntityState)stateFeatureStore).getXMLEntity());
|
587 |
|
// } catch (ReadException e) {
|
588 |
|
// throw new XMLLayerException(getName(),e);
|
589 |
|
// } catch (PersistenceException e) {
|
590 |
|
// throw new XMLLayerException(getName(),e);
|
591 |
|
// }
|
592 |
|
// // properties from ILabelable
|
593 |
|
// xml.putProperty("isLabeled", isLabeled);
|
594 |
|
// if (strategy != null) {
|
595 |
|
// XMLEntity strategyXML = strategy.getXMLEntity();
|
596 |
|
// strategyXML.putProperty("tagName", "labelingStrategy");
|
597 |
|
// xml.addChild(strategy.getXMLEntity());
|
598 |
|
// }
|
599 |
|
// xml.addChild(getLinkProperties().getXMLEntity());
|
600 |
|
// return xml;
|
601 |
|
// }
|
602 |
|
|
603 |
|
|
604 |
|
|
|
557 |
/**
|
|
558 |
* Devuelve el tipo de shape que contiene la capa.
|
|
559 |
*
|
|
560 |
* @return tipo de shape.
|
|
561 |
*
|
|
562 |
* @throws ReadException
|
|
563 |
*/
|
|
564 |
public int getShapeType() throws ReadException {
|
|
565 |
if (typeShape == -1) {
|
|
566 |
FeatureType featureType;
|
|
567 |
try {
|
|
568 |
featureType =
|
|
569 |
(((FeatureStore) getDataStore()).getDefaultFeatureType());
|
|
570 |
} catch (DataException e) {
|
|
571 |
throw new ReadException(getName(), e);
|
|
572 |
}
|
|
573 |
int indexGeom = featureType.getDefaultGeometryAttributeIndex();
|
|
574 |
typeShape =
|
|
575 |
featureType.getAttributeDescriptor(indexGeom).getGeometryType();
|
|
576 |
}
|
|
577 |
return typeShape;
|
|
578 |
}
|
605 |
579 |
|
606 |
|
public void loadFromState(PersistentState state) throws PersistenceException {
|
607 |
|
|
608 |
|
super.loadFromState(state);
|
609 |
|
|
610 |
|
DataStore store = (DataStore) state.get("featureStore");
|
611 |
|
try {
|
612 |
|
this.setDataStore(store);
|
613 |
|
} catch (LoadLayerException e) {
|
614 |
|
throw new PersistenceException("While loading FLyrVect from state.", e);
|
615 |
|
}
|
|
580 |
public void saveToState(PersistentState state) throws PersistenceException {
|
616 |
581 |
|
617 |
|
IVectorLegend lgnd = (IVectorLegend) state.get("legend");
|
618 |
|
try {
|
619 |
|
this.setLegend(lgnd);
|
620 |
|
} catch (LegendLayerException e) {
|
621 |
|
throw new PersistenceException("While loading FLyrVect from state.", e);
|
622 |
|
}
|
|
582 |
if (!this.isAvailable()) {
|
|
583 |
return;
|
|
584 |
}
|
623 |
585 |
|
624 |
|
Boolean isLbl = new Boolean(false);
|
625 |
|
ILabelingStrategy lblst = null;
|
626 |
|
|
627 |
|
try {
|
628 |
|
isLbl = (Boolean) state.get("isLabeled");
|
629 |
|
if (isLbl.booleanValue()) {
|
630 |
|
lblst = (ILabelingStrategy) state.get("labelingStrategy");
|
631 |
|
}
|
632 |
|
} catch (Exception ex) {
|
633 |
|
throw new PersistenceException("While loading FLyrVect from state.", ex);
|
634 |
|
}
|
635 |
|
|
636 |
|
/*
|
637 |
|
String _labelFieldName = null;
|
638 |
|
String _labelfield = null;
|
639 |
|
*/
|
640 |
|
|
641 |
|
if (isLbl.booleanValue()) {
|
642 |
|
this.setIsLabeled(true);
|
643 |
|
this.setLabelingStrategy(lblst);
|
644 |
|
} else {
|
645 |
|
this.setIsLabeled(false);
|
646 |
|
this.setLabelingStrategy(null);
|
647 |
|
}
|
648 |
|
|
649 |
|
// try {
|
650 |
|
// linkProperties = (FLyrVectLinkProperties) state.get("linkProperties");
|
651 |
|
// } catch (PersistenceException pex) {
|
652 |
|
// // not mandatory
|
653 |
|
// linkProperties = null;
|
654 |
|
// }
|
655 |
|
|
656 |
|
|
657 |
|
//bHasJoin = state.getBoolean("bHasJoin");
|
658 |
|
typeShape = state.getInt("typeShape");
|
|
586 |
super.saveToState(state);
|
659 |
587 |
|
660 |
|
// try { _labelFieldName = state.getString("labelFieldName"); } catch (PersistenceException ex) {
|
661 |
|
// _labelFieldName = null;
|
662 |
|
// }
|
663 |
|
// try { _labelfield = state.getString("labelfield"); } catch (PersistenceException ex) {
|
664 |
|
// _labelfield = null;
|
665 |
|
// }
|
666 |
|
|
667 |
|
// ILabelingStrategy not implemented
|
668 |
|
// if (_labelFieldName != null) {
|
669 |
|
//
|
670 |
|
// AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
|
671 |
|
// try {
|
672 |
|
// labeling.setLayer(this);
|
673 |
|
// } catch (ReadException e) {
|
674 |
|
// logger.error("While setting layer to AttrInTableLabelingStrategy: " + e.getMessage());
|
675 |
|
// }
|
676 |
|
// labeling.setUsesFixedSize(true);
|
677 |
|
// labeling.setFixedSize(10);
|
678 |
|
// labeling.setTextField(_labelFieldName);
|
679 |
|
// labeling.setHeightField(state.getString("labelHeightFieldName"));
|
680 |
|
// labeling.setRotationField(state.getString("labelRotationFieldName"));
|
681 |
|
// setLabelingStrategy(labeling);
|
682 |
|
// setIsLabeled(true);
|
683 |
|
//
|
684 |
|
// } else {
|
685 |
|
// if (_labelfield != null) {
|
686 |
|
//
|
687 |
|
// AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
|
688 |
|
// try {
|
689 |
|
// labeling.setLayer(this);
|
690 |
|
// } catch (ReadException e) {
|
691 |
|
// logger.error("While setting layer to AttrInTableLabelingStrategy: " + e.getMessage());
|
692 |
|
// }
|
693 |
|
// labeling.setUsesFixedSize(true);
|
694 |
|
// labeling.setFixedSize(10);
|
695 |
|
// labeling.setTextField(_labelfield);
|
696 |
|
// labeling.setHeightField(state.getString("labelFieldHeight"));
|
697 |
|
// labeling.setRotationField(state.getString("labelFieldRotation"));
|
698 |
|
// setLabelingStrategy(labeling);
|
699 |
|
// setIsLabeled(true);
|
700 |
|
// }
|
701 |
|
// }
|
702 |
|
|
703 |
|
}
|
|
588 |
if (getLegend() != null) {
|
|
589 |
state.set("legend", getLegend());
|
|
590 |
}
|
704 |
591 |
|
705 |
|
// public void setXMLEntity(XMLEntity xml) throws XMLException {
|
706 |
|
// try {
|
707 |
|
// super.setXMLEntity(xml);
|
708 |
|
// XMLEntity legendXML = xml.firstChild("tagName","legend");
|
709 |
|
// IVectorLegend leg = LegendFactory.createFromXML(legendXML);
|
710 |
|
//
|
711 |
|
// // PersistentState persistentState=new XMLEntityState(new XMLEntityManager());
|
712 |
|
// XMLEntity xmlStore=xml.firstChild("tagName","featureStore");
|
713 |
|
// XMLEntityManager xmlManger = new XMLEntityManager();
|
714 |
|
// PersistentState state = xmlManger.createState(xmlStore);
|
715 |
|
// DataStore store = (DataStore) ToolsLocator.getPersistenceManager().create(state);
|
716 |
|
// // persistentState.createState(xmlStore);
|
717 |
|
//
|
718 |
|
// // DataManager dm=DALLocator.getDataManager();
|
719 |
|
//
|
720 |
|
// this.setDataStore(store);
|
721 |
|
// /* end patch */
|
722 |
|
// try {
|
723 |
|
// setLegend(leg);
|
724 |
|
// } catch (LegendLayerException e) {
|
725 |
|
// throw new XMLLegendException(e);
|
726 |
|
// }
|
727 |
|
// // set properties for ILabelable
|
728 |
|
//
|
729 |
|
// if (xml.contains("isLabeled")
|
730 |
|
// && xml.getBooleanProperty(("isLabeled"))) {
|
731 |
|
// XMLEntity labelingXML = xml.firstChild("tagName", "labelingStrategy");
|
732 |
|
// if (labelingXML != null){
|
733 |
|
//
|
734 |
|
// isLabeled = true;
|
735 |
|
// try {
|
736 |
|
// this.strategy = LabelingFactory.createStrategyFromXML(labelingXML, this);
|
737 |
|
// } catch (NotExistInXMLEntity neXMLEX) {
|
738 |
|
// // no strategy was set, just continue;
|
739 |
|
// logger.warn("Reached what should be unreachable code");
|
740 |
|
// }
|
741 |
|
// } else {
|
742 |
|
// isLabeled = false;
|
743 |
|
// }
|
744 |
|
// } else if (legendXML.contains("labelFieldName")|| legendXML.contains("labelfield")) {
|
745 |
|
// /* (jaume) begin patch;
|
746 |
|
// * for backward compatibility purposes. Since gvSIG v1.1 labeling is
|
747 |
|
// * no longer managed by the Legend but by the ILabelingStrategy. The
|
748 |
|
// * following allows restoring older projects' labelings.
|
749 |
|
// */
|
750 |
|
// String labelTextField = null;
|
751 |
|
// if (legendXML.contains("labelFieldName")){
|
752 |
|
// labelTextField = legendXML.getStringProperty("labelFieldName");
|
753 |
|
// if (labelTextField != null) {
|
754 |
|
// AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
|
755 |
|
// labeling.setLayer(this);
|
756 |
|
// labeling.setUsesFixedSize(true);
|
757 |
|
// labeling.setFixedSize(10);
|
758 |
|
// labeling.setTextField(labelTextField);
|
759 |
|
// labeling.setHeightField(legendXML.getStringProperty("labelHeightFieldName"));
|
760 |
|
// labeling.setRotationField(legendXML.getStringProperty("labelRotationFieldName"));
|
761 |
|
// this.setLabelingStrategy(labeling);
|
762 |
|
// this.setIsLabeled(true);
|
763 |
|
// }
|
764 |
|
// }else{
|
765 |
|
// labelTextField = legendXML.getStringProperty("labelfield");
|
766 |
|
// if (labelTextField != null) {
|
767 |
|
// AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
|
768 |
|
// labeling.setLayer(this);
|
769 |
|
// labeling.setUsesFixedSize(true);
|
770 |
|
// labeling.setFixedSize(10);
|
771 |
|
// labeling.setTextField(labelTextField);
|
772 |
|
// labeling.setHeightField(legendXML.getStringProperty("labelFieldHeight"));
|
773 |
|
// labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
|
774 |
|
// this.setLabelingStrategy(labeling);
|
775 |
|
// this.setIsLabeled(true);
|
776 |
|
// }
|
777 |
|
// }
|
778 |
|
// }else{
|
779 |
|
// isLabeled = false;
|
780 |
|
// }
|
781 |
|
// XMLEntity xmlLinkProperties=xml.firstChild("typeChild","linkProperties");
|
782 |
|
// if (xmlLinkProperties != null){
|
783 |
|
// getLinkProperties().setXMLEntity(xmlLinkProperties);
|
784 |
|
// }
|
785 |
|
// } catch (Exception e) {
|
786 |
|
// e.printStackTrace();
|
787 |
|
// this.setAvailable(false);
|
788 |
|
// this.orgXMLEntity = xml;
|
789 |
|
//
|
790 |
|
// }
|
791 |
|
// //
|
792 |
|
//
|
793 |
|
// }
|
|
592 |
FeatureStore fst = null;
|
|
593 |
fst = getFeatureStore();
|
794 |
594 |
|
|
595 |
if (fst != null) {
|
|
596 |
state.set("featureStore", fst);
|
|
597 |
}
|
795 |
598 |
|
|
599 |
state.set("isLabeled", isLabeled);
|
796 |
600 |
|
|
601 |
if (strategy != null) {
|
|
602 |
state.set("labelingStrategy", strategy);
|
|
603 |
}
|
797 |
604 |
|
798 |
|
/**
|
799 |
|
* Sobreimplementaci?n del m?todo toString para que las bases de datos
|
800 |
|
* identifiquen la capa.
|
801 |
|
*
|
802 |
|
* @return DOCUMENT ME!
|
803 |
|
*/
|
804 |
|
public String toString() {
|
805 |
|
/*
|
806 |
|
* Se usa internamente para que la parte de datos identifique de forma
|
807 |
|
* un?voca las tablas
|
808 |
|
*/
|
809 |
|
String ret = super.toString();
|
|
605 |
if (getLinkProperties() != null) {
|
|
606 |
state.set("linkProperties", getLinkProperties());
|
|
607 |
}
|
810 |
608 |
|
811 |
|
return "layer" + ret.substring(ret.indexOf('@') + 1);
|
812 |
|
}
|
|
609 |
// state.set("bHasJoin", bHasJoin);
|
|
610 |
state.set("typeShape", typeShape);
|
|
611 |
}
|
813 |
612 |
|
814 |
|
// public boolean isJoined() {
|
815 |
|
// return bHasJoin;
|
816 |
|
// }
|
|
613 |
// public XMLEntity getXMLEntity() throws XMLException {
|
|
614 |
//
|
|
615 |
// if (!this.isAvailable() && this.orgXMLEntity != null) {
|
|
616 |
// return this.orgXMLEntity;
|
|
617 |
// }
|
|
618 |
// XMLEntity xml = super.getXMLEntity();
|
|
619 |
// if (getLegend()!=null){
|
|
620 |
// XMLEntity xmlLegend=getLegend().getXMLEntity();
|
|
621 |
// xmlLegend.putProperty("tagName","legend");
|
|
622 |
// xml.addChild(xmlLegend);
|
|
623 |
// }
|
|
624 |
// try {
|
|
625 |
// PersistenceManager manager = ToolsLocator.getPersistenceManager();
|
|
626 |
// PersistentState stateFeatureStore=manager.getState(getFeatureStore());
|
|
627 |
// stateFeatureStore.set("tagName","featureStore");
|
|
628 |
// xml.addChild(((XMLEntityState)stateFeatureStore).getXMLEntity());
|
|
629 |
// } catch (ReadException e) {
|
|
630 |
// throw new XMLLayerException(getName(),e);
|
|
631 |
// } catch (PersistenceException e) {
|
|
632 |
// throw new XMLLayerException(getName(),e);
|
|
633 |
// }
|
|
634 |
// // properties from ILabelable
|
|
635 |
// xml.putProperty("isLabeled", isLabeled);
|
|
636 |
// if (strategy != null) {
|
|
637 |
// XMLEntity strategyXML = strategy.getXMLEntity();
|
|
638 |
// strategyXML.putProperty("tagName", "labelingStrategy");
|
|
639 |
// xml.addChild(strategy.getXMLEntity());
|
|
640 |
// }
|
|
641 |
// xml.addChild(getLinkProperties().getXMLEntity());
|
|
642 |
// return xml;
|
|
643 |
// }
|
817 |
644 |
|
818 |
|
/**
|
819 |
|
* Returns if a layer is spatially indexed
|
820 |
|
*
|
821 |
|
* @return if this layer has the ability to proces spatial queries without
|
822 |
|
* secuential scans.
|
823 |
|
*/
|
824 |
|
// public boolean isSpatiallyIndexed() {
|
825 |
|
// ReadableVectorial source = getSource();
|
826 |
|
// if (source instanceof ISpatialDB)
|
827 |
|
// return true;
|
828 |
|
//
|
829 |
|
////FIXME azabala
|
830 |
|
///*
|
831 |
|
// * Esto es muy dudoso, y puede cambiar.
|
832 |
|
// * Estoy diciendo que las que no son fichero o no son
|
833 |
|
// * BoundedShapes estan indexadas. Esto es mentira, pero
|
834 |
|
// * as? quien pregunte no querr? generar el indice.
|
835 |
|
// * Esta por ver si interesa generar el indice para capas
|
836 |
|
// * HSQLDB, WFS, etc.
|
837 |
|
// */
|
838 |
|
// if(!(source instanceof VectorialFileAdapter)){
|
839 |
|
// return true;
|
840 |
|
// }
|
841 |
|
// if (!(source.getDriver() instanceof BoundedShapes)) {
|
842 |
|
// return true;
|
843 |
|
// }
|
844 |
|
//
|
845 |
|
// if (getISpatialIndex() != null)
|
846 |
|
// return true;
|
847 |
|
// return false;
|
848 |
|
// }
|
849 |
|
//
|
850 |
|
// public void setIsJoined(boolean hasJoin) {
|
851 |
|
// bHasJoin = hasJoin;
|
852 |
|
// }
|
|
645 |
public void loadFromState(PersistentState state) throws PersistenceException {
|
853 |
646 |
|
854 |
|
// /**
|
855 |
|
// * @return Returns the spatialIndex.
|
856 |
|
// */
|
857 |
|
// public ISpatialIndex getISpatialIndex() {
|
858 |
|
// return spatialIndex;
|
859 |
|
// }
|
860 |
|
// /**
|
861 |
|
// * Sets the spatial index. This could be useful if, for some
|
862 |
|
// * reasons, you want to work with a distinct spatial index
|
863 |
|
// * (for example, a spatial index which could makes nearest
|
864 |
|
// * neighbour querys)
|
865 |
|
// * @param spatialIndex
|
866 |
|
// */
|
867 |
|
// public void setISpatialIndex(ISpatialIndex spatialIndex){
|
868 |
|
// this.spatialIndex = spatialIndex;
|
869 |
|
// }
|
|
647 |
super.loadFromState(state);
|
870 |
648 |
|
871 |
|
public void setEditing(boolean b) throws StartEditionLayerException {
|
872 |
|
super.setEditing(b);
|
873 |
|
if (b){
|
874 |
|
try {
|
875 |
|
getFeatureStore().edit();
|
876 |
|
} catch (ReadException e) {
|
877 |
|
throw new StartEditionLayerException(getName(),e);
|
878 |
|
} catch (DataException e) {
|
879 |
|
throw new StartEditionLayerException(getName(),e);
|
880 |
|
}
|
881 |
|
}
|
882 |
|
setSpatialCacheEnabled(b);
|
883 |
|
callEditionChanged(LayerEvent
|
884 |
|
.createEditionChangedEvent(this, "edition"));
|
|
649 |
DataStore store = (DataStore) state.get("featureStore");
|
|
650 |
try {
|
|
651 |
this.setDataStore(store);
|
|
652 |
} catch (LoadLayerException e) {
|
|
653 |
throw new PersistenceException("While loading FLyrVect from state.",
|
|
654 |
e);
|
|
655 |
}
|
885 |
656 |
|
886 |
|
}
|
|
657 |
IVectorLegend lgnd = (IVectorLegend) state.get("legend");
|
|
658 |
try {
|
|
659 |
this.setLegend(lgnd);
|
|
660 |
} catch (LegendLayerException e) {
|
|
661 |
throw new PersistenceException("While loading FLyrVect from state.",
|
|
662 |
e);
|
|
663 |
}
|
887 |
664 |
|
888 |
|
|
889 |
|
/**
|
890 |
|
* @deprecated Use {@link #getSpatialCache()}
|
891 |
|
*/
|
892 |
|
public void clearSpatialCache()
|
893 |
|
{
|
894 |
|
spatialCache.clearAll();
|
895 |
|
}
|
|
665 |
Boolean isLbl = new Boolean(false);
|
|
666 |
ILabelingStrategy lblst = null;
|
896 |
667 |
|
897 |
|
/**
|
898 |
|
* @deprecated Use {@link #getSpatialCache()}
|
899 |
|
*/
|
900 |
|
public boolean isSpatialCacheEnabled() {
|
901 |
|
return spatialCache.isEnabled();
|
902 |
|
}
|
|
668 |
try {
|
|
669 |
isLbl = (Boolean) state.get("isLabeled");
|
|
670 |
if (isLbl.booleanValue()) {
|
|
671 |
lblst = (ILabelingStrategy) state.get("labelingStrategy");
|
|
672 |
}
|
|
673 |
} catch (Exception ex) {
|
|
674 |
throw new PersistenceException("While loading FLyrVect from state.",
|
|
675 |
ex);
|
|
676 |
}
|
903 |
677 |
|
904 |
|
/**
|
905 |
|
* @deprecated Use {@link #getSpatialCache()}
|
906 |
|
*/
|
907 |
|
public void setSpatialCacheEnabled(boolean spatialCacheEnabled) {
|
908 |
|
spatialCache.setEnabled(spatialCacheEnabled);
|
909 |
|
}
|
|
678 |
/*
|
|
679 |
* String _labelFieldName = null;
|
|
680 |
* String _labelfield = null;
|
|
681 |
*/
|
910 |
682 |
|
911 |
|
public SpatialCache getSpatialCache() {
|
912 |
|
return spatialCache;
|
913 |
|
}
|
|
683 |
if (isLbl.booleanValue()) {
|
|
684 |
this.setIsLabeled(true);
|
|
685 |
this.setLabelingStrategy(lblst);
|
|
686 |
} else {
|
|
687 |
this.setIsLabeled(false);
|
|
688 |
this.setLabelingStrategy(null);
|
|
689 |
}
|
914 |
690 |
|
915 |
|
/**
|
916 |
|
* Siempre es un numero mayor de 1000
|
917 |
|
* @param maxFeatures
|
918 |
|
*/
|
919 |
|
public void setMaxFeaturesInEditionCache(int maxFeatures) {
|
920 |
|
if (maxFeatures > spatialCache.getMaxFeatures()) {
|
921 |
|
spatialCache.setMaxFeatures(maxFeatures);
|
922 |
|
}
|
|
691 |
// try {
|
|
692 |
// linkProperties = (FLyrVectLinkProperties)
|
|
693 |
// state.get("linkProperties");
|
|
694 |
// } catch (PersistenceException pex) {
|
|
695 |
// // not mandatory
|
|
696 |
// linkProperties = null;
|
|
697 |
// }
|
923 |
698 |
|
924 |
|
}
|
|
699 |
// bHasJoin = state.getBoolean("bHasJoin");
|
|
700 |
typeShape = state.getInt("typeShape");
|
925 |
701 |
|
926 |
|
/**
|
927 |
|
* This method returns a boolean that is used by the FPopMenu
|
928 |
|
* to make visible the properties menu or not. It is visible by
|
929 |
|
* default, and if a later don't have to show this menu only
|
930 |
|
* has to override this method.
|
931 |
|
* @return
|
932 |
|
* If the properties menu is visible (or not)
|
933 |
|
*/
|
934 |
|
public boolean isPropertiesMenuVisible(){
|
935 |
|
return true;
|
936 |
|
}
|
|
702 |
// try { _labelFieldName = state.getString("labelFieldName"); } catch
|
|
703 |
// (PersistenceException ex) {
|
|
704 |
// _labelFieldName = null;
|
|
705 |
// }
|
|
706 |
// try { _labelfield = state.getString("labelfield"); } catch
|
|
707 |
// (PersistenceException ex) {
|
|
708 |
// _labelfield = null;
|
|
709 |
// }
|
937 |
710 |
|
938 |
|
public void reload() throws ReloadLayerException {
|
939 |
|
super.reload();
|
940 |
|
try {
|
941 |
|
DataManager dataManager=DALLocator.getDataManager();
|
942 |
|
DataStoreParameters storeParameters;
|
|
711 |
// ILabelingStrategy not implemented
|
|
712 |
// if (_labelFieldName != null) {
|
|
713 |
//
|
|
714 |
// AttrInTableLabelingStrategy labeling = new
|
|
715 |
// AttrInTableLabelingStrategy();
|
|
716 |
// try {
|
|
717 |
// labeling.setLayer(this);
|
|
718 |
// } catch (ReadException e) {
|
|
719 |
// logger.error("While setting layer to AttrInTableLabelingStrategy: " +
|
|
720 |
// e.getMessage());
|
|
721 |
// }
|
|
722 |
// labeling.setUsesFixedSize(true);
|
|
723 |
// labeling.setFixedSize(10);
|
|
724 |
// labeling.setTextField(_labelFieldName);
|
|
725 |
// labeling.setHeightField(state.getString("labelHeightFieldName"));
|
|
726 |
// labeling.setRotationField(state.getString("labelRotationFieldName"));
|
|
727 |
// setLabelingStrategy(labeling);
|
|
728 |
// setIsLabeled(true);
|
|
729 |
//
|
|
730 |
// } else {
|
|
731 |
// if (_labelfield != null) {
|
|
732 |
//
|
|
733 |
// AttrInTableLabelingStrategy labeling = new
|
|
734 |
// AttrInTableLabelingStrategy();
|
|
735 |
// try {
|
|
736 |
// labeling.setLayer(this);
|
|
737 |
// } catch (ReadException e) {
|
|
738 |
// logger.error("While setting layer to AttrInTableLabelingStrategy: " +
|
|
739 |
// e.getMessage());
|
|
740 |
// }
|
|
741 |
// labeling.setUsesFixedSize(true);
|
|
742 |
// labeling.setFixedSize(10);
|
|
743 |
// labeling.setTextField(_labelfield);
|
|
744 |
// labeling.setHeightField(state.getString("labelFieldHeight"));
|
|
745 |
// labeling.setRotationField(state.getString("labelFieldRotation"));
|
|
746 |
// setLabelingStrategy(labeling);
|
|
747 |
// setIsLabeled(true);
|
|
748 |
// }
|
|
749 |
// }
|
943 |
750 |
|
944 |
|
storeParameters = getFeatureStore().getParameters();
|
|
751 |
}
|
945 |
752 |
|
946 |
|
DataStore dataStore=dataManager.createStore(storeParameters);
|
947 |
|
setDataStore(dataStore);
|