Revision 11290
trunk/libraries/libFMap/src-test/com/iver/cit/gvsig/fmap/featureiterators/FeatureIteratorTest.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 17-abr-2007 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
/* CVS MESSAGES: |
|
45 |
* |
|
46 |
* $Id$ |
|
47 |
* $Log$ |
|
48 |
* Revision 1.1 2007-04-19 18:12:56 azabala |
|
49 |
* *** empty log message *** |
|
50 |
* |
|
51 |
* |
|
52 |
*/ |
|
53 |
package com.iver.cit.gvsig.fmap.featureiterators; |
|
54 |
|
|
55 |
import java.awt.geom.Rectangle2D; |
|
56 |
import java.io.File; |
|
57 |
import java.net.URL; |
|
58 |
|
|
59 |
import junit.framework.TestCase; |
|
60 |
|
|
61 |
import org.cresques.cts.IProjection; |
|
62 |
|
|
63 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
64 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
|
65 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
|
66 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
|
67 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
|
68 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
|
69 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
70 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
71 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
72 |
|
|
73 |
public class FeatureIteratorTest extends TestCase { |
|
74 |
static final String fwAndamiDriverPath = "../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers"; |
|
75 |
private File baseDataPath; |
|
76 |
private File baseDriversPath; |
|
77 |
|
|
78 |
private String SHP_DRIVER_NAME = "gvSIG shp driver"; |
|
79 |
private String DXF_DRIVER_NAME = "gvSIG DXF Memory Driver"; |
|
80 |
|
|
81 |
private IProjection PROJECTION_DEFAULT = |
|
82 |
CRSFactory.getCRS("EPSG:23030"); |
|
83 |
private IProjection newProjection = |
|
84 |
CRSFactory.getCRS("EPSG:23029"); |
|
85 |
|
|
86 |
|
|
87 |
protected void setUp() throws Exception { |
|
88 |
super.setUp(); |
|
89 |
URL url = this.getClass().getResource("testdata"); |
|
90 |
if (url == null) |
|
91 |
throw new Exception("No se encuentra el directorio con datos de prueba"); |
|
92 |
|
|
93 |
baseDataPath = new File(url.getFile()); |
|
94 |
if (!baseDataPath.exists()) |
|
95 |
throw new Exception("No se encuentra el directorio con datos de prueba"); |
|
96 |
|
|
97 |
baseDriversPath = new File(fwAndamiDriverPath); |
|
98 |
if (!baseDriversPath.exists()) |
|
99 |
throw new Exception("Can't find drivers path: " + fwAndamiDriverPath); |
|
100 |
|
|
101 |
LayerFactory.setDriversPath(baseDriversPath.getAbsolutePath()); |
|
102 |
if (LayerFactory.getDM().getDriverNames().length < 1) |
|
103 |
throw new Exception("Can't find drivers in path: " + fwAndamiDriverPath); |
|
104 |
} |
|
105 |
|
|
106 |
|
|
107 |
private FLayer newLayer(String fileName, |
|
108 |
String driverName) |
|
109 |
throws LoadLayerException { |
|
110 |
File file = new File(baseDataPath, fileName); |
|
111 |
return LayerFactory.createLayer(fileName, |
|
112 |
driverName, |
|
113 |
file, PROJECTION_DEFAULT); |
|
114 |
} |
|
115 |
|
|
116 |
|
|
117 |
public void test1() { |
|
118 |
try { |
|
119 |
|
|
120 |
//pruebas de reproyeccion y seleccion de numero de campos |
|
121 |
FLyrVect lyr = (FLyrVect) newLayer("Cantabria.shp", SHP_DRIVER_NAME); |
|
122 |
lyr.setAvailable(true); |
|
123 |
IFeatureIterator iterator = lyr.getSource().getFeatureIterator(new String[]{"ID", "AREA"}, null); |
|
124 |
IFeature feature = iterator.next(); |
|
125 |
assertTrue(feature != null); |
|
126 |
|
|
127 |
iterator = lyr.getSource().getFeatureIterator((String[])null, newProjection); |
|
128 |
IFeature feature2 = iterator.next(); |
|
129 |
//test of field restriction |
|
130 |
assertTrue(feature.getAttributes().length == 2); |
|
131 |
assertTrue(feature2.getAttributes().length > 2); |
|
132 |
assertTrue(!feature.getGeometry().toJTSGeometry().equals(feature2.getGeometry().toJTSGeometry())); |
|
133 |
|
|
134 |
|
|
135 |
//pruebas de iteracion espacial |
|
136 |
FLyrVect lyr2 = (FLyrVect) newLayer("Edificaciones.shp", SHP_DRIVER_NAME); |
|
137 |
lyr2.setAvailable(true); |
|
138 |
double xmin = 410000; |
|
139 |
double xmax = 415000; |
|
140 |
double ymin = 4790000; |
|
141 |
double ymax = 4793000; |
|
142 |
Rectangle2D rect = new Rectangle2D.Double(xmin, ymin, (xmax-xmin), (ymax-ymin)); |
|
143 |
iterator = lyr2.getSource().getFeatureIterator(rect, null, newProjection); |
|
144 |
int numFeatures = 0; |
|
145 |
while(iterator.hasNext()){ |
|
146 |
feature = iterator.next(); |
|
147 |
numFeatures++; |
|
148 |
} |
|
149 |
int numFeatures2 = 0; |
|
150 |
iterator = lyr2.getSource().getFeatureIterator(); |
|
151 |
while(iterator.hasNext()){ |
|
152 |
feature = iterator.next(); |
|
153 |
numFeatures2++; |
|
154 |
} |
|
155 |
assertTrue(numFeatures2 > numFeatures); |
|
156 |
|
|
157 |
|
|
158 |
//pruebas de iteracion en base a criterios alfanumericos |
|
159 |
final String expr = "select * from " + lyr.getRecordset().getName() + " where area < 700;"; |
|
160 |
iterator = lyr.getSource().getFeatureIterator(expr, null); |
|
161 |
numFeatures2 = 0; |
|
162 |
while(iterator.hasNext()){ |
|
163 |
feature = iterator.next(); |
|
164 |
numFeatures2++; |
|
165 |
} |
|
166 |
|
|
167 |
iterator = lyr.getSource().getFeatureIterator(); |
|
168 |
while(iterator.hasNext()){ |
|
169 |
feature = iterator.next(); |
|
170 |
numFeatures++; |
|
171 |
} |
|
172 |
assertTrue(numFeatures2 > 0); |
|
173 |
assertTrue(numFeatures > numFeatures2); |
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
//pruebas con el driver dxf en vez del shp |
|
178 |
FLyrVect lyr3 = (FLyrVect) newLayer("es1120003_2_02.dxf", DXF_DRIVER_NAME); |
|
179 |
lyr3.setAvailable(true); |
|
180 |
iterator = lyr3.getSource().getFeatureIterator("select * from "+lyr3.getRecordset().getName()+" where ID > 17;", null); |
|
181 |
numFeatures2 = 0; |
|
182 |
while(iterator.hasNext()){ |
|
183 |
feature = iterator.next(); |
|
184 |
numFeatures2++; |
|
185 |
} |
|
186 |
assertTrue(numFeatures2 > 0); |
|
187 |
|
|
188 |
//queda por probar los iteradores contra base de datos |
|
189 |
//en base a criterios alfanumericos y espaciales |
|
190 |
|
|
191 |
} catch (LoadLayerException e) { |
|
192 |
// TODO Auto-generated catch block |
|
193 |
e.printStackTrace(); |
|
194 |
} catch (ReadDriverException e) { |
|
195 |
// TODO Auto-generated catch block |
|
196 |
e.printStackTrace(); |
|
197 |
} catch (ExpansionFileReadException e) { |
|
198 |
// TODO Auto-generated catch block |
|
199 |
e.printStackTrace(); |
|
200 |
} |
|
201 |
} |
|
202 |
} |
|
203 |
|
|
0 | 204 |
Also available in: Unified diff