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