svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dalfile / src / org / gvsig / fmap / dal / store / shp / SHPStoreProvider.java @ 33718
History | View | Annotate | Download (17.7 KB)
1 | 24447 | jmvivo | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
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 2
|
||
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 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2008 IVER T.I. S.A. {{Task}}
|
||
26 | */
|
||
27 | |||
28 | 24498 | jmvivo | package org.gvsig.fmap.dal.store.shp; |
29 | 24447 | jmvivo | |
30 | 26061 | jmvivo | import java.io.IOException; |
31 | 24447 | jmvivo | import java.util.Iterator; |
32 | |||
33 | 26717 | jmvivo | import org.cresques.cts.IProjection; |
34 | import org.gvsig.fmap.crs.CRSFactory; |
||
35 | 32880 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
36 | 24498 | jmvivo | import org.gvsig.fmap.dal.DataTypes; |
37 | 32880 | jjdelcerro | import org.gvsig.fmap.dal.FileHelper; |
38 | 24502 | jmvivo | import org.gvsig.fmap.dal.exception.CloseException; |
39 | import org.gvsig.fmap.dal.exception.DataException; |
||
40 | import org.gvsig.fmap.dal.exception.InitializeException; |
||
41 | 31022 | cordinyana | import org.gvsig.fmap.dal.exception.OpenException; |
42 | 24502 | jmvivo | import org.gvsig.fmap.dal.exception.ReadException; |
43 | 33205 | cordinyana | import org.gvsig.tools.dispose.DisposableIterator; |
44 | 24498 | jmvivo | 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 | 24791 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureSet; |
49 | 29326 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureStore; |
50 | 24498 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureType; |
51 | 24502 | jmvivo | import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
52 | 29289 | jmvivo | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
53 | 31022 | cordinyana | import org.gvsig.fmap.dal.resource.ResourceAction; |
54 | 27875 | vcaballero | import org.gvsig.fmap.dal.resource.exception.ResourceException; |
55 | 31022 | cordinyana | import org.gvsig.fmap.dal.resource.exception.ResourceExecuteException; |
56 | 25955 | jmvivo | import org.gvsig.fmap.dal.resource.exception.ResourceNotifyChangesException; |
57 | 24498 | jmvivo | 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 | 31022 | cordinyana | import org.gvsig.fmap.dal.resource.spi.MultiResource; |
61 | 24498 | jmvivo | import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
62 | 29326 | jmvivo | import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
63 | import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters; |
||
64 | 24498 | jmvivo | import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider; |
65 | import org.gvsig.fmap.dal.store.shp.utils.SHPFile; |
||
66 | 33338 | jpiera | import org.gvsig.fmap.geom.Geometry; |
67 | 27413 | jpiera | import org.gvsig.fmap.geom.GeometryLocator; |
68 | import org.gvsig.fmap.geom.GeometryManager; |
||
69 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
70 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
71 | import org.gvsig.fmap.geom.exception.CreateGeometryException; |
||
72 | 25164 | jmvivo | import org.gvsig.fmap.geom.primitive.Envelope; |
73 | 26252 | jmvivo | import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
74 | 31284 | cordinyana | import org.gvsig.tools.exception.BaseException; |
75 | 27413 | jpiera | import org.slf4j.Logger; |
76 | import org.slf4j.LoggerFactory; |
||
77 | 24447 | jmvivo | |
78 | public class SHPStoreProvider extends DBFStoreProvider { |
||
79 | 27413 | jpiera | private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
80 | private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class); |
||
81 | 29518 | jmvivo | public static String NAME = "Shape"; |
82 | public static String DESCRIPTION = "Shape file"; |
||
83 | 24447 | jmvivo | private SHPFile shpFile;
|
84 | 25955 | jmvivo | |
85 | 31022 | cordinyana | private MultiResource resource;
|
86 | 29326 | jmvivo | |
87 | 24791 | jmvivo | protected static final String GEOMETRY_ATTIBUTE_NAME = "GEOMETRY"; |
88 | 25789 | jmvivo | |
89 | 32880 | jjdelcerro | public static final String METADATA_DEFINITION_NAME = NAME; |
90 | |||
91 | 25752 | vcaballero | private SHPFeatureWriter writer = null; |
92 | 24447 | jmvivo | |
93 | 29326 | jmvivo | public SHPStoreProvider(SHPStoreParameters params,
|
94 | DataStoreProviderServices storeServices) |
||
95 | 24447 | jmvivo | throws InitializeException {
|
96 | 32880 | jjdelcerro | super(
|
97 | params, |
||
98 | storeServices, |
||
99 | FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME) |
||
100 | ); |
||
101 | 29326 | jmvivo | } |
102 | 24447 | jmvivo | |
103 | 29326 | jmvivo | protected void init(DBFStoreParameters params, |
104 | DataStoreProviderServices storeServices) throws InitializeException {
|
||
105 | |||
106 | 31022 | cordinyana | this.shpFile = new SHPFile((SHPStoreParameters) params); |
107 | 29326 | jmvivo | super.init(params, storeServices);
|
108 | 24447 | jmvivo | } |
109 | |||
110 | 32880 | jjdelcerro | public Object getDynValue(String name) throws DynFieldNotFoundException { |
111 | if( DataStore.METADATA_CRS.equalsIgnoreCase(name) ) {
|
||
112 | 33396 | cmartin | String srs = this.shpFile.getSRSParameters(); |
113 | if (srs == null){ |
||
114 | return this.getShpParameters().getCRS(); |
||
115 | } |
||
116 | 32880 | jjdelcerro | } else if( DataStore.METADATA_ENVELOPE.equalsIgnoreCase(name) ) { |
117 | try {
|
||
118 | return this.shpFile.getFullExtent(); |
||
119 | } catch (ReadException e) {
|
||
120 | return null; |
||
121 | } |
||
122 | } |
||
123 | return super.getDynValue(name); |
||
124 | } |
||
125 | |||
126 | 31022 | cordinyana | protected void initResource(DBFStoreParameters params, |
127 | DataStoreProviderServices storeServices) throws InitializeException {
|
||
128 | 32880 | jjdelcerro | |
129 | 31022 | cordinyana | SHPStoreParameters shpParams = (SHPStoreParameters) params; |
130 | resource = |
||
131 | (MultiResource) createResource(MultiResource.TYPE_NAME, |
||
132 | new Object[] { shpParams.getSHPFileName() }); |
||
133 | 26252 | jmvivo | |
134 | 31022 | cordinyana | resource.addResource(FileResource.NAME, |
135 | new Object[] { shpParams.getSHPFileName() }, true); |
||
136 | resource.addResource(FileResource.NAME, |
||
137 | new Object[] { shpParams.getSHXFileName() }, true); |
||
138 | resource.addResource(FileResource.NAME, |
||
139 | new Object[] { shpParams.getDBFFileName() }, true); |
||
140 | 25955 | jmvivo | |
141 | 31022 | cordinyana | resource.addConsumer(this);
|
142 | }; |
||
143 | 26252 | jmvivo | |
144 | 31022 | cordinyana | public ResourceProvider getResource() {
|
145 | return resource;
|
||
146 | 25955 | jmvivo | } |
147 | |||
148 | /**
|
||
149 | 26057 | jmvivo | *
|
150 | 25955 | jmvivo | * @throws ResourceNotifyChangesException
|
151 | */
|
||
152 | 26252 | jmvivo | protected void resourcesNotifyChanges() |
153 | throws ResourceNotifyChangesException {
|
||
154 | 31022 | cordinyana | // super.resourcesNotifyChanges();
|
155 | // this.shpResource.notifyChanges();
|
||
156 | // this.shxResource.notifyChanges();
|
||
157 | getResource().notifyChanges(); |
||
158 | 26252 | jmvivo | // TODO .prj
|
159 | |||
160 | 25955 | jmvivo | } |
161 | |||
162 | /**
|
||
163 | * @throws ResourceNotifyCloseException
|
||
164 | 26057 | jmvivo | *
|
165 | 25955 | jmvivo | */
|
166 | 26252 | jmvivo | protected void resourcesNotifyClose() throws ResourceNotifyCloseException { |
167 | 31022 | cordinyana | // super.resourcesNotifyClose();
|
168 | // this.shpResource.notifyClose();
|
||
169 | // this.shxResource.notifyClose();
|
||
170 | getResource().notifyClose(); |
||
171 | 26252 | jmvivo | // TODO .prj
|
172 | |||
173 | 25955 | jmvivo | } |
174 | |||
175 | 31284 | cordinyana | @Override
|
176 | protected void doDispose() throws BaseException { |
||
177 | super.doDispose();
|
||
178 | getResource().removeConsumer(this);
|
||
179 | 26252 | jmvivo | this.writer = null; |
180 | this.shpFile = null; |
||
181 | } |
||
182 | |||
183 | 31022 | cordinyana | protected void disposeResource() { |
184 | getResource().removeConsumer(this);
|
||
185 | } |
||
186 | |||
187 | 25965 | jmvivo | /**
|
188 | * @throws ResourceNotifyOpenException
|
||
189 | 26057 | jmvivo | *
|
190 | 25965 | jmvivo | */
|
191 | 26252 | jmvivo | protected void resourcesOpen() throws ResourceNotifyOpenException { |
192 | 31022 | cordinyana | // super.resourcesOpen();
|
193 | // this.shpResource.notifyOpen();
|
||
194 | // this.shxResource.notifyOpen();
|
||
195 | getResource().notifyOpen(); |
||
196 | 25965 | jmvivo | } |
197 | 25955 | jmvivo | |
198 | 24918 | jmvivo | protected static EditableFeatureAttributeDescriptor addGeometryColumn( |
199 | 24791 | jmvivo | EditableFeatureType fType) { |
200 | |||
201 | 26057 | jmvivo | EditableFeatureAttributeDescriptor attrTmp = null;
|
202 | EditableFeatureAttributeDescriptor attr = null;
|
||
203 | Iterator iter = fType.iterator();
|
||
204 | while (iter.hasNext()) {
|
||
205 | attrTmp = (EditableFeatureAttributeDescriptor) iter.next(); |
||
206 | 33331 | jjdelcerro | if (attrTmp.getType() == DataTypes.GEOMETRY) {
|
207 | 26057 | jmvivo | if (attr != null) { |
208 | // Two geom fields not allowed
|
||
209 | fType.remove(attrTmp.getName()); |
||
210 | } else {
|
||
211 | attr = attrTmp; |
||
212 | attr.setName(GEOMETRY_ATTIBUTE_NAME); |
||
213 | } |
||
214 | } |
||
215 | } |
||
216 | |||
217 | |||
218 | if (attr == null){ |
||
219 | attr = fType.add( |
||
220 | GEOMETRY_ATTIBUTE_NAME, DataTypes.GEOMETRY); |
||
221 | 27413 | jpiera | try {
|
222 | 30551 | jmvivo | attr.setDefaultValue(geomManager |
223 | .createNullGeometry(SUBTYPES.GEOM2D)); |
||
224 | 27413 | jpiera | } catch (CreateGeometryException e) {
|
225 | logger.error("Error creating the envelope", e);
|
||
226 | } |
||
227 | 26057 | jmvivo | } |
228 | |||
229 | 33338 | jpiera | attr.setObjectClass(Geometry.class); |
230 | 25164 | jmvivo | fType.setDefaultGeometryAttributeName(attr.getName()); |
231 | return attr;
|
||
232 | |||
233 | 24791 | jmvivo | } |
234 | |||
235 | 26323 | jmvivo | protected static FeatureType removeGeometryColumn( |
236 | 24791 | jmvivo | EditableFeatureType fType) { |
237 | 26057 | jmvivo | Iterator iter = fType.iterator();
|
238 | FeatureAttributeDescriptor attr; |
||
239 | while (iter.hasNext()) {
|
||
240 | attr = (FeatureAttributeDescriptor) iter.next(); |
||
241 | 33331 | jjdelcerro | if (attr.getType() == DataTypes.GEOMETRY) {
|
242 | 26057 | jmvivo | iter.remove(); |
243 | } |
||
244 | } |
||
245 | fType.setDefaultGeometryAttributeName(null);
|
||
246 | 26323 | jmvivo | return fType.getNotEditableCopy();
|
247 | 24791 | jmvivo | } |
248 | |||
249 | 24447 | jmvivo | protected EditableFeatureType getTheFeatureType()
|
250 | 31022 | cordinyana | throws InitializeException, OpenException {
|
251 | final EditableFeatureType fType = super.getTheFeatureType(); |
||
252 | this.open();
|
||
253 | // try {
|
||
254 | // this.resourcesBegin();
|
||
255 | // } catch (DataException e) {
|
||
256 | // throw new InitializeException(this.getName(), e);
|
||
257 | // }
|
||
258 | 24447 | jmvivo | try {
|
259 | 31022 | cordinyana | getResource().execute(new ResourceAction() {
|
260 | public Object run() throws Exception { |
||
261 | EditableFeatureAttributeDescriptor attr = |
||
262 | addGeometryColumn(fType); |
||
263 | attr.setGeometryType(shpFile.getGeometryType()); |
||
264 | attr.setGeometrySubType(shpFile.getGeometrySubType()); |
||
265 | // String srs =
|
||
266 | // this.getSRSFromPrj(this.shpFile.getSRSParameters());
|
||
267 | // if (srs == null){
|
||
268 | // // TODO petar ??
|
||
269 | // srs = "EPSG:23030";
|
||
270 | // }
|
||
271 | 32880 | jjdelcerro | IProjection srs = getShpParameters().getCRS(); |
272 | 31022 | cordinyana | if (srs == null) { |
273 | srs = CRSFactory.getCRS("EPSG:23030");
|
||
274 | } |
||
275 | 24447 | jmvivo | |
276 | 31022 | cordinyana | attr.setSRS(srs); |
277 | 26717 | jmvivo | |
278 | 31022 | cordinyana | return null; |
279 | } |
||
280 | }); |
||
281 | 24447 | jmvivo | return fType;
|
282 | 31022 | cordinyana | } catch (ResourceExecuteException e) {
|
283 | 24447 | jmvivo | throw new InitializeException(e); |
284 | 31022 | cordinyana | // } finally {
|
285 | // this.resourcesEnd();
|
||
286 | 24447 | jmvivo | } |
287 | } |
||
288 | |||
289 | 32880 | jjdelcerro | // private String getSRSFromPrj(String srsParameters) {
|
290 | // // TODO identificar que SRS hay que usar, ya sea
|
||
291 | // // el que se recibe de los parametros o el que
|
||
292 | // // conicida con el que se ha encontrado en el
|
||
293 | // // prg... y si ninguna de las dos que?
|
||
294 | // return null;
|
||
295 | // }
|
||
296 | 24447 | jmvivo | |
297 | protected SHPStoreParameters getShpParameters() {
|
||
298 | 29326 | jmvivo | return (SHPStoreParameters) getParameters();
|
299 | 24447 | jmvivo | } |
300 | |||
301 | 33718 | jjdelcerro | public String getProviderName() { |
302 | 24447 | jmvivo | return NAME;
|
303 | } |
||
304 | |||
305 | public boolean allowWrite() { |
||
306 | 31101 | cordinyana | return this.shpFile.isEditable(); |
307 | 24447 | jmvivo | } |
308 | |||
309 | /**
|
||
310 | 25610 | vcaballero | *
|
311 | 24447 | jmvivo | * @param index
|
312 | * @param featureType
|
||
313 | * @return
|
||
314 | * @throws ReadException
|
||
315 | */
|
||
316 | 29292 | jmvivo | protected FeatureProvider getFeatureProviderByIndex(long index, |
317 | 24447 | jmvivo | FeatureType featureType) throws DataException {
|
318 | 31022 | cordinyana | // this.open();
|
319 | // this.resourcesBegin();
|
||
320 | 24447 | jmvivo | try {
|
321 | |||
322 | 29292 | jmvivo | FeatureProvider featureProvider = super.getFeatureProviderByIndex(index,
|
323 | 24447 | jmvivo | featureType); |
324 | 29292 | jmvivo | featureProvider.setDefaultEnvelope(this.shpFile.getBoundingBox(index));
|
325 | return featureProvider;
|
||
326 | 24447 | jmvivo | } catch (DataException e) {
|
327 | throw e;
|
||
328 | 27413 | jpiera | } catch (CreateEnvelopeException e) {
|
329 | throw new org.gvsig.fmap.dal.feature.exception.CreateGeometryException(e); |
||
330 | 31022 | cordinyana | // } finally {
|
331 | // this.resourcesEnd();
|
||
332 | 24447 | jmvivo | } |
333 | |||
334 | } |
||
335 | |||
336 | 29292 | jmvivo | protected void initFeatureProviderByIndex(FeatureProvider featureProvider, |
337 | 24447 | jmvivo | long index, FeatureType featureType) throws DataException { |
338 | 31022 | cordinyana | // this.open();
|
339 | // this.resourcesBegin();
|
||
340 | 24447 | jmvivo | try {
|
341 | 29292 | jmvivo | super.initFeatureProviderByIndex(featureProvider, index, featureType);
|
342 | featureProvider.setDefaultEnvelope(this.shpFile.getBoundingBox(index));
|
||
343 | 27413 | jpiera | } catch (CreateEnvelopeException e) {
|
344 | throw new org.gvsig.fmap.dal.feature.exception.CreateGeometryException(e); |
||
345 | 31022 | cordinyana | // } finally {
|
346 | // this.resourcesEnd();
|
||
347 | 24447 | jmvivo | } |
348 | |||
349 | } |
||
350 | |||
351 | /**
|
||
352 | 25610 | vcaballero | *
|
353 | 29292 | jmvivo | * @param featureProvider
|
354 | 24447 | jmvivo | * @throws DataException
|
355 | */
|
||
356 | 29292 | jmvivo | protected void loadFeatureProviderByIndex(FeatureProvider featureProvider) |
357 | 24447 | jmvivo | throws DataException {
|
358 | 31022 | cordinyana | // this.open();
|
359 | // this.resourcesBegin();
|
||
360 | // try {
|
||
361 | 30920 | cordinyana | FeatureType featureType = featureProvider.getType(); |
362 | 29292 | jmvivo | long index = ((Long) featureProvider.getOID()).longValue(); |
363 | 30920 | cordinyana | boolean hasGeometry = false; |
364 | if (featureType.getIndex(featureType.getDefaultGeometryAttributeName()) >= 0) { |
||
365 | 26904 | jpiera | try {
|
366 | 29292 | jmvivo | featureProvider.setDefaultGeometry(this.shpFile.getGeometry(index));
|
367 | 30920 | cordinyana | hasGeometry = true;
|
368 | 27413 | jpiera | } catch (CreateGeometryException e) {
|
369 | 33718 | jjdelcerro | throw new ReadException(getProviderName(), e); |
370 | 26904 | jpiera | } |
371 | 25241 | jmvivo | } |
372 | 30920 | cordinyana | if (hasDBFAttributes(featureType, hasGeometry)) {
|
373 | super.loadFeatureProviderByIndex(featureProvider);
|
||
374 | } |
||
375 | 24447 | jmvivo | |
376 | 31022 | cordinyana | // } finally {
|
377 | // this.resourcesEnd();
|
||
378 | // }
|
||
379 | 30920 | cordinyana | |
380 | 24447 | jmvivo | } |
381 | |||
382 | 30920 | cordinyana | private boolean hasDBFAttributes(FeatureType featureType, |
383 | boolean hasGeometry) {
|
||
384 | FeatureAttributeDescriptor[] attributes =
|
||
385 | featureType.getAttributeDescriptors(); |
||
386 | // If there aren't any attributes, nor has any DBF attributes
|
||
387 | if (attributes == null || attributes.length == 0) { |
||
388 | return false; |
||
389 | } |
||
390 | // If there is only one attribute and it is the geometry one
|
||
391 | if (attributes.length == 1 && hasGeometry) { |
||
392 | return false; |
||
393 | } |
||
394 | // In any other case
|
||
395 | return true; |
||
396 | } |
||
397 | 24447 | jmvivo | |
398 | 29292 | jmvivo | protected void loadValue(FeatureProvider featureProvider, int rowIndex, |
399 | 24447 | jmvivo | FeatureAttributeDescriptor descriptor) throws ReadException {
|
400 | 33331 | jjdelcerro | if (descriptor.getType() == DataTypes.GEOMETRY) {
|
401 | 24447 | jmvivo | return;
|
402 | } else {
|
||
403 | 29292 | jmvivo | super.loadValue(featureProvider, rowIndex, descriptor);
|
404 | 24447 | jmvivo | } |
405 | } |
||
406 | |||
407 | 29292 | jmvivo | public FeatureProvider createFeatureProvider(FeatureType type) throws DataException { |
408 | FeatureProvider data = new SHPFeatureProvider(this, type); |
||
409 | 25610 | vcaballero | return data;
|
410 | 24447 | jmvivo | } |
411 | |||
412 | 25789 | jmvivo | |
413 | 26252 | jmvivo | protected void openFile() throws IOException, DataException { |
414 | super.openFile();
|
||
415 | this.shpFile.open();
|
||
416 | 25965 | jmvivo | |
417 | 26252 | jmvivo | } |
418 | 25789 | jmvivo | |
419 | 26252 | jmvivo | protected void closeFile() throws CloseException { |
420 | super.closeFile();
|
||
421 | 24447 | jmvivo | if (!this.shpFile.isOpen()) { |
422 | return;
|
||
423 | } |
||
424 | 26252 | jmvivo | this.shpFile.close();
|
425 | 24447 | jmvivo | } |
426 | |||
427 | 31022 | cordinyana | public boolean canWriteGeometry(final int geometryType, int geometrySubType) |
428 | throws DataException {
|
||
429 | 24447 | jmvivo | this.open();
|
430 | 31022 | cordinyana | return ((Boolean) getResource().execute(new ResourceAction() { |
431 | public Object run() throws Exception { |
||
432 | boolean value = shpFile.canWriteGeometry(geometryType);
|
||
433 | return value ? Boolean.TRUE : Boolean.FALSE; |
||
434 | } |
||
435 | })).booleanValue(); |
||
436 | // this.resourcesBegin();
|
||
437 | // try {
|
||
438 | // return this.shpFile.canWriteGeometry(geometryType);
|
||
439 | //
|
||
440 | // } finally {
|
||
441 | // this.resourcesEnd();
|
||
442 | // }
|
||
443 | 24447 | jmvivo | } |
444 | |||
445 | 29289 | jmvivo | public void performChanges(Iterator deleteds, Iterator inserteds, |
446 | 28098 | jmvivo | Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException { |
447 | 31022 | cordinyana | final FeatureType fType;
|
448 | 24791 | jmvivo | try {
|
449 | 29326 | jmvivo | fType = this.getStoreServices().getDefaultFeatureType();
|
450 | 24791 | jmvivo | } catch (DataException e) {
|
451 | 33718 | jjdelcerro | throw new PerformEditingException(this.getProviderName(), e); |
452 | 24791 | jmvivo | } |
453 | // TODO Comprobar el campo de geometria
|
||
454 | |||
455 | 31022 | cordinyana | final EditableFeatureType dbfFtype = fType.getEditable();
|
456 | 24791 | jmvivo | |
457 | 24925 | jmvivo | removeGeometryColumn(dbfFtype); |
458 | 24791 | jmvivo | |
459 | 31022 | cordinyana | // try {
|
460 | // this.resourcesBegin();
|
||
461 | // } catch (ResourceExecuteException e1) {
|
||
462 | // throw new PerformEditingException(this.getName(), e1);
|
||
463 | // }
|
||
464 | 25752 | vcaballero | |
465 | 24791 | jmvivo | try {
|
466 | 25955 | jmvivo | |
467 | 31022 | cordinyana | getResource().execute(new ResourceAction() {
|
468 | public Object run() throws Exception { |
||
469 | 31284 | cordinyana | FeatureSet set = null;
|
470 | DisposableIterator iter = null;
|
||
471 | try {
|
||
472 | set = getFeatureStore().getFeatureSet(); |
||
473 | 33718 | jjdelcerro | writer = new SHPFeatureWriter(getProviderName());
|
474 | 25789 | jmvivo | |
475 | 31284 | cordinyana | SHPStoreParameters shpParams = getShpParameters(); |
476 | SHPStoreParameters tmpParams = |
||
477 | (SHPStoreParameters) shpParams.getCopy(); |
||
478 | 32880 | jjdelcerro | tmpParams.setDBFFile(tmpParams.getDBFFileName() |
479 | 31284 | cordinyana | + ".tmp");
|
480 | 32880 | jjdelcerro | tmpParams.setSHPFile(tmpParams.getSHPFileName() |
481 | 31284 | cordinyana | + ".tmp");
|
482 | 32880 | jjdelcerro | tmpParams.setSHXFile(tmpParams.getSHXFileName() |
483 | 31284 | cordinyana | + ".tmp");
|
484 | 25782 | vcaballero | |
485 | 31284 | cordinyana | writer.begin(tmpParams, fType, dbfFtype, set.getSize()); |
486 | 25997 | jmvivo | |
487 | 31284 | cordinyana | iter = set.fastIterator(); |
488 | while (iter.hasNext()) {
|
||
489 | Feature feature = (Feature) iter.next(); |
||
490 | writer.append(feature); |
||
491 | } |
||
492 | 25789 | jmvivo | |
493 | 31284 | cordinyana | writer.end(); |
494 | 25789 | jmvivo | |
495 | 31284 | cordinyana | close(); |
496 | resourceCloseRequest(); |
||
497 | 27875 | vcaballero | |
498 | 31284 | cordinyana | if (!shpParams.getDBFFile().delete()) {
|
499 | 33718 | jjdelcerro | throw new PerformEditingException(getProviderName(), |
500 | 31284 | cordinyana | new IOException(shpParams.getDBFFileName())); |
501 | } |
||
502 | if (!shpParams.getSHPFile().delete()) {
|
||
503 | 33718 | jjdelcerro | throw new PerformEditingException(getProviderName(), |
504 | 31284 | cordinyana | new IOException(shpParams.getSHPFileName())); |
505 | } |
||
506 | if (!shpParams.getSHXFile().delete()) {
|
||
507 | 33718 | jjdelcerro | throw new PerformEditingException(getProviderName(), |
508 | 31284 | cordinyana | new IOException(shpParams.getSHXFileName())); |
509 | } |
||
510 | if (!tmpParams.getDBFFile().renameTo(
|
||
511 | shpParams.getDBFFile())) { |
||
512 | 33718 | jjdelcerro | throw new PerformEditingException(getProviderName(), |
513 | 31284 | cordinyana | new IOException(shpParams.getSHPFileName())); |
514 | } |
||
515 | if (!tmpParams.getSHPFile().renameTo(
|
||
516 | shpParams.getSHPFile())) { |
||
517 | 33718 | jjdelcerro | throw new PerformEditingException(getProviderName(), |
518 | 31284 | cordinyana | new IOException(shpParams.getSHPFileName())); |
519 | } |
||
520 | if (!tmpParams.getSHXFile().renameTo(
|
||
521 | shpParams.getSHXFile())) { |
||
522 | 33718 | jjdelcerro | throw new PerformEditingException(getProviderName(), |
523 | 31284 | cordinyana | new IOException(shpParams.getSHXFileName())); |
524 | } |
||
525 | |||
526 | resourcesNotifyChanges(); |
||
527 | initFeatureType(); |
||
528 | return null; |
||
529 | } finally {
|
||
530 | dispose(set); |
||
531 | dispose(iter); |
||
532 | 31022 | cordinyana | } |
533 | } |
||
534 | }); |
||
535 | 26252 | jmvivo | |
536 | 24791 | jmvivo | } catch (Exception e) { |
537 | 33718 | jjdelcerro | throw new PerformEditingException(this.getProviderName(), e); |
538 | 31022 | cordinyana | // } finally {
|
539 | // this.resourcesEnd();
|
||
540 | 24791 | jmvivo | } |
541 | |||
542 | |||
543 | 24447 | jmvivo | } |
544 | |||
545 | 27875 | vcaballero | protected void resourceCloseRequest() throws ResourceException { |
546 | 31022 | cordinyana | // super.resourceCloseRequest();
|
547 | // this.shpResource.closeRequest();
|
||
548 | // this.shxResource.closeRequest();
|
||
549 | getResource().closeRequest(); |
||
550 | 27875 | vcaballero | } |
551 | |||
552 | 25164 | jmvivo | public Envelope getEnvelope() throws DataException { |
553 | this.open();
|
||
554 | 29326 | jmvivo | return (Envelope) this.getDynValue("Envelope"); |
555 | 25164 | jmvivo | } |
556 | |||
557 | 31022 | cordinyana | public void append(final FeatureProvider featureProvider) throws DataException { |
558 | // this.resourcesBegin();
|
||
559 | // try {
|
||
560 | 25955 | jmvivo | |
561 | 31022 | cordinyana | getResource().execute(new ResourceAction() {
|
562 | public Object run() throws Exception { |
||
563 | writer.append(getStoreServices().createFeature(featureProvider)); |
||
564 | return null; |
||
565 | } |
||
566 | }); |
||
567 | // } finally {
|
||
568 | // this.resourcesEnd();
|
||
569 | // }
|
||
570 | |||
571 | 24447 | jmvivo | } |
572 | |||
573 | 25955 | jmvivo | public void beginAppend() throws DataException { |
574 | 31022 | cordinyana | // this.resourcesBegin();
|
575 | // try {
|
||
576 | 25955 | jmvivo | |
577 | 31022 | cordinyana | getResource().execute(new ResourceAction() {
|
578 | public Object run() throws Exception { |
||
579 | FeatureStore store = getFeatureStore(); |
||
580 | FeatureType fType = store.getDefaultFeatureType(); |
||
581 | 25752 | vcaballero | |
582 | 31022 | cordinyana | // TODO Comprobar el campo de geometria
|
583 | 25752 | vcaballero | |
584 | 31022 | cordinyana | EditableFeatureType dbfFtype = fType.getEditable(); |
585 | 25752 | vcaballero | |
586 | 31022 | cordinyana | removeGeometryColumn(dbfFtype); |
587 | FeatureSet set = store.getFeatureSet(); |
||
588 | 25752 | vcaballero | |
589 | 33718 | jjdelcerro | writer = new SHPFeatureWriter(getProviderName());
|
590 | 25752 | vcaballero | |
591 | 31022 | cordinyana | writer.begin(getShpParameters(), fType, dbfFtype, set.getSize()); |
592 | return null; |
||
593 | } |
||
594 | }); |
||
595 | // } finally {
|
||
596 | // this.resourcesEnd();
|
||
597 | // }
|
||
598 | 25752 | vcaballero | |
599 | 24447 | jmvivo | } |
600 | |||
601 | 25955 | jmvivo | public void endAppend() throws DataException { |
602 | 31022 | cordinyana | // this.resourcesBegin();
|
603 | // try {
|
||
604 | getResource().execute(new ResourceAction() {
|
||
605 | public Object run() throws Exception { |
||
606 | writer.end(); |
||
607 | resourcesNotifyChanges(); |
||
608 | return null; |
||
609 | } |
||
610 | }); |
||
611 | // } finally {
|
||
612 | // this.resourcesEnd();
|
||
613 | // }
|
||
614 | 25955 | jmvivo | |
615 | 24447 | jmvivo | } |
616 | 25789 | jmvivo | |
617 | 26837 | jmvivo | public Object getSourceId() { |
618 | return this.getShpParameters().getFile(); |
||
619 | } |
||
620 | 31022 | cordinyana | } |