svn-gvsig-desktop / trunk / libraries / libDataSourceBaseDrivers / src-test / org / gvsig / data / datastores / vectorial / file / DataStoreTest.java @ 20607
History | View | Annotate | Download (30.1 KB)
1 |
package org.gvsig.data.datastores.vectorial.file; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.Iterator; |
5 |
|
6 |
import junit.framework.TestCase; |
7 |
|
8 |
import org.cresques.cts.IProjection; |
9 |
import org.gvsig.data.DataManager; |
10 |
import org.gvsig.data.IDataStoreParameters; |
11 |
import org.gvsig.data.commands.ICommandsRecord; |
12 |
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStore; |
13 |
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStoreParameters; |
14 |
import org.gvsig.data.datastores.vectorial.file.dgn.DGNStore; |
15 |
import org.gvsig.data.datastores.vectorial.file.dgn.DGNStoreParameters; |
16 |
import org.gvsig.data.datastores.vectorial.file.dxf.DXFStore; |
17 |
import org.gvsig.data.datastores.vectorial.file.dxf.DXFStoreParameters; |
18 |
import org.gvsig.data.datastores.vectorial.file.shp.SHPStore; |
19 |
import org.gvsig.data.datastores.vectorial.file.shp.SHPStoreParameters; |
20 |
import org.gvsig.data.datastores.vectorial.file.shp.utils.SHP; |
21 |
import org.gvsig.data.exception.CloseException; |
22 |
import org.gvsig.data.exception.DataException; |
23 |
import org.gvsig.data.exception.InitializeException; |
24 |
import org.gvsig.data.exception.OpenException; |
25 |
import org.gvsig.data.exception.ReadException; |
26 |
import org.gvsig.data.exception.WriteException; |
27 |
import org.gvsig.data.vectorial.AttributeDescriptor; |
28 |
import org.gvsig.data.vectorial.FeatureType; |
29 |
import org.gvsig.data.vectorial.IFeature; |
30 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
31 |
import org.gvsig.data.vectorial.IFeatureCollection; |
32 |
import org.gvsig.data.vectorial.IFeatureStore; |
33 |
import org.gvsig.data.vectorial.IFeatureType; |
34 |
import org.gvsig.data.vectorial.IsNotAttributeSettingException; |
35 |
import org.gvsig.data.vectorial.IsNotFeatureSettingException; |
36 |
import org.gvsig.data.vectorial.visitor.PrintlnFeaturesVisitor; |
37 |
import org.gvsig.exceptions.BaseException; |
38 |
|
39 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
40 |
|
41 |
public class DataStoreTest extends TestCase { |
42 |
|
43 |
private File dbffile = new File(DataStoreTest.class.getResource("data/prueba.dbf").getFile()); |
44 |
private File shpfile = new File(DataStoreTest.class.getResource("data/prueba.shp").getFile()); |
45 |
private File dxffile = new File(DataStoreTest.class.getResource("data/prueba.dxf").getFile()); |
46 |
private File dgnfile = new File(DataStoreTest.class.getResource("data/cv_300_todo.dgn").getFile()); |
47 |
|
48 |
public static void main(String[] args) { |
49 |
junit.textui.TestRunner.run(DataStoreTest.class); |
50 |
} |
51 |
|
52 |
protected void setUp() throws Exception { |
53 |
super.setUp();
|
54 |
|
55 |
} |
56 |
|
57 |
public void testDBF() { |
58 |
try {
|
59 |
System.out.println("======= DBF =============="); |
60 |
org.gvsig.data.datastores.vectorial.file.dbf.Register.selfRegister(); |
61 |
|
62 |
DataManager dsm=DataManager.getManager(); |
63 |
|
64 |
|
65 |
IDataStoreParameters dp=dsm.createDataStoreParameters(DBFStore.DATASTORE_NAME); |
66 |
((DBFStoreParameters)dp).setFile(dbffile); |
67 |
|
68 |
driverTest(dp,null,null,true); |
69 |
IFeatureStore fs=null;
|
70 |
try {
|
71 |
fs = (IFeatureStore)dsm.createDataStore(dp); |
72 |
} catch (InitializeException e) {
|
73 |
e.printStackTrace(); |
74 |
fail("Exception:" + e);
|
75 |
} |
76 |
assertNotNull("Can't create Feature Store", fs);
|
77 |
|
78 |
|
79 |
fs.open(); |
80 |
|
81 |
|
82 |
Iterator it;
|
83 |
IFeatureCollection fc; |
84 |
Comparable v1,v2;
|
85 |
IFeature feature,pfeature; |
86 |
long count;
|
87 |
|
88 |
|
89 |
fc = (IFeatureCollection)fs.getDataCollection(); |
90 |
|
91 |
assertEquals(9, fc.size());
|
92 |
|
93 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null); |
94 |
|
95 |
assertEquals(2, fc.size());
|
96 |
|
97 |
it = fc.iterator(); |
98 |
count=0;
|
99 |
while (it.hasNext()){
|
100 |
feature = (IFeature)it.next(); |
101 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
102 |
count++; |
103 |
} |
104 |
assertEquals("Iteration error",2,count); |
105 |
|
106 |
|
107 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC"); |
108 |
assertEquals(9, fc.size());
|
109 |
it = fc.iterator(); |
110 |
count=0;
|
111 |
pfeature = (IFeature)it.next(); |
112 |
count++; |
113 |
while (it.hasNext()){
|
114 |
feature = (IFeature)it.next(); |
115 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
116 |
v2 = (Comparable)feature.get("NOMBRE"); |
117 |
pfeature=feature; |
118 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
119 |
count++; |
120 |
} |
121 |
assertEquals("Iteration error",9,count); |
122 |
|
123 |
|
124 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
125 |
assertEquals(9, fc.size());
|
126 |
it = fc.iterator(); |
127 |
|
128 |
count=0;
|
129 |
pfeature = (IFeature)it.next(); |
130 |
count++; |
131 |
while (it.hasNext()){
|
132 |
feature = (IFeature)it.next(); |
133 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
134 |
v2 = (Comparable)feature.get("NOMBRE"); |
135 |
pfeature=feature; |
136 |
assertTrue("Short error", (v1.compareTo(v1) >= 0)); |
137 |
count++; |
138 |
} |
139 |
assertEquals("Iteration error",9,count); |
140 |
|
141 |
|
142 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE"); |
143 |
|
144 |
assertEquals(2, fc.size());
|
145 |
|
146 |
it = fc.iterator(); |
147 |
|
148 |
count=0;
|
149 |
pfeature = (IFeature)it.next(); |
150 |
assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b")); |
151 |
count++; |
152 |
while (it.hasNext()){
|
153 |
feature = (IFeature)it.next(); |
154 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
155 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
156 |
v2 = (Comparable)feature.get("NOMBRE"); |
157 |
pfeature=feature; |
158 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
159 |
count++; |
160 |
} |
161 |
assertEquals("Iteration error",2,count); |
162 |
|
163 |
|
164 |
|
165 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
166 |
assertEquals(9, fc.size());
|
167 |
it = fc.iterator(); |
168 |
count=0;
|
169 |
pfeature = (IFeature)it.next(); |
170 |
System.out.println(pfeature.getString("NOMBRE")); |
171 |
count++; |
172 |
while (it.hasNext()){
|
173 |
feature = (IFeature)it.next(); |
174 |
v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
175 |
v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
176 |
pfeature=feature; |
177 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
178 |
System.out.println(pfeature.getString("NOMBRE")); |
179 |
count++; |
180 |
} |
181 |
assertEquals("Iteration error",9,count); |
182 |
|
183 |
|
184 |
/// CON EDICION
|
185 |
|
186 |
fs.startEditing(); |
187 |
|
188 |
IFeature newFeature = fs.createFeature(fs.getDefaultFeatureType()); |
189 |
newFeature.editing(); |
190 |
newFeature.set("NOMBRE","BuRjaSOT"); |
191 |
newFeature.set("TIPO","MUNICIPIO"); |
192 |
fs.insert(newFeature); |
193 |
|
194 |
try {
|
195 |
fc = (IFeatureCollection)fs.getDataCollection(); |
196 |
} catch (ReadException e1) {
|
197 |
e1.printStackTrace(); |
198 |
fail(); |
199 |
} |
200 |
|
201 |
assertEquals(10, fc.size());
|
202 |
|
203 |
try {
|
204 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null); |
205 |
} catch (ReadException e1) {
|
206 |
e1.printStackTrace(); |
207 |
fail(); |
208 |
} |
209 |
|
210 |
assertEquals(3, fc.size());
|
211 |
|
212 |
it = fc.iterator(); |
213 |
count=0;
|
214 |
while (it.hasNext()){
|
215 |
feature = (IFeature)it.next(); |
216 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
217 |
count++; |
218 |
} |
219 |
assertEquals("Iteration error",3,count); |
220 |
|
221 |
|
222 |
try {
|
223 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC"); |
224 |
} catch (ReadException e1) {
|
225 |
e1.printStackTrace(); |
226 |
fail(); |
227 |
} |
228 |
assertEquals(10, fc.size());
|
229 |
it = fc.iterator(); |
230 |
count=0;
|
231 |
pfeature = (IFeature)it.next(); |
232 |
count++; |
233 |
while (it.hasNext()){
|
234 |
feature = (IFeature)it.next(); |
235 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
236 |
v2 = (Comparable)feature.get("NOMBRE"); |
237 |
pfeature=feature; |
238 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
239 |
count++; |
240 |
} |
241 |
assertEquals("Iteration error",10,count); |
242 |
|
243 |
|
244 |
try {
|
245 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
246 |
} catch (ReadException e1) {
|
247 |
e1.printStackTrace(); |
248 |
fail(); |
249 |
} |
250 |
assertEquals(10, fc.size());
|
251 |
it = fc.iterator(); |
252 |
|
253 |
count=0;
|
254 |
pfeature = (IFeature)it.next(); |
255 |
count++; |
256 |
while (it.hasNext()){
|
257 |
feature = (IFeature)it.next(); |
258 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
259 |
v2 = (Comparable)feature.get("NOMBRE"); |
260 |
pfeature=feature; |
261 |
if (v1!=null && v2!=null) |
262 |
assertTrue("Short error", (v1.compareTo(v1) >= 0)); |
263 |
count++; |
264 |
} |
265 |
assertEquals("Iteration error",10,count); |
266 |
|
267 |
|
268 |
try {
|
269 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE"); |
270 |
} catch (ReadException e1) {
|
271 |
e1.printStackTrace(); |
272 |
fail(); |
273 |
} |
274 |
|
275 |
assertEquals(3, fc.size());
|
276 |
|
277 |
it = fc.iterator(); |
278 |
|
279 |
count=0;
|
280 |
pfeature = (IFeature)it.next(); |
281 |
assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b")); |
282 |
count++; |
283 |
while (it.hasNext()){
|
284 |
feature = (IFeature)it.next(); |
285 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
286 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
287 |
v2 = (Comparable)feature.get("NOMBRE"); |
288 |
pfeature=feature; |
289 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
290 |
count++; |
291 |
} |
292 |
assertEquals("Iteration error",3,count); |
293 |
|
294 |
|
295 |
|
296 |
try {
|
297 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
298 |
} catch (ReadException e1) {
|
299 |
e1.printStackTrace(); |
300 |
fail(); |
301 |
} |
302 |
assertEquals(10, fc.size());
|
303 |
it = fc.iterator(); |
304 |
count=0;
|
305 |
pfeature = (IFeature)it.next(); |
306 |
System.out.println(pfeature.getString("TIPO")+","+pfeature.getString("NOMBRE")); |
307 |
count++; |
308 |
while (it.hasNext()){
|
309 |
feature = (IFeature)it.next(); |
310 |
System.out.println(feature.getString("TIPO")+","+feature.getString("NOMBRE")); |
311 |
v1 = (Comparable)((String)pfeature.get("TIPO")).toLowerCase(); |
312 |
v2 = (Comparable)((String)feature.get("TIPO")).toLowerCase(); |
313 |
assertTrue("Short error", (v2.compareTo(v1) >= 0)); |
314 |
if (v1.compareTo(v2) == 0){ |
315 |
v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
316 |
v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
317 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
318 |
} |
319 |
pfeature=feature; |
320 |
|
321 |
// System.out.println(pfeature.getString("TIPO")+","+pfeature.getString("NOMBRE"));
|
322 |
count++; |
323 |
} |
324 |
assertEquals("Iteration error",10,count); |
325 |
|
326 |
fs.cancelEditing(); |
327 |
|
328 |
try {
|
329 |
fs.close(); |
330 |
} catch (CloseException e) {
|
331 |
e.printStackTrace(); |
332 |
fail("Exception:" + e);
|
333 |
} |
334 |
|
335 |
|
336 |
System.out.println("======= /DBF =============="); |
337 |
|
338 |
} catch (DataException e) {
|
339 |
// TODO Auto-generated catch block
|
340 |
e.printStackTrace(); |
341 |
} |
342 |
} |
343 |
|
344 |
public void testSHP() { |
345 |
try {
|
346 |
System.out.println("======= SHP =============="); |
347 |
org.gvsig.data.datastores.vectorial.file.shp.Register.selfRegister(); |
348 |
org.gvsig.data.datastores.vectorial.file.dbf.Register.selfRegister(); |
349 |
|
350 |
DataManager dsm=DataManager.getManager(); |
351 |
|
352 |
|
353 |
IDataStoreParameters dp=dsm.createDataStoreParameters(SHPStore.DATASTORE_NAME); |
354 |
((SHPStoreParameters)dp).setFile(shpfile); |
355 |
// ((SHPStoreParameters)dp).setSHXFile(SHP.getShxFile(shpfile));
|
356 |
// ((SHPStoreParameters)dp).setDBFFile(SHP.getDbfFile(shpfile));
|
357 |
|
358 |
|
359 |
driverTest(dp,null,null,true); |
360 |
|
361 |
IFeatureStore fs=null;
|
362 |
try {
|
363 |
fs = (IFeatureStore)dsm.createDataStore(dp); |
364 |
} catch (InitializeException e) {
|
365 |
e.printStackTrace(); |
366 |
fail("Exception:" + e);
|
367 |
} |
368 |
|
369 |
assertNotNull("Can't create Feature Store", fs);
|
370 |
|
371 |
|
372 |
fs.open(); |
373 |
|
374 |
|
375 |
Iterator it;
|
376 |
IFeatureCollection fc; |
377 |
Comparable v1,v2;
|
378 |
IFeature feature,pfeature; |
379 |
long count;
|
380 |
|
381 |
|
382 |
fc = (IFeatureCollection)fs.getDataCollection(); |
383 |
|
384 |
assertEquals(9, fc.size());
|
385 |
|
386 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null); |
387 |
|
388 |
assertEquals(2, fc.size());
|
389 |
|
390 |
it = fc.iterator(); |
391 |
count=0;
|
392 |
while (it.hasNext()){
|
393 |
feature = (IFeature)it.next(); |
394 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
395 |
count++; |
396 |
} |
397 |
assertEquals("Iteration error",2,count); |
398 |
|
399 |
|
400 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE"); |
401 |
assertEquals(9, fc.size());
|
402 |
it = fc.iterator(); |
403 |
count=0;
|
404 |
pfeature = (IFeature)it.next(); |
405 |
count++; |
406 |
while (it.hasNext()){
|
407 |
feature = (IFeature)it.next(); |
408 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
409 |
v2 = (Comparable)feature.get("NOMBRE"); |
410 |
pfeature=feature; |
411 |
assertTrue("Short error", (v1.compareTo(v2) <= 0)); |
412 |
count++; |
413 |
} |
414 |
assertEquals("Iteration error",9,count); |
415 |
|
416 |
|
417 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
418 |
assertEquals(9, fc.size());
|
419 |
it = fc.iterator(); |
420 |
count=0;
|
421 |
pfeature = (IFeature)it.next(); |
422 |
System.out.println(pfeature.getString("NOMBRE")); |
423 |
count++; |
424 |
while (it.hasNext()){
|
425 |
feature = (IFeature)it.next(); |
426 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
427 |
v2 = (Comparable)feature.get("NOMBRE"); |
428 |
pfeature=feature; |
429 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
430 |
System.out.println(pfeature.getString("NOMBRE")); |
431 |
count++; |
432 |
} |
433 |
assertEquals("Iteration error",9,count); |
434 |
|
435 |
|
436 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE ASC"); |
437 |
|
438 |
assertEquals(2, fc.size());
|
439 |
|
440 |
it = fc.iterator(); |
441 |
|
442 |
count=0;
|
443 |
pfeature = (IFeature)it.next(); |
444 |
assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b")); |
445 |
count++; |
446 |
while (it.hasNext()){
|
447 |
feature = (IFeature)it.next(); |
448 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
449 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
450 |
v2 = (Comparable)feature.get("NOMBRE"); |
451 |
pfeature=feature; |
452 |
assertTrue("Short error", (v1.compareTo(v2) <= 0)); |
453 |
count++; |
454 |
} |
455 |
assertEquals("Iteration error",2,count); |
456 |
|
457 |
|
458 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"lower(NOMBRE) ASC"); |
459 |
assertEquals(9, fc.size());
|
460 |
it = fc.iterator(); |
461 |
count=0;
|
462 |
pfeature = (IFeature)it.next(); |
463 |
count++; |
464 |
while (it.hasNext()){
|
465 |
feature = (IFeature)it.next(); |
466 |
v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
467 |
v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
468 |
pfeature=feature; |
469 |
assertTrue("Short error", (v1.compareTo(v2) <= 0)); |
470 |
count++; |
471 |
} |
472 |
assertEquals("Iteration error",9,count); |
473 |
|
474 |
|
475 |
|
476 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
477 |
assertEquals(9, fc.size());
|
478 |
it = fc.iterator(); |
479 |
count=0;
|
480 |
pfeature = (IFeature)it.next(); |
481 |
System.out.println(pfeature.getString("NOMBRE")); |
482 |
count++; |
483 |
while (it.hasNext()){
|
484 |
feature = (IFeature)it.next(); |
485 |
v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
486 |
v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
487 |
pfeature=feature; |
488 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
489 |
System.out.println(pfeature.getString("NOMBRE")); |
490 |
count++; |
491 |
} |
492 |
assertEquals("Iteration error",9,count); |
493 |
|
494 |
|
495 |
|
496 |
/// CON EDICION
|
497 |
|
498 |
fs.startEditing(); |
499 |
|
500 |
IFeature newFeature = fs.createFeature(fs.getDefaultFeatureType()); |
501 |
newFeature.editing(); |
502 |
newFeature.set("NOMBRE","BuRjaSOT"); |
503 |
newFeature.set("TIPO","MUNICIPIO"); |
504 |
fs.insert(newFeature); |
505 |
|
506 |
|
507 |
|
508 |
try {
|
509 |
fc = (IFeatureCollection)fs.getDataCollection(); |
510 |
} catch (ReadException e1) {
|
511 |
e1.printStackTrace(); |
512 |
fail(); |
513 |
} |
514 |
|
515 |
assertEquals(10, fc.size());
|
516 |
|
517 |
try {
|
518 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null); |
519 |
} catch (ReadException e1) {
|
520 |
e1.printStackTrace(); |
521 |
fail(); |
522 |
} |
523 |
|
524 |
assertEquals(3, fc.size());
|
525 |
|
526 |
it = fc.iterator(); |
527 |
count=0;
|
528 |
while (it.hasNext()){
|
529 |
feature = (IFeature)it.next(); |
530 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
531 |
count++; |
532 |
} |
533 |
assertEquals("Iteration error",3,count); |
534 |
|
535 |
|
536 |
try {
|
537 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC"); |
538 |
} catch (ReadException e1) {
|
539 |
e1.printStackTrace(); |
540 |
fail(); |
541 |
} |
542 |
assertEquals(10, fc.size());
|
543 |
it = fc.iterator(); |
544 |
count=0;
|
545 |
pfeature = (IFeature)it.next(); |
546 |
count++; |
547 |
while (it.hasNext()){
|
548 |
feature = (IFeature)it.next(); |
549 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
550 |
v2 = (Comparable)feature.get("NOMBRE"); |
551 |
pfeature=feature; |
552 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
553 |
count++; |
554 |
} |
555 |
assertEquals("Iteration error",10,count); |
556 |
|
557 |
|
558 |
try {
|
559 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
560 |
} catch (ReadException e1) {
|
561 |
e1.printStackTrace(); |
562 |
fail(); |
563 |
} |
564 |
assertEquals(10, fc.size());
|
565 |
it = fc.iterator(); |
566 |
|
567 |
count=0;
|
568 |
pfeature = (IFeature)it.next(); |
569 |
count++; |
570 |
while (it.hasNext()){
|
571 |
feature = (IFeature)it.next(); |
572 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
573 |
v2 = (Comparable)feature.get("NOMBRE"); |
574 |
pfeature=feature; |
575 |
assertTrue("Short error", (v1.compareTo(v1) >= 0)); |
576 |
count++; |
577 |
} |
578 |
assertEquals("Iteration error",10,count); |
579 |
|
580 |
|
581 |
try {
|
582 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE"); |
583 |
} catch (ReadException e1) {
|
584 |
e1.printStackTrace(); |
585 |
fail(); |
586 |
} |
587 |
|
588 |
assertEquals(3, fc.size());
|
589 |
|
590 |
it = fc.iterator(); |
591 |
|
592 |
count=0;
|
593 |
pfeature = (IFeature)it.next(); |
594 |
assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b")); |
595 |
count++; |
596 |
while (it.hasNext()){
|
597 |
feature = (IFeature)it.next(); |
598 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
599 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
600 |
v2 = (Comparable)feature.get("NOMBRE"); |
601 |
pfeature=feature; |
602 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
603 |
count++; |
604 |
} |
605 |
assertEquals("Iteration error",3,count); |
606 |
|
607 |
|
608 |
|
609 |
try {
|
610 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
611 |
} catch (ReadException e1) {
|
612 |
e1.printStackTrace(); |
613 |
fail(); |
614 |
} |
615 |
assertEquals(10, fc.size());
|
616 |
it = fc.iterator(); |
617 |
count=0;
|
618 |
pfeature = (IFeature)it.next(); |
619 |
System.out.println(pfeature.getString("NOMBRE")); |
620 |
count++; |
621 |
while (it.hasNext()){
|
622 |
feature = (IFeature)it.next(); |
623 |
v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
624 |
v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
625 |
pfeature=feature; |
626 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
627 |
System.out.println(pfeature.getString("NOMBRE")); |
628 |
count++; |
629 |
} |
630 |
assertEquals("Iteration error",10,count); |
631 |
|
632 |
|
633 |
|
634 |
|
635 |
fs.cancelEditing(); |
636 |
|
637 |
|
638 |
|
639 |
try {
|
640 |
fs.close(); |
641 |
} catch (CloseException e) {
|
642 |
e.printStackTrace(); |
643 |
fail("Exception:" + e);
|
644 |
} |
645 |
|
646 |
|
647 |
|
648 |
System.out.println("======= /SHP =============="); |
649 |
} catch (DataException e) {
|
650 |
// TODO Auto-generated catch block
|
651 |
e.printStackTrace(); |
652 |
} |
653 |
} |
654 |
|
655 |
public void testDXF() { |
656 |
try {
|
657 |
System.out.println("======= DXF =============="); |
658 |
org.gvsig.data.datastores.vectorial.file.dxf.Register.selfRegister(); |
659 |
|
660 |
DataManager dsm=DataManager.getManager(); |
661 |
|
662 |
|
663 |
IDataStoreParameters dp=dsm.createDataStoreParameters(DXFStore.DATASTORE_NAME); |
664 |
((DXFStoreParameters)dp).setFile(dxffile); |
665 |
IProjection proj = CRSFactory.getCRS("EPSG:23030");
|
666 |
((DXFStoreParameters)dp).setProjection(proj); |
667 |
driverTest(dp,null,null,true); |
668 |
|
669 |
IFeatureStore fs=null;
|
670 |
try {
|
671 |
fs = (IFeatureStore)dsm.createDataStore(dp); |
672 |
} catch (InitializeException e) {
|
673 |
e.printStackTrace(); |
674 |
fail("Exception:" + e);
|
675 |
} |
676 |
assertNotNull("Can't create Feature Store", fs);
|
677 |
|
678 |
|
679 |
fs.open(); |
680 |
|
681 |
|
682 |
Iterator it;
|
683 |
IFeatureCollection fc; |
684 |
Comparable v1,v2;
|
685 |
IFeature feature,pfeature; |
686 |
long count;
|
687 |
|
688 |
|
689 |
fc = (IFeatureCollection)fs.getDataCollection(); |
690 |
|
691 |
assertEquals(10, fc.size());
|
692 |
|
693 |
fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'",null); |
694 |
|
695 |
assertEquals(2, fc.size());
|
696 |
|
697 |
it = fc.iterator(); |
698 |
count=0;
|
699 |
while (it.hasNext()){
|
700 |
feature = (IFeature)it.next(); |
701 |
assertTrue("Filter error",feature.getInt("Color")>7); |
702 |
count++; |
703 |
} |
704 |
assertEquals("Iteration error",2,count); |
705 |
|
706 |
|
707 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer ASC"); |
708 |
assertEquals(10, fc.size());
|
709 |
it = fc.iterator(); |
710 |
count=0;
|
711 |
pfeature = (IFeature)it.next(); |
712 |
count++; |
713 |
while (it.hasNext()){
|
714 |
feature = (IFeature)it.next(); |
715 |
v1 = (Comparable)pfeature.get("Layer"); |
716 |
v2 = (Comparable)feature.get("Layer"); |
717 |
pfeature=feature; |
718 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
719 |
count++; |
720 |
} |
721 |
assertEquals("Iteration error",10,count); |
722 |
|
723 |
|
724 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer DESC"); |
725 |
assertEquals(10, fc.size());
|
726 |
it = fc.iterator(); |
727 |
|
728 |
count=0;
|
729 |
pfeature = (IFeature)it.next(); |
730 |
count++; |
731 |
while (it.hasNext()){
|
732 |
feature = (IFeature)it.next(); |
733 |
v1 = (Comparable)pfeature.get("Layer"); |
734 |
v2 = (Comparable)feature.get("Layer"); |
735 |
pfeature=feature; |
736 |
assertTrue("Short error", (v1.compareTo(v1) >= 0)); |
737 |
count++; |
738 |
} |
739 |
assertEquals("Iteration error",10,count); |
740 |
|
741 |
|
742 |
fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'","Layer ASC"); |
743 |
|
744 |
assertEquals(2, fc.size());
|
745 |
|
746 |
it = fc.iterator(); |
747 |
|
748 |
count=0;
|
749 |
pfeature = (IFeature)it.next(); |
750 |
assertTrue(pfeature.getInt("Color")>7); |
751 |
count++; |
752 |
while (it.hasNext()){
|
753 |
feature = (IFeature)it.next(); |
754 |
assertTrue("Filter error",feature.getInt("Color")>7); |
755 |
v1 = (Comparable)pfeature.get("Color"); |
756 |
v2 = (Comparable)feature.get("Color"); |
757 |
pfeature=feature; |
758 |
Integer i1=(Integer)v1; |
759 |
Integer i2=(Integer)v2; |
760 |
assertTrue("Short error", (i1.intValue()>i2.intValue()));
|
761 |
count++; |
762 |
} |
763 |
assertEquals("Iteration error",2,count); |
764 |
|
765 |
|
766 |
|
767 |
// fc = (IFeatureCollection)fs.getDataCollection(null,null,"Color,Layer Desc");
|
768 |
// assertEquals(10, fc.size());
|
769 |
// it = fc.iterator();
|
770 |
// count=0;
|
771 |
// pfeature = (IFeature)it.next();
|
772 |
// System.out.println(pfeature.getString("Layer"));
|
773 |
// count++;
|
774 |
// while (it.hasNext()){
|
775 |
// feature = (IFeature)it.next();
|
776 |
// v1 = (Comparable)((String)pfeature.get("Layer")).toLowerCase();
|
777 |
// v2 = (Comparable)((String)feature.get("Layer")).toLowerCase();
|
778 |
// pfeature=feature;
|
779 |
// assertTrue("Short error", (v1.compareTo(v2) >= 0));
|
780 |
// System.out.println(pfeature.getString("Layer"));
|
781 |
// count++;
|
782 |
// }
|
783 |
// assertEquals("Iteration error",10,count);
|
784 |
|
785 |
|
786 |
try {
|
787 |
fs.close(); |
788 |
} catch (CloseException e) {
|
789 |
e.printStackTrace(); |
790 |
fail("Exception:" + e);
|
791 |
} |
792 |
|
793 |
|
794 |
System.out.println("======= /DXF =============="); |
795 |
} catch (OpenException e1) {
|
796 |
e1.printStackTrace(); |
797 |
fail(); |
798 |
} catch (ReadException e) {
|
799 |
// TODO Auto-generated catch block
|
800 |
e.printStackTrace(); |
801 |
} |
802 |
} |
803 |
|
804 |
public void testDGN() { |
805 |
try {
|
806 |
System.out.println("======= DGN =============="); |
807 |
org.gvsig.data.datastores.vectorial.file.dgn.Register.selfRegister(); |
808 |
|
809 |
DataManager dsm=DataManager.getManager(); |
810 |
|
811 |
|
812 |
IDataStoreParameters dp=dsm.createDataStoreParameters(DGNStore.DATASTORE_NAME); |
813 |
((DGNStoreParameters)dp).setFile(dgnfile); |
814 |
driverTest(dp,null,null,true); |
815 |
IFeatureStore fs=null;
|
816 |
try {
|
817 |
fs = (IFeatureStore)dsm.createDataStore(dp); |
818 |
} catch (InitializeException e) {
|
819 |
e.printStackTrace(); |
820 |
fail("Exception:" + e);
|
821 |
} |
822 |
assertNotNull("Can't create Feature Store", fs);
|
823 |
|
824 |
|
825 |
fs.open(); |
826 |
|
827 |
|
828 |
Iterator it;
|
829 |
IFeatureCollection fc; |
830 |
Comparable v1,v2;
|
831 |
IFeature feature,pfeature; |
832 |
long count;
|
833 |
|
834 |
|
835 |
fc = (IFeatureCollection)fs.getDataCollection(); |
836 |
|
837 |
assertEquals(14646, fc.size());
|
838 |
|
839 |
fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'",null); |
840 |
|
841 |
assertEquals(7352, fc.size());
|
842 |
|
843 |
it = fc.iterator(); |
844 |
count=0;
|
845 |
while (it.hasNext()){
|
846 |
feature = (IFeature)it.next(); |
847 |
assertTrue("Filter error",feature.getInt("Color")>=7); |
848 |
count++; |
849 |
} |
850 |
assertEquals("Iteration error",7352,count); |
851 |
|
852 |
|
853 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer ASC"); |
854 |
assertEquals(14646, fc.size());
|
855 |
it = fc.iterator(); |
856 |
count=0;
|
857 |
pfeature = (IFeature)it.next(); |
858 |
count++; |
859 |
while (it.hasNext()){
|
860 |
feature = (IFeature)it.next(); |
861 |
v1 = (Comparable)pfeature.get("Layer"); |
862 |
v2 = (Comparable)feature.get("Layer"); |
863 |
if (v2==null) |
864 |
System.out.println("null"); |
865 |
assertTrue("Short error", (v1.compareTo(v2) <= 0)); |
866 |
pfeature=feature; |
867 |
count++; |
868 |
} |
869 |
assertEquals("Iteration error",14646,count); |
870 |
|
871 |
|
872 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer DESC"); |
873 |
assertEquals(14646, fc.size());
|
874 |
it = fc.iterator(); |
875 |
|
876 |
count=0;
|
877 |
pfeature = (IFeature)it.next(); |
878 |
count++; |
879 |
while (it.hasNext()){
|
880 |
feature = (IFeature)it.next(); |
881 |
v1 = (Comparable)pfeature.get("Layer"); |
882 |
v2 = (Comparable)feature.get("Layer"); |
883 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
884 |
pfeature=feature; |
885 |
count++; |
886 |
} |
887 |
assertEquals("Iteration error",14646,count); |
888 |
|
889 |
|
890 |
fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'","Layer ASC"); |
891 |
|
892 |
assertEquals(7352, fc.size());
|
893 |
|
894 |
it = fc.iterator(); |
895 |
|
896 |
count=0;
|
897 |
pfeature = (IFeature)it.next(); |
898 |
assertTrue(pfeature.getInt("Color")>7); |
899 |
count++; |
900 |
while (it.hasNext()){
|
901 |
feature = (IFeature)it.next(); |
902 |
assertTrue("Filter error",feature.getInt("Color")>7); |
903 |
v1 = (Comparable)pfeature.get("Layer"); |
904 |
v2 = (Comparable)feature.get("Layer"); |
905 |
pfeature=feature; |
906 |
Integer i1=(Integer)v1; |
907 |
Integer i2=(Integer)v2; |
908 |
assertTrue("Short error", (i1.intValue()<=i2.intValue()));
|
909 |
count++; |
910 |
} |
911 |
assertEquals("Iteration error",7352,count); |
912 |
|
913 |
|
914 |
|
915 |
// fc = (IFeatureCollection)fs.getDataCollection(null,null,"Color,Layer Desc");
|
916 |
// assertEquals(10, fc.size());
|
917 |
// it = fc.iterator();
|
918 |
// count=0;
|
919 |
// pfeature = (IFeature)it.next();
|
920 |
// System.out.println(pfeature.getString("Layer"));
|
921 |
// count++;
|
922 |
// while (it.hasNext()){
|
923 |
// feature = (IFeature)it.next();
|
924 |
// v1 = (Comparable)((String)pfeature.get("Layer")).toLowerCase();
|
925 |
// v2 = (Comparable)((String)feature.get("Layer")).toLowerCase();
|
926 |
// pfeature=feature;
|
927 |
// assertTrue("Short error", (v1.compareTo(v2) >= 0));
|
928 |
// System.out.println(pfeature.getString("Layer"));
|
929 |
// count++;
|
930 |
// }
|
931 |
// assertEquals("Iteration error",10,count);
|
932 |
|
933 |
|
934 |
try {
|
935 |
fs.close(); |
936 |
} catch (CloseException e) {
|
937 |
e.printStackTrace(); |
938 |
fail("Exception:" + e);
|
939 |
} |
940 |
|
941 |
|
942 |
System.out.println("======= /DGN =============="); |
943 |
} catch (OpenException e1) {
|
944 |
e1.printStackTrace(); |
945 |
fail(); |
946 |
} catch (ReadException e) {
|
947 |
// TODO Auto-generated catch block
|
948 |
e.printStackTrace(); |
949 |
} |
950 |
} |
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
// private IFeatureStore createFeatureStore(IDriverParameters dp){
|
958 |
// DataSourceManager dsm=DataSourceManager.getManager();
|
959 |
|
960 |
// IDataStoreParameters dsp=dsm.createDataStoreParameters(DriverStore.DATASTORE_NAME);
|
961 |
|
962 |
// ((IDriverStoreParameters)dsp).setDriverParameters(dp);
|
963 |
// IFeatureStore fs=null;
|
964 |
// try {
|
965 |
// fs = (IFeatureStore)dsm.createDataStore(dsp);
|
966 |
// } catch (InitializeException e) {
|
967 |
// e.printStackTrace();
|
968 |
// fail("Exception:" + e);
|
969 |
// }
|
970 |
// return fs;
|
971 |
|
972 |
// }
|
973 |
|
974 |
|
975 |
private void driverTest(IDataStoreParameters dp,String filter, String order,boolean testEdit){ |
976 |
DataManager dsm=DataManager.getManager(); |
977 |
|
978 |
// IDataStoreParameters dsp=dsm.createDataStoreParameters(DriverStore.DATASTORE_NAME);
|
979 |
|
980 |
// ((IDriverStoreParameters)dsp).setDriverParameters(dp);
|
981 |
// IFeatureStore fs=createFeatureStore(dp);
|
982 |
IFeatureStore fs=null;
|
983 |
try {
|
984 |
fs = (IFeatureStore)dsm.createDataStore(dp); |
985 |
} catch (InitializeException e) {
|
986 |
e.printStackTrace(); |
987 |
fail("Exception:" + e);
|
988 |
} |
989 |
try {
|
990 |
fs.open(); |
991 |
} catch (OpenException e2) {
|
992 |
e2.printStackTrace(); |
993 |
fail(); |
994 |
} |
995 |
|
996 |
if (fs.isEditable() && testEdit) {
|
997 |
try {
|
998 |
fs.startEditing(); |
999 |
if (fs.canAlterFeatureType()){
|
1000 |
IFeatureType featureType=fs.getDefaultFeatureType(); |
1001 |
// DefaultAttributeDescriptor dad=new DefaultAttributeDescriptor();
|
1002 |
// dad.loading();
|
1003 |
// dad.setName("Prueba1");
|
1004 |
// dad.setDefaultValue("11p");
|
1005 |
// dad.setSize(10);
|
1006 |
// dad.setType(IFeatureAttributeDescriptor.TYPE_STRING);
|
1007 |
// dad.stopLoading();
|
1008 |
// fs.insert(dad);
|
1009 |
// fs.delete((IFeatureAttributeDescriptor)featureType.get(featureType.getFieldIndex("Prueba1")));
|
1010 |
AttributeDescriptor dad2=(AttributeDescriptor)featureType.get(featureType.getFieldIndex("TIPO"));
|
1011 |
dad2.editing(); |
1012 |
// dad2.setName("TIPO");
|
1013 |
dad2.setDefaultValue("Tipop");
|
1014 |
// dad2.setSize(10);
|
1015 |
dad2.setType(IFeatureAttributeDescriptor.TYPE_STRING); |
1016 |
fs.update(dad2); |
1017 |
} |
1018 |
} catch (ReadException e) {
|
1019 |
e.printStackTrace(); |
1020 |
fail(); |
1021 |
} |
1022 |
catch (IsNotAttributeSettingException e) {
|
1023 |
// TODO Auto-generated catch block
|
1024 |
e.printStackTrace(); |
1025 |
} |
1026 |
try {
|
1027 |
IFeature feature1 = fs.createDefaultFeature(false);
|
1028 |
|
1029 |
IFeature feature2 = fs.createDefaultFeature(false);
|
1030 |
IFeature feature3 = fs.createDefaultFeature(false);
|
1031 |
|
1032 |
fs.insert(feature1); |
1033 |
fs.insert(feature2); |
1034 |
|
1035 |
feature1.editing(); |
1036 |
feature1.set(1,"hola"); |
1037 |
|
1038 |
fs.update(feature1); |
1039 |
fs.delete(feature3); |
1040 |
fs.delete(feature2); |
1041 |
} catch (DataException e) {
|
1042 |
// TODO Auto-generated catch block
|
1043 |
e.printStackTrace(); |
1044 |
} |
1045 |
} |
1046 |
|
1047 |
//Mostrar por consola todos los registros.
|
1048 |
IFeatureType ft= fs.getDefaultFeatureType(); |
1049 |
IFeatureCollection featureCollection=null;
|
1050 |
// featureCollection = (IFeatureCollection)fs.getDataCollection();
|
1051 |
// featureCollection = (IFeatureCollection)fs.getDataCollection(ft,"NOMBRE = 'CALPE'",null);
|
1052 |
// featureCollection = (IFeatureCollection)fs.getDataCollection(ft,"AREA > 3.2213163729E7 and AREA < 3.2213163749E7",null);
|
1053 |
try {
|
1054 |
featureCollection = (IFeatureCollection)fs.getDataCollection(ft,filter,order); |
1055 |
} catch (ReadException e2) {
|
1056 |
// TODO Auto-generated catch block
|
1057 |
e2.printStackTrace(); |
1058 |
} |
1059 |
|
1060 |
PrintlnFeaturesVisitor visitor=new PrintlnFeaturesVisitor(ft);
|
1061 |
try {
|
1062 |
featureCollection.accept(visitor); |
1063 |
} catch (BaseException e1) {
|
1064 |
e1.printStackTrace(); |
1065 |
fail("Exception: "+e1);
|
1066 |
} |
1067 |
|
1068 |
featureCollection.dispose(); |
1069 |
|
1070 |
if (fs.isEditable() && testEdit){
|
1071 |
try {
|
1072 |
fs.finishEditing(); |
1073 |
} catch (WriteException e) {
|
1074 |
e.printStackTrace(); |
1075 |
fail("Exception: "+e);
|
1076 |
} catch (ReadException e) {
|
1077 |
e.printStackTrace(); |
1078 |
fail("Exception: "+e);
|
1079 |
} |
1080 |
} |
1081 |
try {
|
1082 |
fs.close(); |
1083 |
} catch (CloseException e) {
|
1084 |
e.printStackTrace(); |
1085 |
fail("Exception: "+e);
|
1086 |
} |
1087 |
try {
|
1088 |
fs.dispose(); |
1089 |
} catch (CloseException e) {
|
1090 |
// TODO Auto-generated catch block
|
1091 |
e.printStackTrace(); |
1092 |
} |
1093 |
} |
1094 |
} |