svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libGeocoding / src-test / org / gvsig / geocoding / massive / TestMassiveGeocoding.java @ 29385
History | View | Annotate | Download (18.7 KB)
1 |
/* 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 Prodevelop S.L main development
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.geocoding.massive; |
29 |
|
30 |
import java.io.File; |
31 |
import java.util.ArrayList; |
32 |
import java.util.Iterator; |
33 |
import java.util.List; |
34 |
import java.util.Set; |
35 |
|
36 |
import junit.framework.TestCase; |
37 |
|
38 |
import org.gvsig.fmap.dal.DALFileLibrary; |
39 |
import org.gvsig.fmap.dal.DALLibrary; |
40 |
import org.gvsig.fmap.dal.DALLocator; |
41 |
import org.gvsig.fmap.dal.DataManager; |
42 |
import org.gvsig.fmap.dal.DataServerExplorer; |
43 |
import org.gvsig.fmap.dal.DataTypes; |
44 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
45 |
import org.gvsig.fmap.dal.exception.DataException; |
46 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
47 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
48 |
import org.gvsig.fmap.dal.feature.Feature; |
49 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
50 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
51 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
52 |
import org.gvsig.fmap.dal.feature.FeatureType; |
53 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
54 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
55 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
56 |
import org.gvsig.fmap.dal.store.dbf.DBFNewStoreParameters; |
57 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters; |
58 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider; |
59 |
import org.gvsig.fmap.dal.store.shp.SHPLibrary; |
60 |
import org.gvsig.fmap.dal.store.shp.SHPNewStoreParameters; |
61 |
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters; |
62 |
import org.gvsig.fmap.dal.store.shp.SHPStoreProvider; |
63 |
import org.gvsig.fmap.geom.Geometry; |
64 |
import org.gvsig.fmap.geom.GeometryLibrary; |
65 |
import org.gvsig.fmap.geom.GeometryLocator; |
66 |
import org.gvsig.fmap.geom.GeometryManager; |
67 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
68 |
import org.gvsig.fmap.geom.primitive.Point; |
69 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
70 |
import org.gvsig.geocoding.Geocoder; |
71 |
import org.gvsig.geocoding.GeocodingLibrary; |
72 |
import org.gvsig.geocoding.GeocodingLocator; |
73 |
import org.gvsig.geocoding.address.Address; |
74 |
import org.gvsig.geocoding.address.AddressComponent; |
75 |
import org.gvsig.geocoding.address.ComposedAddress; |
76 |
import org.gvsig.geocoding.address.Literal; |
77 |
import org.gvsig.geocoding.address.impl.DefaultAddress; |
78 |
import org.gvsig.geocoding.address.impl.DefaultAddressComponent; |
79 |
import org.gvsig.geocoding.address.impl.DefaultLiteral; |
80 |
import org.gvsig.geocoding.address.impl.DefaultRelationsComponent; |
81 |
import org.gvsig.geocoding.impl.DataGeocoderImpl; |
82 |
import org.gvsig.geocoding.impl.DefaultGeocodingLibrary; |
83 |
import org.gvsig.geocoding.pattern.GeocodingSource; |
84 |
import org.gvsig.geocoding.pattern.Patterngeocoding; |
85 |
import org.gvsig.geocoding.pattern.impl.DefaultGeocodingSource; |
86 |
import org.gvsig.geocoding.pattern.impl.DefaultPatterngeocoding; |
87 |
import org.gvsig.geocoding.result.GeocodingResult; |
88 |
import org.gvsig.geocoding.styles.AbstractGeocodingStyle; |
89 |
import org.gvsig.geocoding.styles.impl.SimpleCentroid; |
90 |
import org.gvsig.tools.ToolsLibrary; |
91 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
92 |
import org.gvsig.tools.locator.Library; |
93 |
import org.slf4j.Logger; |
94 |
import org.slf4j.LoggerFactory; |
95 |
|
96 |
/**
|
97 |
* Test
|
98 |
*
|
99 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
100 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
101 |
*/
|
102 |
|
103 |
public class TestMassiveGeocoding extends TestCase { |
104 |
|
105 |
private static final Logger log = LoggerFactory |
106 |
.getLogger(TestMassiveGeocoding.class); |
107 |
|
108 |
private DataManager dataManager = null; |
109 |
private FeatureStore masStore = null; |
110 |
private FeatureStore streetsStore = null; |
111 |
|
112 |
private Patterngeocoding pat = null; |
113 |
private List<Set<GeocodingResult>> listResults; |
114 |
|
115 |
public TestMassiveGeocoding() {
|
116 |
listResults = new ArrayList<Set<GeocodingResult>>(); |
117 |
|
118 |
try {
|
119 |
Library tools = new ToolsLibrary();
|
120 |
tools.initialize(); |
121 |
tools.postInitialize(); |
122 |
|
123 |
Library dlib = new DALLibrary();
|
124 |
dlib.initialize(); |
125 |
dlib.postInitialize(); |
126 |
|
127 |
Library libFile = new DALFileLibrary();
|
128 |
libFile.initialize(); |
129 |
libFile.postInitialize(); |
130 |
|
131 |
Library lib = new GeometryLibrary();
|
132 |
lib.initialize(); |
133 |
lib.postInitialize(); |
134 |
|
135 |
Library shpLib = new SHPLibrary();
|
136 |
shpLib.initialize(); |
137 |
shpLib.postInitialize(); |
138 |
|
139 |
Library geocoLib = new DefaultGeocodingLibrary();
|
140 |
geocoLib.initialize(); |
141 |
geocoLib.postInitialize(); |
142 |
|
143 |
} catch (Exception e) { |
144 |
e.printStackTrace(); |
145 |
} |
146 |
|
147 |
dataManager = DALLocator.getDataManager(); |
148 |
|
149 |
try {
|
150 |
// prov file
|
151 |
File prov = new File("test-data/geocoder/massive/streetsmassive.dbf"); |
152 |
assertTrue(prov.exists()); |
153 |
DBFStoreParameters provParam = (DBFStoreParameters) dataManager |
154 |
.createStoreParameters(DBFStoreProvider.NAME); |
155 |
provParam.setFile(prov); |
156 |
masStore = (FeatureStore) dataManager.createStore(provParam); |
157 |
assertNotNull(masStore); |
158 |
} catch (Exception e) { |
159 |
log.error("Getting massivestreets.dbf store", e);
|
160 |
} |
161 |
try {
|
162 |
// streets file
|
163 |
File streets = new File("test-data/geocoder/streets.shp"); |
164 |
assertTrue(streets.exists()); |
165 |
SHPStoreParameters strParam = (SHPStoreParameters) dataManager |
166 |
.createStoreParameters(SHPStoreProvider.NAME); |
167 |
strParam.setFile(streets); |
168 |
streetsStore = (FeatureStore) dataManager.createStore(strParam); |
169 |
assertNotNull(streetsStore); |
170 |
|
171 |
} catch (Exception e) { |
172 |
log.error("Getting streets.shp store", e);
|
173 |
} |
174 |
|
175 |
// Get ppatern
|
176 |
pat = getPattern(); |
177 |
} |
178 |
|
179 |
/**
|
180 |
* setUP
|
181 |
*/
|
182 |
public void setUp() { |
183 |
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* tearDown
|
188 |
*/
|
189 |
public void tearDown() { |
190 |
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* geocoding Massive
|
195 |
*
|
196 |
* @throws DataException
|
197 |
* @throws CreateGeometryException
|
198 |
*/
|
199 |
public void testMassive() throws DataException, CreateGeometryException { |
200 |
|
201 |
Geocoder geocoder = GeocodingLocator.getInstance().getGeocoder(); |
202 |
((DataGeocoderImpl) geocoder).setPattern(pat); |
203 |
|
204 |
// Get addresses
|
205 |
List<Address> addresses = getAddresses();
|
206 |
|
207 |
for (Address addr : addresses) {
|
208 |
Set<GeocodingResult> results = null; |
209 |
try {
|
210 |
results = geocoder.geocode(addr); |
211 |
} catch (Exception e) { |
212 |
log.error("Geocoding", e);
|
213 |
} |
214 |
listResults.add(results); |
215 |
} |
216 |
assertEquals(6, listResults.size());
|
217 |
|
218 |
// Create DBF file
|
219 |
FeatureStore allResults = createDBFAllResults(); |
220 |
|
221 |
// Create Layer select results
|
222 |
FeatureStore selResults = createGeocodingResultsLayer(); |
223 |
fillSelectedResultsStore(selResults, allResults); |
224 |
} |
225 |
|
226 |
/**
|
227 |
* geocoding Massive
|
228 |
*
|
229 |
* @throws DataException
|
230 |
*/
|
231 |
private FeatureStore createDBFAllResults() throws DataException { |
232 |
|
233 |
// File dbfFile = File.createTempFile("allresults", "dbf", new
|
234 |
// File("c:/geoco"));
|
235 |
|
236 |
File dbfFile = new File("c:/geoco/allresults.dbf"); |
237 |
|
238 |
FeatureStore store = null;
|
239 |
DataManager manager = DALLocator.getDataManager(); |
240 |
|
241 |
if (dbfFile != null) { |
242 |
// build DBF store
|
243 |
File parentfile = dbfFile.getParentFile();
|
244 |
|
245 |
FilesystemServerExplorerParameters exParam = null;
|
246 |
try {
|
247 |
exParam = (FilesystemServerExplorerParameters) manager |
248 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
249 |
|
250 |
exParam.setRoot(parentfile.getAbsolutePath()); |
251 |
|
252 |
DataServerExplorer serverExplorer = manager |
253 |
.createServerExplorer(exParam); |
254 |
|
255 |
NewDataStoreParameters newParams = serverExplorer |
256 |
.getAddParameters(DBFStoreProvider.NAME); |
257 |
((FilesystemStoreParameters) newParams).setFile(dbfFile); |
258 |
EditableFeatureType featureType = generateFeatureTypeAllResults(store, listResults |
259 |
.get(0));
|
260 |
((DBFNewStoreParameters) newParams) |
261 |
.setDefaultFeatureType(featureType); |
262 |
serverExplorer.add(newParams, true);
|
263 |
|
264 |
// fill DBF store
|
265 |
int max = 10; |
266 |
|
267 |
DBFStoreParameters dbfParameters = (DBFStoreParameters) manager |
268 |
.createStoreParameters(DBFStoreProvider.NAME); |
269 |
dbfParameters.setFile(dbfFile); |
270 |
|
271 |
store = (FeatureStore) manager.createStore(dbfParameters); |
272 |
store.edit(); |
273 |
|
274 |
int id = 0; |
275 |
int idres = 0; |
276 |
|
277 |
Integer[] sels = { 0, 0, 0, 0, 0, 0 }; |
278 |
for (Set<GeocodingResult> set : listResults) { |
279 |
int sel = sels[idres];
|
280 |
int i = 0; |
281 |
int selec = 0; |
282 |
for (GeocodingResult res : set) {
|
283 |
if (i >= max) {
|
284 |
break;
|
285 |
} |
286 |
EditableFeature feature = store.createNewFeature(); |
287 |
// FIRST fields
|
288 |
feature.setInt("gID", id);
|
289 |
feature.setInt("gID_RESUL", idres);
|
290 |
if (selec == sel) {
|
291 |
feature.setInt("gSELECT", 1); |
292 |
} else {
|
293 |
feature.setInt("gSELECT", 0); |
294 |
} |
295 |
feature.setDouble("gSCORE", res.getScore());
|
296 |
Point pto = (Point) res.getGeometry(); |
297 |
feature.setDouble("gX", pto.getX());
|
298 |
feature.setDouble("gY", pto.getY());
|
299 |
// Dynamic address fields
|
300 |
List<AddressComponent> comps = getListAddressElements(res
|
301 |
.getAddress()); |
302 |
for (AddressComponent comp : comps) {
|
303 |
feature.setString(comp.getKeyElement(), comp |
304 |
.getValue()); |
305 |
} |
306 |
store.insert(feature); |
307 |
id++; |
308 |
i++; |
309 |
selec++; |
310 |
} |
311 |
idres++; |
312 |
} |
313 |
store.finishEditing(); |
314 |
store.dispose(); |
315 |
|
316 |
} catch (Exception e) { |
317 |
log.error("Creating dbf store", e);
|
318 |
} |
319 |
} |
320 |
assertTrue(dbfFile.exists()); |
321 |
return store;
|
322 |
} |
323 |
|
324 |
/**
|
325 |
* get pattern
|
326 |
*
|
327 |
* @return
|
328 |
*/
|
329 |
private Patterngeocoding getPattern() {
|
330 |
|
331 |
assertNotNull(dataManager); |
332 |
dataManager.registerDefaultEvaluator(SQLJEPEvaluator.class); |
333 |
|
334 |
Patterngeocoding pat = new DefaultPatterngeocoding();
|
335 |
|
336 |
try {
|
337 |
pat.setPatternName("SimpleCentroidLines");
|
338 |
|
339 |
GeocodingSource source = new DefaultGeocodingSource();
|
340 |
source.setLayerSource(streetsStore); |
341 |
|
342 |
AbstractGeocodingStyle style = new SimpleCentroid();
|
343 |
FeatureType ftype = streetsStore.getDefaultFeatureType(); |
344 |
Literal relations = new DefaultLiteral();
|
345 |
relations.add(new DefaultRelationsComponent("Calle","STREET_NAM")); |
346 |
|
347 |
style.setRelationsLiteral(relations); |
348 |
source.setStyle(style); |
349 |
|
350 |
pat.setSource(source); |
351 |
|
352 |
} catch (Exception e) { |
353 |
log.error("Building a pattern", e);
|
354 |
} |
355 |
|
356 |
return pat;
|
357 |
} |
358 |
|
359 |
private List<Address> getAddresses() { |
360 |
List<Address> list = new ArrayList<Address>(); |
361 |
try {
|
362 |
FeatureSet features = masStore.getFeatureSet(); |
363 |
for (int i = 0; i < features.getSize(); i++) { |
364 |
list.add(getTableAddress(i)); |
365 |
} |
366 |
} catch (Exception e) { |
367 |
log.error("", e);
|
368 |
} |
369 |
|
370 |
return list;
|
371 |
|
372 |
} |
373 |
|
374 |
public Address getTableAddress(int row) { |
375 |
|
376 |
Address address = null;
|
377 |
|
378 |
try {
|
379 |
FeatureType type = masStore.getDefaultFeatureType(); |
380 |
FeatureAttributeDescriptor nameDesc = type |
381 |
.getAttributeDescriptor("tcalle");
|
382 |
|
383 |
// Get store from Gmodel and the feature
|
384 |
FeatureSet features = null;
|
385 |
Feature feature = null;
|
386 |
|
387 |
features = masStore.getFeatureSet(); |
388 |
Iterator<Feature> it = features.iterator(row);
|
389 |
feature = it.next(); |
390 |
|
391 |
// Create the address
|
392 |
address = new DefaultAddress();
|
393 |
DefaultLiteral literal = new DefaultLiteral();
|
394 |
|
395 |
for (int i = 0; i < features.getSize(); i++) { |
396 |
if (row == i) {
|
397 |
String key = "calle"; |
398 |
Object obj = feature.get(nameDesc.getName());
|
399 |
String value = obj.toString();
|
400 |
literal.add(new DefaultAddressComponent(key, value));
|
401 |
} |
402 |
|
403 |
} |
404 |
address.setMainLiteral(literal); |
405 |
|
406 |
} catch (DataException e) {
|
407 |
log.error("Get the feature of FeatureStore", e);
|
408 |
} |
409 |
|
410 |
return address;
|
411 |
} |
412 |
|
413 |
/**
|
414 |
* Build feature type dbf all results
|
415 |
*
|
416 |
* @return
|
417 |
* @throws DataException
|
418 |
*/
|
419 |
private EditableFeatureType generateFeatureTypeAllResults(FeatureStore store,
|
420 |
Set<GeocodingResult> result) throws DataException { |
421 |
|
422 |
boolean compose = false; |
423 |
boolean cross = true; |
424 |
|
425 |
// address fields
|
426 |
Address address = null;
|
427 |
for (GeocodingResult res : result) {
|
428 |
address = res.getAddress(); |
429 |
break;
|
430 |
} |
431 |
Literal mainLiteral = address.getMainLiteral(); |
432 |
int cant = mainLiteral.size();
|
433 |
String[] fields = new String[cant]; |
434 |
int i = 0; |
435 |
for (Object obj : mainLiteral) { |
436 |
AddressComponent aComp = (AddressComponent) obj; |
437 |
fields[i] = aComp.getKeyElement(); |
438 |
i++; |
439 |
} |
440 |
if (address instanceof ComposedAddress) { |
441 |
compose = true;
|
442 |
ComposedAddress caddress = (ComposedAddress) address; |
443 |
List<Literal> inter = caddress.getIntersectionLiterals();
|
444 |
if (inter.size() == 2) { |
445 |
cross = false;
|
446 |
} |
447 |
} |
448 |
|
449 |
EditableFeatureType eFType = store.getDefaultFeatureType().getEditable(); |
450 |
eFType.add("gID", DataTypes.INT).setSize(10); |
451 |
eFType.add("gID_RESUL", DataTypes.INT).setSize(10); |
452 |
eFType.add("gSELECT", DataTypes.INT).setSize(10); |
453 |
eFType.add("gSCORE", DataTypes.DOUBLE).setSize(10); |
454 |
eFType.add("gX", DataTypes.DOUBLE).setSize(14); |
455 |
eFType.add("gY", DataTypes.DOUBLE).setSize(14); |
456 |
|
457 |
// no compose address
|
458 |
if (!compose) {
|
459 |
for (String field : fields) { |
460 |
eFType.add(field, DataTypes.STRING).setSize(20);
|
461 |
} |
462 |
} |
463 |
// compose address
|
464 |
else {
|
465 |
for (String field : fields) { |
466 |
eFType.add(field + "_1", DataTypes.STRING).setSize(20); |
467 |
} |
468 |
for (String field : fields) { |
469 |
eFType.add(field + "_2", DataTypes.STRING).setSize(20); |
470 |
} |
471 |
// compose between address
|
472 |
if (!cross) {
|
473 |
for (String field : fields) { |
474 |
eFType.add(field + "_3", DataTypes.STRING).setSize(20); |
475 |
} |
476 |
} |
477 |
} |
478 |
return eFType;
|
479 |
} |
480 |
|
481 |
/**
|
482 |
* get list address elements
|
483 |
*
|
484 |
* @param address
|
485 |
* @return
|
486 |
*/
|
487 |
private List<AddressComponent> getListAddressElements(Address address) { |
488 |
|
489 |
List<AddressComponent> comps = new ArrayList<AddressComponent>(); |
490 |
Literal mainLiteral = address.getMainLiteral(); |
491 |
|
492 |
for (Object obj : mainLiteral) { |
493 |
AddressComponent aComp = (AddressComponent) obj; |
494 |
comps.add(aComp); |
495 |
} |
496 |
if (address instanceof ComposedAddress) { |
497 |
ComposedAddress caddress = (ComposedAddress) address; |
498 |
List<Literal> inter = caddress.getIntersectionLiterals();
|
499 |
if (inter.size() == 1) { |
500 |
Literal seclit = inter.get(0);
|
501 |
for (Object obj : seclit) { |
502 |
AddressComponent aComp = (AddressComponent) obj; |
503 |
comps.add(aComp); |
504 |
} |
505 |
} |
506 |
if (inter.size() == 2) { |
507 |
Literal thilit = inter.get(1);
|
508 |
for (Object obj : thilit) { |
509 |
AddressComponent aComp = (AddressComponent) obj; |
510 |
comps.add(aComp); |
511 |
} |
512 |
} |
513 |
} |
514 |
return comps;
|
515 |
} |
516 |
|
517 |
/**
|
518 |
*
|
519 |
* @param shpFile
|
520 |
* @return
|
521 |
*/
|
522 |
private FeatureStore createGeocodingResultsLayer() {
|
523 |
|
524 |
FeatureStore lyrstore = null;
|
525 |
|
526 |
// File shpFile = File.createTempFile("shpresults", "shp", new
|
527 |
// File("c:/geoco"));
|
528 |
|
529 |
File shpFile = new File("c:/geoco/shpresults.shp"); |
530 |
|
531 |
FLyrVect lyr = null;
|
532 |
FilesystemServerExplorerParameters explorerParam = null;
|
533 |
|
534 |
DataManager manager = DALLocator.getDataManager(); |
535 |
|
536 |
File directory = shpFile.getParentFile();
|
537 |
|
538 |
try {
|
539 |
explorerParam = (FilesystemServerExplorerParameters) manager |
540 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
541 |
explorerParam.setRoot(directory.getAbsolutePath()); |
542 |
|
543 |
DataServerExplorer serverExplorer = manager |
544 |
.createServerExplorer(explorerParam); |
545 |
|
546 |
SHPNewStoreParameters newShpParams = (SHPNewStoreParameters) serverExplorer |
547 |
.getAddParameters(SHPStoreProvider.NAME); |
548 |
newShpParams.setSHPFileName(shpFile.getName()); |
549 |
newShpParams.setFile(shpFile); |
550 |
|
551 |
EditableFeatureType featureType = generateFeatureTypeSelectedResult(lyrstore); |
552 |
newShpParams.setDefaultFeatureType(featureType); |
553 |
serverExplorer.add(newShpParams, true);
|
554 |
|
555 |
lyrstore = (FeatureStore) dataManager.createStore(newShpParams); |
556 |
|
557 |
// LayerFactory factory = LayerFactory.getInstance();
|
558 |
// String name = shpFile.getName();
|
559 |
// lyr = (FLyrVect) factory.createLayer(name, newShpParams);
|
560 |
// lyrstore = lyr.getFeatureStore();
|
561 |
|
562 |
} catch (Exception e) { |
563 |
log.error("ERROR building FLayer");
|
564 |
} |
565 |
|
566 |
return lyrstore;
|
567 |
} |
568 |
|
569 |
/**
|
570 |
* Build feature type of the selected results store
|
571 |
*
|
572 |
* @return
|
573 |
* @throws DataException
|
574 |
*/
|
575 |
private EditableFeatureType generateFeatureTypeSelectedResult(FeatureStore store) throws DataException { |
576 |
|
577 |
EditableFeatureType eFType = store.getDefaultFeatureType().getEditable(); |
578 |
|
579 |
eFType.add("gID_RESUL", DataTypes.INT).setSize(10); |
580 |
eFType.add("id", DataTypes.STRING).setSize(10); |
581 |
eFType.add("gSCORE", DataTypes.DOUBLE).setSize(10); |
582 |
eFType.add("gX", DataTypes.DOUBLE).setSize(14); |
583 |
eFType.add("gY", DataTypes.DOUBLE).setSize(14); |
584 |
// GEOM field
|
585 |
eFType.add("gGEOMETRY", DataTypes.GEOMETRY).setSize(14); |
586 |
eFType.setDefaultGeometryAttributeName("gGEOMETRY");
|
587 |
|
588 |
return eFType;
|
589 |
} |
590 |
|
591 |
/**
|
592 |
* Fill selected results store
|
593 |
*
|
594 |
* @param newstore
|
595 |
* @throws DataException
|
596 |
* @throws CreateGeometryException
|
597 |
*/
|
598 |
private void fillSelectedResultsStore(FeatureStore newstore, |
599 |
FeatureStore allResults) throws DataException,
|
600 |
CreateGeometryException { |
601 |
|
602 |
Integer[] sels = { 0, 0, 0, 0, 0, 0 }; |
603 |
|
604 |
newstore.edit(); |
605 |
int i = 0; |
606 |
for (Set<GeocodingResult> set : listResults) { |
607 |
int sel = sels[i];
|
608 |
|
609 |
GeocodingResult resu = null;
|
610 |
int j = 0; |
611 |
for (GeocodingResult res : set) {
|
612 |
if (j == sel) {
|
613 |
resu = res; |
614 |
break;
|
615 |
} |
616 |
j++; |
617 |
} |
618 |
|
619 |
EditableFeature feature = newstore.createNewFeature(); |
620 |
|
621 |
String fieldname = "id"; |
622 |
// feature.setInt(GeocodingTags.gID, i);
|
623 |
|
624 |
if (resu != null) { |
625 |
|
626 |
FeatureSet feats = allResults.getFeatureSet(); |
627 |
Iterator<Feature> it = feats.iterator(i);
|
628 |
Feature tableFeat = it.next(); |
629 |
Object obj = tableFeat.get(fieldname);
|
630 |
|
631 |
feature.setInt("gID_RESUL", i);
|
632 |
|
633 |
feature.set(fieldname, obj); |
634 |
|
635 |
feature.setDouble("gSCORE", resu.getScore());
|
636 |
Point pto = (Point) resu.getGeometry(); |
637 |
feature.setDouble("gX", pto.getX());
|
638 |
feature.setDouble("gY", pto.getY());
|
639 |
GeometryManager geomManager = GeometryLocator |
640 |
.getGeometryManager(); |
641 |
Point geom = (Point) geomManager.createPoint(pto.getX(), pto |
642 |
.getY(), Geometry.SUBTYPES.GEOM2D); |
643 |
|
644 |
feature.setGeometry("gGEOMETRY", geom);
|
645 |
} |
646 |
newstore.insert(feature); |
647 |
i++; |
648 |
} |
649 |
newstore.finishEditing(); |
650 |
newstore.dispose(); |
651 |
} |
652 |
|
653 |
} |