svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.shp / src / main / java / org / gvsig / fmap / dal / store / shp / SHPStoreProvider.java @ 41556
History | View | Annotate | Download (19.3 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.fmap.dal.store.shp; |
26 |
|
27 |
import java.io.File; |
28 |
import java.io.IOException; |
29 |
import java.util.Iterator; |
30 |
|
31 |
import org.apache.commons.io.FileUtils; |
32 |
import org.cresques.cts.IProjection; |
33 |
import org.slf4j.Logger; |
34 |
import org.slf4j.LoggerFactory; |
35 |
|
36 |
import org.gvsig.fmap.dal.DataStore; |
37 |
import org.gvsig.fmap.dal.DataTypes; |
38 |
import org.gvsig.fmap.dal.FileHelper; |
39 |
import org.gvsig.fmap.dal.exception.CloseException; |
40 |
import org.gvsig.fmap.dal.exception.DataException; |
41 |
import org.gvsig.fmap.dal.exception.InitializeException; |
42 |
import org.gvsig.fmap.dal.exception.OpenException; |
43 |
import org.gvsig.fmap.dal.exception.ReadException; |
44 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
45 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
46 |
import org.gvsig.fmap.dal.feature.Feature; |
47 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
48 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
49 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
50 |
import org.gvsig.fmap.dal.feature.FeatureType; |
51 |
import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
52 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
53 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
54 |
import org.gvsig.fmap.dal.resource.exception.ResourceException; |
55 |
import org.gvsig.fmap.dal.resource.exception.ResourceExecuteException; |
56 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyChangesException; |
57 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyCloseException; |
58 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyOpenException; |
59 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
60 |
import org.gvsig.fmap.dal.resource.spi.MultiResource; |
61 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
62 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
63 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters; |
64 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider; |
65 |
import org.gvsig.fmap.dal.store.shp.utils.ISHPFile; |
66 |
import org.gvsig.fmap.dal.store.shp.utils.SHPFile2; |
67 |
import org.gvsig.fmap.geom.Geometry; |
68 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
69 |
import org.gvsig.fmap.geom.GeometryLocator; |
70 |
import org.gvsig.fmap.geom.GeometryManager; |
71 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
72 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
73 |
import org.gvsig.fmap.geom.primitive.Envelope; |
74 |
import org.gvsig.tools.dispose.DisposableIterator; |
75 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
76 |
import org.gvsig.tools.exception.BaseException; |
77 |
|
78 |
public class SHPStoreProvider extends DBFStoreProvider { |
79 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
80 |
private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class); |
81 |
public static String NAME = "Shape"; |
82 |
public static String DESCRIPTION = "Shape file"; |
83 |
private ISHPFile shpFile;
|
84 |
|
85 |
private MultiResource resource;
|
86 |
|
87 |
protected static final String GEOMETRY_ATTIBUTE_NAME = "GEOMETRY"; |
88 |
|
89 |
public static final String METADATA_DEFINITION_NAME = NAME; |
90 |
|
91 |
private SHPFeatureWriter writer = null; |
92 |
|
93 |
public SHPStoreProvider(SHPStoreParameters params,
|
94 |
DataStoreProviderServices storeServices) |
95 |
throws InitializeException {
|
96 |
super(
|
97 |
params, |
98 |
storeServices, |
99 |
FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME) |
100 |
); |
101 |
} |
102 |
|
103 |
protected void init(DBFStoreParameters params, |
104 |
DataStoreProviderServices storeServices) throws InitializeException {
|
105 |
|
106 |
this.shpFile = new SHPFile2((SHPStoreParameters) params); |
107 |
super.init(params, storeServices);
|
108 |
this.shpFile.setUseNullGeometry(this.getShpParameters().getUseNullGeometry()); |
109 |
} |
110 |
|
111 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
112 |
if( DataStore.METADATA_CRS.equalsIgnoreCase(name) ) {
|
113 |
|
114 |
/*
|
115 |
* String srs = this.shpFile.getSRSParameters();
|
116 |
if (srs != null){
|
117 |
// This can be non null but not sure how to handle
|
118 |
}
|
119 |
*/
|
120 |
return this.getShpParameters().getCRS(); |
121 |
|
122 |
} else if( DataStore.METADATA_ENVELOPE.equalsIgnoreCase(name) ) { |
123 |
try {
|
124 |
return this.shpFile.getFullExtent(); |
125 |
} catch (ReadException e) {
|
126 |
return null; |
127 |
} |
128 |
} |
129 |
return super.getDynValue(name); |
130 |
} |
131 |
|
132 |
protected void initResource(DBFStoreParameters params, |
133 |
DataStoreProviderServices storeServices) throws InitializeException {
|
134 |
|
135 |
SHPStoreParameters shpParams = (SHPStoreParameters) params; |
136 |
resource = |
137 |
(MultiResource) createResource(MultiResource.TYPE_NAME, |
138 |
new Object[] { shpParams.getSHPFileName() }); |
139 |
|
140 |
resource.addResource(FileResource.NAME, |
141 |
new Object[] { shpParams.getSHPFileName() }, true); |
142 |
resource.addResource(FileResource.NAME, |
143 |
new Object[] { shpParams.getSHXFileName() }, true); |
144 |
resource.addResource(FileResource.NAME, |
145 |
new Object[] { shpParams.getDBFFileName() }, true); |
146 |
|
147 |
resource.addConsumer(this);
|
148 |
}; |
149 |
|
150 |
public ResourceProvider getResource() {
|
151 |
return resource;
|
152 |
} |
153 |
|
154 |
/**
|
155 |
*
|
156 |
* @throws ResourceNotifyChangesException
|
157 |
*/
|
158 |
protected void resourcesNotifyChanges() |
159 |
throws ResourceNotifyChangesException {
|
160 |
// super.resourcesNotifyChanges();
|
161 |
// this.shpResource.notifyChanges();
|
162 |
// this.shxResource.notifyChanges();
|
163 |
getResource().notifyChanges(); |
164 |
// TODO .prj
|
165 |
|
166 |
} |
167 |
|
168 |
/**
|
169 |
* @throws ResourceNotifyCloseException
|
170 |
*
|
171 |
*/
|
172 |
protected void resourcesNotifyClose() throws ResourceNotifyCloseException { |
173 |
// super.resourcesNotifyClose();
|
174 |
// this.shpResource.notifyClose();
|
175 |
// this.shxResource.notifyClose();
|
176 |
getResource().notifyClose(); |
177 |
// TODO .prj
|
178 |
|
179 |
} |
180 |
|
181 |
@Override
|
182 |
protected void doDispose() throws BaseException { |
183 |
super.doDispose();
|
184 |
getResource().removeConsumer(this);
|
185 |
this.writer = null; |
186 |
this.shpFile = null; |
187 |
} |
188 |
|
189 |
protected void disposeResource() { |
190 |
getResource().removeConsumer(this);
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* @throws ResourceNotifyOpenException
|
195 |
*
|
196 |
*/
|
197 |
protected void resourcesOpen() throws ResourceNotifyOpenException { |
198 |
// super.resourcesOpen();
|
199 |
// this.shpResource.notifyOpen();
|
200 |
// this.shxResource.notifyOpen();
|
201 |
getResource().notifyOpen(); |
202 |
} |
203 |
|
204 |
protected static EditableFeatureAttributeDescriptor addGeometryColumn( |
205 |
EditableFeatureType fType) { |
206 |
|
207 |
EditableFeatureAttributeDescriptor attrTmp = null;
|
208 |
EditableFeatureAttributeDescriptor attr = null;
|
209 |
Iterator iter = fType.iterator();
|
210 |
while (iter.hasNext()) {
|
211 |
attrTmp = (EditableFeatureAttributeDescriptor) iter.next(); |
212 |
if (attrTmp.getType() == DataTypes.GEOMETRY) {
|
213 |
if (attr != null) { |
214 |
// Two geom fields not allowed
|
215 |
fType.remove(attrTmp.getName()); |
216 |
} else {
|
217 |
attr = attrTmp; |
218 |
// attr.setName(GEOMETRY_ATTIBUTE_NAME);
|
219 |
} |
220 |
} |
221 |
} |
222 |
|
223 |
|
224 |
if (attr == null){ |
225 |
|
226 |
String geofield = createGeometryFieldName(fType);
|
227 |
attr = fType.add(geofield, DataTypes.GEOMETRY); |
228 |
try {
|
229 |
attr.setDefaultValue(geomManager |
230 |
.createNullGeometry(SUBTYPES.GEOM2D)); |
231 |
} catch (CreateGeometryException e) {
|
232 |
logger.error("Error creating the envelope", e);
|
233 |
} |
234 |
} |
235 |
|
236 |
attr.setObjectClass(Geometry.class); |
237 |
fType.setDefaultGeometryAttributeName(attr.getName()); |
238 |
return attr;
|
239 |
|
240 |
} |
241 |
|
242 |
private static String createGeometryFieldName(FeatureType ft) { |
243 |
|
244 |
if (ft.getAttributeDescriptor(GEOMETRY_ATTIBUTE_NAME) == null) { |
245 |
return GEOMETRY_ATTIBUTE_NAME;
|
246 |
} |
247 |
|
248 |
int i = 0; |
249 |
String candidate = GEOMETRY_ATTIBUTE_NAME + i;
|
250 |
while (ft.getAttributeDescriptor(candidate) != null) { |
251 |
i++; |
252 |
candidate = GEOMETRY_ATTIBUTE_NAME + i; |
253 |
} |
254 |
return candidate;
|
255 |
} |
256 |
|
257 |
protected static FeatureType removeGeometryColumn( |
258 |
EditableFeatureType fType) { |
259 |
Iterator iter = fType.iterator();
|
260 |
FeatureAttributeDescriptor attr; |
261 |
while (iter.hasNext()) {
|
262 |
attr = (FeatureAttributeDescriptor) iter.next(); |
263 |
if (attr.getType() == DataTypes.GEOMETRY) {
|
264 |
iter.remove(); |
265 |
} |
266 |
} |
267 |
fType.setDefaultGeometryAttributeName(null);
|
268 |
return fType.getNotEditableCopy();
|
269 |
} |
270 |
|
271 |
protected EditableFeatureType getTheFeatureType()
|
272 |
throws InitializeException, OpenException {
|
273 |
final EditableFeatureType fType = super.getTheFeatureType(); |
274 |
this.open();
|
275 |
// try {
|
276 |
// this.resourcesBegin();
|
277 |
// } catch (DataException e) {
|
278 |
// throw new InitializeException(this.getName(), e);
|
279 |
// }
|
280 |
try {
|
281 |
getResource().execute(new ResourceAction() {
|
282 |
public Object run() throws Exception { |
283 |
EditableFeatureAttributeDescriptor attr = |
284 |
addGeometryColumn(fType); |
285 |
attr.setGeometryType(shpFile.getGeometryType()); |
286 |
attr.setGeometrySubType(shpFile.getGeometrySubType()); |
287 |
|
288 |
IProjection srs = getShpParameters().getCRS(); |
289 |
attr.setSRS(srs); |
290 |
|
291 |
return null; |
292 |
} |
293 |
}); |
294 |
return fType;
|
295 |
} catch (ResourceExecuteException e) {
|
296 |
throw new InitializeException(e); |
297 |
// } finally {
|
298 |
// this.resourcesEnd();
|
299 |
} |
300 |
} |
301 |
|
302 |
// private String getSRSFromPrj(String srsParameters) {
|
303 |
// // TODO identificar que SRS hay que usar, ya sea
|
304 |
// // el que se recibe de los parametros o el que
|
305 |
// // conicida con el que se ha encontrado en el
|
306 |
// // prg... y si ninguna de las dos que?
|
307 |
// return null;
|
308 |
// }
|
309 |
|
310 |
protected SHPStoreParameters getShpParameters() {
|
311 |
return (SHPStoreParameters) getParameters();
|
312 |
} |
313 |
|
314 |
public String getProviderName() { |
315 |
return NAME;
|
316 |
} |
317 |
|
318 |
public boolean allowWrite() { |
319 |
return this.shpFile.isEditable(); |
320 |
} |
321 |
|
322 |
/**
|
323 |
*
|
324 |
* @param index
|
325 |
* @param featureType
|
326 |
* @return
|
327 |
* @throws ReadException
|
328 |
*/
|
329 |
protected FeatureProvider getFeatureProviderByIndex(long index, |
330 |
FeatureType featureType) throws DataException {
|
331 |
// this.open();
|
332 |
// this.resourcesBegin();
|
333 |
try {
|
334 |
|
335 |
FeatureProvider featureProvider = super.getFeatureProviderByIndex(index,
|
336 |
featureType); |
337 |
featureProvider.setDefaultEnvelope(this.shpFile.getBoundingBox(index));
|
338 |
return featureProvider;
|
339 |
} catch (DataException e) {
|
340 |
throw e;
|
341 |
} catch (CreateEnvelopeException e) {
|
342 |
throw new org.gvsig.fmap.dal.feature.exception.CreateGeometryException(e); |
343 |
} catch (CreateGeometryException e) {
|
344 |
throw new org.gvsig.fmap.dal.feature.exception.CreateGeometryException(e); |
345 |
} |
346 |
|
347 |
} |
348 |
|
349 |
protected void initFeatureProviderByIndex(FeatureProvider featureProvider, |
350 |
long index, FeatureType featureType) throws DataException { |
351 |
// this.open();
|
352 |
// this.resourcesBegin();
|
353 |
try {
|
354 |
super.initFeatureProviderByIndex(featureProvider, index, featureType);
|
355 |
featureProvider.setDefaultEnvelope(this.shpFile.getBoundingBox(index));
|
356 |
} catch (CreateEnvelopeException e) {
|
357 |
throw new org.gvsig.fmap.dal.feature.exception.CreateGeometryException(e); |
358 |
} catch (CreateGeometryException e) {
|
359 |
throw new org.gvsig.fmap.dal.feature.exception.CreateGeometryException(e); |
360 |
} |
361 |
} |
362 |
|
363 |
/**
|
364 |
*
|
365 |
* @param featureProvider
|
366 |
* @throws DataException
|
367 |
*/
|
368 |
protected void loadFeatureProviderByIndex(FeatureProvider featureProvider) |
369 |
throws DataException {
|
370 |
|
371 |
FeatureType featureType = featureProvider.getType(); |
372 |
long index = ((Long) featureProvider.getOID()).longValue(); |
373 |
boolean hasGeometry = false; |
374 |
int i = featureType.getDefaultGeometryAttributeIndex();
|
375 |
if (i >= 0) { |
376 |
if (!featureProvider.isReadOnly(i)) {
|
377 |
try {
|
378 |
Geometry geom = this.shpFile.getGeometry(index);
|
379 |
featureProvider.set(i, geom); |
380 |
} catch (CreateGeometryException e) {
|
381 |
throw new ReadException(getProviderName(), e); |
382 |
} |
383 |
} |
384 |
hasGeometry = true;
|
385 |
} |
386 |
if (hasDBFAttributes(featureType, hasGeometry)) {
|
387 |
super.loadFeatureProviderByIndex(featureProvider);
|
388 |
} |
389 |
|
390 |
} |
391 |
|
392 |
private boolean hasDBFAttributes(FeatureType featureType, |
393 |
boolean hasGeometry) {
|
394 |
FeatureAttributeDescriptor[] attributes =
|
395 |
featureType.getAttributeDescriptors(); |
396 |
// If there aren't any attributes, nor has any DBF attributes
|
397 |
if (attributes == null || attributes.length == 0) { |
398 |
return false; |
399 |
} |
400 |
// If there is only one attribute and it is the geometry one
|
401 |
if (attributes.length == 1 && hasGeometry) { |
402 |
return false; |
403 |
} |
404 |
// In any other case
|
405 |
return true; |
406 |
} |
407 |
|
408 |
protected void loadValue(FeatureProvider featureProvider, int rowIndex, |
409 |
FeatureAttributeDescriptor descriptor) throws ReadException {
|
410 |
if (descriptor.getType() == DataTypes.GEOMETRY) {
|
411 |
return;
|
412 |
} else {
|
413 |
super.loadValue(featureProvider, rowIndex, descriptor);
|
414 |
} |
415 |
} |
416 |
|
417 |
public FeatureProvider createFeatureProvider(FeatureType type) throws DataException { |
418 |
FeatureProvider data = new SHPFeatureProvider(this, type); |
419 |
return data;
|
420 |
} |
421 |
|
422 |
|
423 |
protected void openFile() throws IOException, DataException { |
424 |
super.openFile();
|
425 |
this.shpFile.open();
|
426 |
|
427 |
} |
428 |
|
429 |
protected void closeFile() throws CloseException { |
430 |
super.closeFile();
|
431 |
if (!this.shpFile.isOpen()) { |
432 |
return;
|
433 |
} |
434 |
this.shpFile.close();
|
435 |
} |
436 |
|
437 |
public boolean canWriteGeometry(final int geometryType, int geometrySubType) |
438 |
throws DataException {
|
439 |
this.open();
|
440 |
return ((Boolean) getResource().execute(new ResourceAction() { |
441 |
public Object run() throws Exception { |
442 |
boolean value = shpFile.canWriteGeometry(geometryType);
|
443 |
return value ? Boolean.TRUE : Boolean.FALSE; |
444 |
} |
445 |
})).booleanValue(); |
446 |
// this.resourcesBegin();
|
447 |
// try {
|
448 |
// return this.shpFile.canWriteGeometry(geometryType);
|
449 |
//
|
450 |
// } finally {
|
451 |
// this.resourcesEnd();
|
452 |
// }
|
453 |
} |
454 |
|
455 |
public void performChanges(Iterator deleteds, Iterator inserteds, |
456 |
Iterator updateds, Iterator originalFeatureTypesUpdated) |
457 |
throws PerformEditingException {
|
458 |
|
459 |
|
460 |
/*
|
461 |
* This will throw an exception if there are new fields
|
462 |
* with names too long
|
463 |
*/
|
464 |
checkNewFieldsNameSize(originalFeatureTypesUpdated); |
465 |
|
466 |
|
467 |
final FeatureType fType;
|
468 |
try {
|
469 |
fType = this.getStoreServices().getDefaultFeatureType();
|
470 |
} catch (DataException e) {
|
471 |
throw new PerformEditingException(this.getProviderName(), e); |
472 |
} |
473 |
// TODO Comprobar el campo de geometria
|
474 |
|
475 |
final EditableFeatureType dbfFtype = fType.getEditable();
|
476 |
|
477 |
removeGeometryColumn(dbfFtype); |
478 |
|
479 |
// try {
|
480 |
// this.resourcesBegin();
|
481 |
// } catch (ResourceExecuteException e1) {
|
482 |
// throw new PerformEditingException(this.getName(), e1);
|
483 |
// }
|
484 |
|
485 |
try {
|
486 |
|
487 |
getResource().execute(new ResourceAction() {
|
488 |
public Object run() throws Exception { |
489 |
FeatureSet set = null;
|
490 |
DisposableIterator iter = null;
|
491 |
try {
|
492 |
set = getFeatureStore().getFeatureSet(); |
493 |
writer = new SHPFeatureWriter(getProviderName());
|
494 |
|
495 |
SHPStoreParameters shpParams = getShpParameters(); |
496 |
SHPStoreParameters tmpParams = |
497 |
(SHPStoreParameters) shpParams.getCopy(); |
498 |
|
499 |
File tmp_base = File.createTempFile( |
500 |
"tmp_" + System.currentTimeMillis(), null); |
501 |
String str_base = tmp_base.getCanonicalPath();
|
502 |
|
503 |
tmpParams.setDBFFile(str_base + ".dbf");
|
504 |
tmpParams.setSHPFile(str_base + ".shp");
|
505 |
tmpParams.setSHXFile(str_base + ".shx");
|
506 |
|
507 |
writer.begin(tmpParams, fType, dbfFtype, set.getSize()); |
508 |
|
509 |
iter = set.fastIterator(); |
510 |
while (iter.hasNext()) {
|
511 |
Feature feature = (Feature) iter.next(); |
512 |
writer.append(feature); |
513 |
} |
514 |
|
515 |
writer.end(); |
516 |
|
517 |
close(); |
518 |
resourceCloseRequest(); |
519 |
|
520 |
if (!shpParams.getDBFFile().delete()) {
|
521 |
throw new PerformEditingException(getProviderName(), |
522 |
new IOException(shpParams.getDBFFileName())); |
523 |
} |
524 |
if (!shpParams.getSHPFile().delete()) {
|
525 |
throw new PerformEditingException(getProviderName(), |
526 |
new IOException(shpParams.getSHPFileName())); |
527 |
} |
528 |
if (!shpParams.getSHXFile().delete()) {
|
529 |
throw new PerformEditingException(getProviderName(), |
530 |
new IOException(shpParams.getSHXFileName())); |
531 |
} |
532 |
|
533 |
if (!tmpParams.getDBFFile().renameTo(
|
534 |
shpParams.getDBFFile())) { |
535 |
logger.info("Warning: copying tmp file instead of renaming: "
|
536 |
+ shpParams.getDBFFile()); |
537 |
FileUtils.copyFile( |
538 |
tmpParams.getDBFFile(), |
539 |
shpParams.getDBFFile()); |
540 |
} |
541 |
if (!tmpParams.getSHPFile().renameTo(
|
542 |
shpParams.getSHPFile())) { |
543 |
logger.info("Warning: copying tmp file instead of renaming: "
|
544 |
+ shpParams.getSHPFile()); |
545 |
FileUtils.copyFile( |
546 |
tmpParams.getSHPFile(), |
547 |
shpParams.getSHPFile()); |
548 |
} |
549 |
if (!tmpParams.getSHXFile().renameTo(
|
550 |
shpParams.getSHXFile())) { |
551 |
logger.info("Warning: copying tmp file instead of renaming: "
|
552 |
+ shpParams.getSHXFile()); |
553 |
FileUtils.copyFile( |
554 |
tmpParams.getSHXFile(), |
555 |
shpParams.getSHXFile()); |
556 |
} |
557 |
|
558 |
resourcesNotifyChanges(); |
559 |
initFeatureType(); |
560 |
return null; |
561 |
} finally {
|
562 |
dispose(set); |
563 |
dispose(iter); |
564 |
} |
565 |
} |
566 |
}); |
567 |
|
568 |
} catch (Exception e) { |
569 |
throw new PerformEditingException(this.getProviderName(), e); |
570 |
// } finally {
|
571 |
// this.resourcesEnd();
|
572 |
} |
573 |
|
574 |
|
575 |
} |
576 |
|
577 |
|
578 |
|
579 |
protected void resourceCloseRequest() throws ResourceException { |
580 |
// super.resourceCloseRequest();
|
581 |
// this.shpResource.closeRequest();
|
582 |
// this.shxResource.closeRequest();
|
583 |
getResource().closeRequest(); |
584 |
} |
585 |
|
586 |
public Envelope getEnvelope() throws DataException { |
587 |
this.open();
|
588 |
return (Envelope) this.getDynValue("Envelope"); |
589 |
} |
590 |
|
591 |
public void append(final FeatureProvider featureProvider) throws DataException { |
592 |
// this.resourcesBegin();
|
593 |
// try {
|
594 |
|
595 |
getResource().execute(new ResourceAction() {
|
596 |
public Object run() throws Exception { |
597 |
writer.append(getStoreServices().createFeature(featureProvider)); |
598 |
return null; |
599 |
} |
600 |
}); |
601 |
// } finally {
|
602 |
// this.resourcesEnd();
|
603 |
// }
|
604 |
|
605 |
} |
606 |
|
607 |
public void beginAppend() throws DataException { |
608 |
// this.resourcesBegin();
|
609 |
// try {
|
610 |
|
611 |
getResource().execute(new ResourceAction() {
|
612 |
public Object run() throws Exception { |
613 |
FeatureStore store = getFeatureStore(); |
614 |
FeatureType fType = store.getDefaultFeatureType(); |
615 |
|
616 |
// TODO Comprobar el campo de geometria
|
617 |
|
618 |
EditableFeatureType dbfFtype = fType.getEditable(); |
619 |
|
620 |
removeGeometryColumn(dbfFtype); |
621 |
FeatureSet set = store.getFeatureSet(); |
622 |
|
623 |
writer = new SHPFeatureWriter(getProviderName());
|
624 |
|
625 |
writer.begin(getShpParameters(), fType, dbfFtype, set.getSize()); |
626 |
return null; |
627 |
} |
628 |
}); |
629 |
// } finally {
|
630 |
// this.resourcesEnd();
|
631 |
// }
|
632 |
|
633 |
} |
634 |
|
635 |
public void endAppend() throws DataException { |
636 |
// this.resourcesBegin();
|
637 |
// try {
|
638 |
getResource().execute(new ResourceAction() {
|
639 |
public Object run() throws Exception { |
640 |
writer.end(); |
641 |
resourcesNotifyChanges(); |
642 |
return null; |
643 |
} |
644 |
}); |
645 |
// } finally {
|
646 |
// this.resourcesEnd();
|
647 |
// }
|
648 |
|
649 |
} |
650 |
|
651 |
public Object getSourceId() { |
652 |
return this.getShpParameters().getFile(); |
653 |
} |
654 |
} |