Revision 29385 branches/v2_0_0_prep/libraries/libGeocoding/src-test/org/gvsig/geocoding/GeocoderTest.java
GeocoderTest.java | ||
---|---|---|
28 | 28 |
package org.gvsig.geocoding; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
/** |
|
32 |
* Test |
|
33 |
* |
|
34 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a> |
|
35 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a> |
|
36 |
*/ |
|
37 | 31 |
import java.util.Iterator; |
38 | 32 |
import java.util.Set; |
39 | 33 |
|
... | ... | |
43 | 37 |
import org.gvsig.fmap.dal.DALLibrary; |
44 | 38 |
import org.gvsig.fmap.dal.DALLocator; |
45 | 39 |
import org.gvsig.fmap.dal.DataManager; |
46 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
40 |
import org.gvsig.fmap.dal.exception.DataException; |
|
41 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
42 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
43 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
47 | 44 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
48 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
49 | 45 |
import org.gvsig.fmap.dal.store.shp.SHPLibrary; |
50 | 46 |
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters; |
51 | 47 |
import org.gvsig.fmap.dal.store.shp.SHPStoreProvider; |
52 |
import org.gvsig.fmap.geom.GeometryLibrary; |
|
48 |
import org.gvsig.fmap.geom.impl.DefaultGeometryLibrary;
|
|
53 | 49 |
import org.gvsig.fmap.geom.primitive.Point; |
54 | 50 |
import org.gvsig.geocoding.address.Address; |
55 | 51 |
import org.gvsig.geocoding.address.Literal; |
... | ... | |
71 | 67 |
import org.gvsig.tools.ToolsLibrary; |
72 | 68 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
73 | 69 |
import org.gvsig.tools.locator.Library; |
70 |
import org.gvsig.tools.locator.LocatorException; |
|
74 | 71 |
import org.slf4j.Logger; |
75 | 72 |
import org.slf4j.LoggerFactory; |
76 | 73 |
|
... | ... | |
83 | 80 |
public class GeocoderTest extends TestCase { |
84 | 81 |
|
85 | 82 |
protected DataManager dataManager = null; |
86 |
private File shape = new File("./test-data/geocoder/streets.shp");
|
|
87 |
private Logger log = LoggerFactory.getLogger(ComposedTest.class);
|
|
83 |
private File file = new File("test-data/geocoder/streets.shp");
|
|
84 |
private Logger log = LoggerFactory.getLogger(GeocoderTest.class);
|
|
88 | 85 |
|
89 | 86 |
protected void setUp() throws Exception { |
90 | 87 |
super.setUp(); |
... | ... | |
101 | 98 |
libFile.initialize(); |
102 | 99 |
libFile.postInitialize(); |
103 | 100 |
|
104 |
Library lib = new GeometryLibrary(); |
|
101 |
Library lib = new DefaultGeometryLibrary();
|
|
105 | 102 |
lib.initialize(); |
106 | 103 |
lib.postInitialize(); |
107 | 104 |
|
108 | 105 |
Library shpLib = new SHPLibrary(); |
109 | 106 |
shpLib.initialize(); |
110 | 107 |
shpLib.postInitialize(); |
111 |
|
|
108 |
|
|
112 | 109 |
Library geocoLib = new DefaultGeocodingLibrary(); |
113 | 110 |
geocoLib.initialize(); |
114 | 111 |
geocoLib.postInitialize(); |
... | ... | |
120 | 117 |
super.tearDown(); |
121 | 118 |
} |
122 | 119 |
|
123 |
public void testGeocode() throws ReadException { |
|
120 |
public void testGeocode() throws InitializeException, LocatorException, |
|
121 |
DataException, ValidateDataParametersException { |
|
124 | 122 |
|
125 | 123 |
/* Set the pattern */ |
126 | 124 |
Patterngeocoding pat = getAPattern(); |
... | ... | |
135 | 133 |
|
136 | 134 |
Address address = new DefaultAddress(literal); |
137 | 135 |
|
138 |
Set<GeocodingResult> results = null; |
|
139 |
try { |
|
140 |
results = geocoder.geocode(address); |
|
141 |
assertEquals(2, results.size()); |
|
142 |
} catch (Exception e) { |
|
143 |
log.error("Geocoding", e); |
|
144 |
} |
|
136 |
Set<GeocodingResult> results = geocoder.geocode(address); |
|
137 |
assertEquals(2, results.size()); |
|
138 |
|
|
145 | 139 |
Iterator<GeocodingResult> it = results.iterator(); |
146 | 140 |
while (it.hasNext()) { |
147 | 141 |
GeocodingResult res = it.next(); |
148 |
Point pto = (Point)res.getGeometry(); |
|
149 |
log.debug("PTO: "+pto.getX()+","+pto.getY());
|
|
142 |
Point pto = (Point) res.getGeometry();
|
|
143 |
log.debug("PTO: " + pto.getX() + "," + pto.getY());
|
|
150 | 144 |
} |
151 |
|
|
152 | 145 |
|
153 | 146 |
} |
154 | 147 |
|
155 |
private Patterngeocoding getAPattern() { |
|
148 |
private Patterngeocoding getAPattern() throws InitializeException, |
|
149 |
ProviderNotRegisteredException, ValidateDataParametersException { |
|
156 | 150 |
|
157 | 151 |
assertNotNull(dataManager); |
158 | 152 |
dataManager.registerDefaultEvaluator(SQLJEPEvaluator.class); |
159 | 153 |
|
160 | 154 |
Patterngeocoding pat = new DefaultPatterngeocoding(); |
161 | 155 |
|
162 |
try { |
|
163 |
pat.setPatternName("Test pattern"); |
|
156 |
pat.setPatternName("Test pattern"); |
|
164 | 157 |
|
165 |
GeocodingSource source = new DefaultGeocodingSource();
|
|
158 |
GeocodingSource source = new DefaultGeocodingSource(); |
|
166 | 159 |
|
167 |
SHPStoreParameters params = (SHPStoreParameters) dataManager |
|
168 |
.createStoreParameters(SHPStoreProvider.NAME); |
|
169 |
assertNotNull(shape); |
|
170 |
params.setFile(shape); |
|
171 |
FeatureStore store = (FeatureStore) dataManager.createStore(params); |
|
172 |
source.setLayerSource(store); |
|
160 |
SHPStoreParameters params = (SHPStoreParameters) dataManager |
|
161 |
.createStoreParameters(SHPStoreProvider.NAME); |
|
162 |
System.out.println(file.getAbsolutePath()); |
|
163 |
assertNotNull(file); |
|
164 |
params.setFile(file); |
|
165 |
FeatureStore store = (FeatureStore) dataManager.createStore(params); |
|
166 |
source.setLayerSource(store); |
|
173 | 167 |
|
174 |
AbstractGeocodingStyle style = new SimpleCentroid();
|
|
175 |
Literal relations = new DefaultLiteral();
|
|
176 |
relations.add(new DefaultRelationsComponent("via","STREET_TYP"));
|
|
177 |
relations.add(new DefaultRelationsComponent("calle","STREET_NAM"));
|
|
178 |
relations.add(new DefaultRelationsComponent("nparfrom","RF_ADD"));
|
|
179 |
relations.add(new DefaultRelationsComponent("nparto","RT_ADD"));
|
|
180 |
relations.add(new DefaultRelationsComponent("nimparfrom","LF_ADD"));
|
|
181 |
relations.add(new DefaultRelationsComponent("nimparto","LT_ADD"));
|
|
168 |
AbstractGeocodingStyle style = new SimpleCentroid(); |
|
169 |
Literal relations = new DefaultLiteral(); |
|
170 |
relations.add(new DefaultRelationsComponent("via", "STREET_TYP"));
|
|
171 |
relations.add(new DefaultRelationsComponent("calle", "STREET_NAM"));
|
|
172 |
relations.add(new DefaultRelationsComponent("nparfrom", "RF_ADD"));
|
|
173 |
relations.add(new DefaultRelationsComponent("nparto", "RT_ADD"));
|
|
174 |
relations.add(new DefaultRelationsComponent("nimparfrom", "LF_ADD"));
|
|
175 |
relations.add(new DefaultRelationsComponent("nimparto", "LT_ADD"));
|
|
182 | 176 |
|
183 |
style.setRelationsLiteral(relations);
|
|
184 |
source.setStyle(style);
|
|
177 |
style.setRelationsLiteral(relations); |
|
178 |
source.setStyle(style); |
|
185 | 179 |
|
186 |
pat.setSource(source); |
|
187 |
|
|
188 |
GeocodingSettings settings = new DefaultGeocodingSettings(); |
|
189 |
pat.setSettings(settings); |
|
180 |
pat.setSource(source); |
|
190 | 181 |
|
191 |
} catch (Exception e) { |
|
192 |
log.error("Building a pattern", e); |
|
193 |
} |
|
182 |
GeocodingSettings settings = new DefaultGeocodingSettings(); |
|
183 |
pat.setSettings(settings); |
|
194 | 184 |
|
195 | 185 |
return pat; |
196 | 186 |
|
Also available in: Unified diff