root / branches / v2_0_0_prep / libraries / libFMap_dalfile / src-test / org / gvsig / fmap / dal / store / shp / TestSHP.java @ 30580
History | View | Annotate | Download (9.52 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 | import java.io.File; |
||
31 | import java.util.Iterator; |
||
32 | |||
33 | 26040 | jmvivo | import org.gvsig.fmap.dal.DataStoreParameters; |
34 | 24502 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
35 | 26047 | jmvivo | import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore; |
36 | 27525 | jmvivo | import org.gvsig.fmap.dal.feature.DisposableIterator; |
37 | 25752 | vcaballero | import org.gvsig.fmap.dal.feature.EditableFeature; |
38 | 24498 | jmvivo | import org.gvsig.fmap.dal.feature.Feature; |
39 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
40 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
41 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
42 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
43 | 25752 | vcaballero | import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
44 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
||
45 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
||
46 | import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters; |
||
47 | import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider; |
||
48 | 30580 | cordinyana | import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
49 | 24447 | jmvivo | |
50 | 26047 | jmvivo | public class TestSHP extends BaseTestEditableFeatureStore { |
51 | 24447 | jmvivo | |
52 | 26040 | jmvivo | protected boolean testSHPInitialized = false; |
53 | |||
54 | |||
55 | 26047 | jmvivo | private FilesystemServerExplorer myExplorer;
|
56 | |||
57 | |||
58 | 24447 | jmvivo | public static final File file_prueba = new File(TestSHP.class.getResource( |
59 | "data/prueba.shp").getFile());
|
||
60 | 26047 | jmvivo | public static final File file_prueba_destino = new File(file_prueba |
61 | 26057 | jmvivo | .getParent() |
62 | 28777 | vcaballero | + File.separatorChar + "pruebaTemp.shp"); |
63 | 24447 | jmvivo | public static final File file_pruebaNull = new File(TestSHP.class |
64 | .getResource("data/pruebaNull.shp").getFile());
|
||
65 | |||
66 | public static final File file_poly_valencia = new File(TestSHP.class |
||
67 | .getResource("data/poly-valencia.shp").getFile());
|
||
68 | |||
69 | |||
70 | protected void setUp() throws Exception { |
||
71 | super.setUp();
|
||
72 | |||
73 | 26040 | jmvivo | if (testSHPInitialized) {
|
74 | return;
|
||
75 | } |
||
76 | 30580 | cordinyana | |
77 | new DefaultLibrariesInitializer().fullInitialize();
|
||
78 | 26040 | jmvivo | |
79 | 30580 | cordinyana | // DALFileLibrary libFile = new DALFileLibrary();
|
80 | // libFile.initialize();
|
||
81 | //
|
||
82 | // DefaultGeometryLibrary defGeomLib = new DefaultGeometryLibrary();
|
||
83 | // defGeomLib.initialize();
|
||
84 | //
|
||
85 | // ProjectionLibrary projLib = new ProjectionLibrary();
|
||
86 | // projLib.initialize();
|
||
87 | //
|
||
88 | // CresquesCtsLibrary cresquesLib = new CresquesCtsLibrary();
|
||
89 | // cresquesLib.initialize();
|
||
90 | //
|
||
91 | // SHPLibrary shpLib = new SHPLibrary();
|
||
92 | // shpLib.initialize();
|
||
93 | //
|
||
94 | //
|
||
95 | // JTSIndexLibrary jtsIndex = new JTSIndexLibrary();
|
||
96 | // jtsIndex.initialize();
|
||
97 | //
|
||
98 | // defGeomLib.postInitialize();
|
||
99 | // projLib.postInitialize();
|
||
100 | // cresquesLib.postInitialize();
|
||
101 | // libFile.postInitialize();
|
||
102 | // shpLib.postInitialize();
|
||
103 | // jtsIndex.postInitialize();
|
||
104 | 24447 | jmvivo | |
105 | 26040 | jmvivo | testSHPInitialized = true;
|
106 | 26061 | jmvivo | |
107 | |||
108 | 24447 | jmvivo | } |
109 | |||
110 | 27723 | jmvivo | public void testSimpleIteration() throws Exception { |
111 | 25789 | jmvivo | |
112 | 24447 | jmvivo | FeatureStore store = null;
|
113 | SHPStoreParameters shpParameters = null;
|
||
114 | |||
115 | 27723 | jmvivo | shpParameters = (SHPStoreParameters) dataManager |
116 | .createStoreParameters(SHPStoreProvider.NAME); |
||
117 | 24447 | jmvivo | |
118 | 27723 | jmvivo | // shpParameters.setFile(file_poly_valencia);
|
119 | shpParameters.setFile(file_prueba); |
||
120 | 24447 | jmvivo | |
121 | 27749 | jmvivo | shpParameters.setSRSID("EPSG:23030");
|
122 | |||
123 | 27723 | jmvivo | store = (FeatureStore) dataManager.createStore(shpParameters); |
124 | FeatureSet set; |
||
125 | FeatureType type = store.getDefaultFeatureType(); |
||
126 | set = store.getFeatureSet(); |
||
127 | 24447 | jmvivo | |
128 | 27723 | jmvivo | System.out.println("Num:" + set.getSize()); |
129 | DisposableIterator it = set.iterator(); |
||
130 | Iterator ftIt;
|
||
131 | FeatureAttributeDescriptor desc; |
||
132 | 24447 | jmvivo | |
133 | 27723 | jmvivo | int i = 0; |
134 | Feature feature; |
||
135 | while (it.hasNext()) {
|
||
136 | ftIt = type.iterator(); |
||
137 | 24447 | jmvivo | |
138 | 27723 | jmvivo | feature = (Feature) it.next(); |
139 | // while (ftIt.hasNext()) {
|
||
140 | // desc = (FeatureAttributeDescriptor) ftIt.next();
|
||
141 | // System.out.println(desc.getName() + ":"
|
||
142 | // + feature.get(desc.getIndex()));
|
||
143 | //
|
||
144 | // }
|
||
145 | // System.out.println(feature.get("NOMBRE"));
|
||
146 | System.out.print(feature.getDefaultEnvelope() + "\t"); |
||
147 | // System.out.print(feature.getDefaultGeometry() + "\t");
|
||
148 | // System.out.println(feature.get("NOMBRE"));
|
||
149 | System.out.println("row:" + i); |
||
150 | i++; |
||
151 | 24447 | jmvivo | |
152 | |||
153 | } |
||
154 | |||
155 | 27723 | jmvivo | it.dispose(); |
156 | set.dispose(); |
||
157 | 24447 | jmvivo | |
158 | 27723 | jmvivo | store.dispose(); |
159 | |||
160 | 24447 | jmvivo | } |
161 | 27723 | jmvivo | |
162 | public void testEditing(Object x) throws Exception { |
||
163 | 25752 | vcaballero | FeatureStore store = null;
|
164 | SHPStoreParameters shpParameters = null;
|
||
165 | 24447 | jmvivo | |
166 | 27723 | jmvivo | shpParameters = (SHPStoreParameters) dataManager |
167 | .createStoreParameters(SHPStoreProvider.NAME); |
||
168 | 25752 | vcaballero | |
169 | 27723 | jmvivo | shpParameters.setFile(file_poly_valencia); |
170 | 25752 | vcaballero | |
171 | 27723 | jmvivo | store = (FeatureStore) dataManager.createStore(shpParameters); |
172 | FeatureSet set; |
||
173 | FeatureType type = store.getDefaultFeatureType(); |
||
174 | System.err.println("Antes de la edici?n"); |
||
175 | set = store.getFeatureSet(); |
||
176 | System.out.println("Num:" + set.getSize()); |
||
177 | DisposableIterator it = set.iterator(); |
||
178 | Iterator ftIt;
|
||
179 | FeatureAttributeDescriptor desc; |
||
180 | 25752 | vcaballero | |
181 | 27723 | jmvivo | int i = 0; |
182 | Feature feature; |
||
183 | while (it.hasNext()) {
|
||
184 | ftIt = type.iterator(); |
||
185 | 25752 | vcaballero | |
186 | 27723 | jmvivo | feature = (Feature) it.next(); |
187 | // while (ftIt.hasNext()) {
|
||
188 | // desc = (FeatureAttributeDescriptor) ftIt.next();
|
||
189 | // System.out.println(desc.getName() + ":"
|
||
190 | // + feature.get(desc.getIndex()));
|
||
191 | //
|
||
192 | // }
|
||
193 | // System.out.println(feature.get("NOMBRE"));
|
||
194 | System.out.print(feature.getDefaultEnvelope() + "\t"); |
||
195 | // System.out.print(feature.getDefaultGeometry() + "\t");
|
||
196 | // System.out.println(feature.get("NOMBRE"));
|
||
197 | System.out.println("row:" + i); |
||
198 | i++; |
||
199 | 25752 | vcaballero | |
200 | |||
201 | 27723 | jmvivo | } |
202 | 25752 | vcaballero | |
203 | 27723 | jmvivo | it.dispose(); |
204 | set.dispose(); |
||
205 | store.edit(); |
||
206 | EditableFeature ef = store.createNewFeature(); |
||
207 | store.insert(ef); |
||
208 | store.finishEditing(); |
||
209 | System.err.println("Despu?s de la edici?n"); |
||
210 | set = store.getFeatureSet(); |
||
211 | System.out.println("Num:" + set.getSize()); |
||
212 | it = set.iterator(); |
||
213 | 25752 | vcaballero | |
214 | 27723 | jmvivo | i = 0;
|
215 | while (it.hasNext()) {
|
||
216 | ftIt = type.iterator(); |
||
217 | 25752 | vcaballero | |
218 | 27723 | jmvivo | feature = (Feature) it.next(); |
219 | // while (ftIt.hasNext()) {
|
||
220 | // desc = (FeatureAttributeDescriptor) ftIt.next();
|
||
221 | // System.out.println(desc.getName() + ":"
|
||
222 | // + feature.get(desc.getIndex()));
|
||
223 | //
|
||
224 | // }
|
||
225 | // System.out.println(feature.get("NOMBRE"));
|
||
226 | System.out.print(feature.getDefaultEnvelope() + "\t"); |
||
227 | // System.out.print(feature.getDefaultGeometry() + "\t");
|
||
228 | // System.out.println(feature.get("NOMBRE"));
|
||
229 | System.out.println("row:" + i); |
||
230 | i++; |
||
231 | 25752 | vcaballero | |
232 | |||
233 | 27723 | jmvivo | } |
234 | 25752 | vcaballero | |
235 | 27723 | jmvivo | it.dispose(); |
236 | set.dispose(); |
||
237 | 25752 | vcaballero | |
238 | 27723 | jmvivo | store.dispose(); |
239 | 25752 | vcaballero | |
240 | } |
||
241 | 26040 | jmvivo | |
242 | 27723 | jmvivo | public void testExport(Object x) throws Exception { |
243 | 25752 | vcaballero | DBFStoreParameters dbfParameters = null;
|
244 | |||
245 | 27723 | jmvivo | dbfParameters = (DBFStoreParameters) dataManager |
246 | .createStoreParameters(DBFStoreProvider.NAME); |
||
247 | 25752 | vcaballero | |
248 | 27723 | jmvivo | dbfParameters.setFile(file_prueba); |
249 | 25752 | vcaballero | |
250 | 27723 | jmvivo | FeatureStore store = (FeatureStore) dataManager |
251 | .createStore(dbfParameters); |
||
252 | FilesystemServerExplorerParameters explorerParams = (FilesystemServerExplorerParameters) dataManager |
||
253 | .createServerExplorerParameters(FilesystemServerExplorerParameters.DYNCLASS_NAME); |
||
254 | explorerParams.setRoot(file_prueba.getParent()); |
||
255 | 25752 | vcaballero | |
256 | 27723 | jmvivo | FilesystemServerExplorer explorer = (FilesystemServerExplorer) dataManager |
257 | .createServerExplorer(explorerParams); |
||
258 | 25752 | vcaballero | |
259 | 27723 | jmvivo | NewFeatureStoreParameters newParams = (NewFeatureStoreParameters) explorer |
260 | .getAddParameters(file_prueba_destino); |
||
261 | 25752 | vcaballero | |
262 | 27723 | jmvivo | store.export(explorer, newParams); |
263 | 25752 | vcaballero | |
264 | 27723 | jmvivo | FeatureStore result = (FeatureStore) dataManager.createStore(newParams); |
265 | 25752 | vcaballero | |
266 | 27723 | jmvivo | FeatureSet set = result.getFeatureSet(); |
267 | FeatureSet originalSet = store.getFeatureSet(); |
||
268 | assertEquals(set.getSize(), originalSet.getSize()); |
||
269 | 25752 | vcaballero | |
270 | 27723 | jmvivo | DisposableIterator originalIter = originalSet.iterator(); |
271 | DisposableIterator iter = set.iterator(); |
||
272 | while (iter.hasNext()) {
|
||
273 | assertEquals(originalIter.next(), iter.next()); |
||
274 | 25752 | vcaballero | } |
275 | |||
276 | 27723 | jmvivo | originalIter.dispose(); |
277 | iter.dispose(); |
||
278 | result.dispose(); |
||
279 | explorer.remove(newParams); |
||
280 | |||
281 | 25752 | vcaballero | } |
282 | |||
283 | 26040 | jmvivo | /*
|
284 | * (non-Javadoc)
|
||
285 | 26359 | jmvivo | *
|
286 | 26040 | jmvivo | * @see
|
287 | * org.gvsig.fmap.dal.feature.BaseTestFeatureStore#getDefaultDataStoreParameters
|
||
288 | * ()
|
||
289 | */
|
||
290 | public DataStoreParameters getDefaultDataStoreParameters()
|
||
291 | throws DataException {
|
||
292 | SHPStoreParameters shpParameters = (SHPStoreParameters) dataManager |
||
293 | .createStoreParameters(SHPStoreProvider.NAME); |
||
294 | |||
295 | // shpParameters.setFile(file_poly_valencia);
|
||
296 | shpParameters.setFile(file_prueba); |
||
297 | 27749 | jmvivo | shpParameters.setSRSID("EPSG:23030");
|
298 | 26040 | jmvivo | return shpParameters;
|
299 | } |
||
300 | |||
301 | /*
|
||
302 | * (non-Javadoc)
|
||
303 | 26359 | jmvivo | *
|
304 | 26040 | jmvivo | * @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer()
|
305 | */
|
||
306 | public boolean hasExplorer() { |
||
307 | return true; |
||
308 | } |
||
309 | |||
310 | 26047 | jmvivo | /*
|
311 | * (non-Javadoc)
|
||
312 | 26359 | jmvivo | *
|
313 | 26047 | jmvivo | * @seeorg.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore#
|
314 | * getDefaultNewDataStoreParameters()
|
||
315 | */
|
||
316 | public NewFeatureStoreParameters getDefaultNewDataStoreParameters()
|
||
317 | 27723 | jmvivo | throws Exception { |
318 | 27749 | jmvivo | SHPStoreParameters parameters = (SHPStoreParameters) this
|
319 | .getDefaultDataStoreParameters(); |
||
320 | |||
321 | 26047 | jmvivo | if (this.myExplorer == null) { |
322 | FeatureStore store = (FeatureStore) dataManager |
||
323 | .createStore(parameters); |
||
324 | myExplorer = (FilesystemServerExplorer) store.getExplorer(); |
||
325 | store.dispose(); |
||
326 | } |
||
327 | |||
328 | 27749 | jmvivo | SHPNewStoreParameters result = (SHPNewStoreParameters) myExplorer |
329 | 26047 | jmvivo | .getAddParameters(file_prueba_destino); |
330 | 27749 | jmvivo | |
331 | result.setSRS(parameters.getSRS()); |
||
332 | return result;
|
||
333 | 26047 | jmvivo | } |
334 | |||
335 | 26209 | jmvivo | public boolean usesResources() { |
336 | return true; |
||
337 | } |
||
338 | |||
339 | 28663 | jmvivo | public boolean resourcesNotifyChanges() { |
340 | return true; |
||
341 | } |
||
342 | |||
343 | 24447 | jmvivo | } |