svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libGeocoding / src-test / org / gvsig / geocoding / massive / TestMassiveGeocoding.java @ 28375
History | View | Annotate | Download (18.6 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.feature.impl.DefaultEditableFeatureType; |
54 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
55 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
56 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
57 |
import org.gvsig.fmap.dal.store.dbf.DBFNewStoreParameters; |
58 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters; |
59 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider; |
60 |
import org.gvsig.fmap.dal.store.shp.SHPLibrary; |
61 |
import org.gvsig.fmap.dal.store.shp.SHPNewStoreParameters; |
62 |
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters; |
63 |
import org.gvsig.fmap.dal.store.shp.SHPStoreProvider; |
64 |
import org.gvsig.fmap.geom.Geometry; |
65 |
import org.gvsig.fmap.geom.GeometryLibrary; |
66 |
import org.gvsig.fmap.geom.GeometryLocator; |
67 |
import org.gvsig.fmap.geom.GeometryManager; |
68 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
69 |
import org.gvsig.fmap.geom.primitive.Point; |
70 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
71 |
import org.gvsig.geocoding.Geocoder; |
72 |
import org.gvsig.geocoding.GeocodingLibrary; |
73 |
import org.gvsig.geocoding.GeocodingLocator; |
74 |
import org.gvsig.geocoding.address.Address; |
75 |
import org.gvsig.geocoding.address.AddressComponent; |
76 |
import org.gvsig.geocoding.address.ComposedAddress; |
77 |
import org.gvsig.geocoding.address.Literal; |
78 |
import org.gvsig.geocoding.address.impl.DefaultAddress; |
79 |
import org.gvsig.geocoding.address.impl.DefaultAddressComponent; |
80 |
import org.gvsig.geocoding.address.impl.DefaultLiteral; |
81 |
import org.gvsig.geocoding.address.impl.DefaultRelationsComponent; |
82 |
import org.gvsig.geocoding.impl.DataGeocoderImpl; |
83 |
import org.gvsig.geocoding.impl.DefaultGeocodingLibrary; |
84 |
import org.gvsig.geocoding.pattern.GeocodingSource; |
85 |
import org.gvsig.geocoding.pattern.Patterngeocoding; |
86 |
import org.gvsig.geocoding.pattern.impl.DefaultGeocodingSource; |
87 |
import org.gvsig.geocoding.pattern.impl.DefaultPatterngeocoding; |
88 |
import org.gvsig.geocoding.result.GeocodingResult; |
89 |
import org.gvsig.geocoding.styles.AbstractGeocodingStyle; |
90 |
import org.gvsig.geocoding.styles.impl.SimpleCentroid; |
91 |
import org.gvsig.tools.ToolsLibrary; |
92 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
93 |
import org.gvsig.tools.locator.Library; |
94 |
import org.slf4j.Logger; |
95 |
import org.slf4j.LoggerFactory; |
96 |
|
97 |
/**
|
98 |
* Test
|
99 |
*
|
100 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
101 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
102 |
*/
|
103 |
|
104 |
public class TestMassiveGeocoding extends TestCase { |
105 |
|
106 |
private static final Logger log = LoggerFactory |
107 |
.getLogger(TestMassiveGeocoding.class); |
108 |
|
109 |
private DataManager dataManager = null; |
110 |
private FeatureStore masStore = null; |
111 |
private FeatureStore streetsStore = null; |
112 |
|
113 |
private Patterngeocoding pat = null; |
114 |
private List<Set<GeocodingResult>> listResults; |
115 |
|
116 |
public TestMassiveGeocoding() {
|
117 |
listResults = new ArrayList<Set<GeocodingResult>>(); |
118 |
|
119 |
try {
|
120 |
Library tools = new ToolsLibrary();
|
121 |
tools.initialize(); |
122 |
tools.postInitialize(); |
123 |
|
124 |
Library dlib = new DALLibrary();
|
125 |
dlib.initialize(); |
126 |
dlib.postInitialize(); |
127 |
|
128 |
Library libFile = new DALFileLibrary();
|
129 |
libFile.initialize(); |
130 |
libFile.postInitialize(); |
131 |
|
132 |
Library lib = new GeometryLibrary();
|
133 |
lib.initialize(); |
134 |
lib.postInitialize(); |
135 |
|
136 |
Library shpLib = new SHPLibrary();
|
137 |
shpLib.initialize(); |
138 |
shpLib.postInitialize(); |
139 |
|
140 |
Library geocoLib = new DefaultGeocodingLibrary();
|
141 |
geocoLib.initialize(); |
142 |
geocoLib.postInitialize(); |
143 |
|
144 |
} catch (Exception e) { |
145 |
e.printStackTrace(); |
146 |
} |
147 |
|
148 |
dataManager = DALLocator.getDataManager(); |
149 |
|
150 |
try {
|
151 |
// prov file
|
152 |
File prov = new File("./test-data/massive/streetsmassive.dbf"); |
153 |
assertTrue(prov.exists()); |
154 |
DBFStoreParameters provParam = (DBFStoreParameters) dataManager |
155 |
.createStoreParameters(DBFStoreProvider.NAME); |
156 |
provParam.setFile(prov); |
157 |
masStore = (FeatureStore) dataManager.createStore(provParam); |
158 |
assertNotNull(masStore); |
159 |
} catch (Exception e) { |
160 |
log.error("Getting massivestreets.dbf store", e);
|
161 |
} |
162 |
try {
|
163 |
// streets file
|
164 |
File streets = new File("./test-data/geocoder/streets.shp"); |
165 |
assertTrue(streets.exists()); |
166 |
SHPStoreParameters strParam = (SHPStoreParameters) dataManager |
167 |
.createStoreParameters(SHPStoreProvider.NAME); |
168 |
strParam.setFile(streets); |
169 |
streetsStore = (FeatureStore) dataManager.createStore(strParam); |
170 |
assertNotNull(streetsStore); |
171 |
|
172 |
} catch (Exception e) { |
173 |
log.error("Getting streets.shp store", e);
|
174 |
} |
175 |
|
176 |
// Get ppatern
|
177 |
pat = getPattern(); |
178 |
} |
179 |
|
180 |
/**
|
181 |
* setUP
|
182 |
*/
|
183 |
public void setUp() { |
184 |
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* tearDown
|
189 |
*/
|
190 |
public void tearDown() { |
191 |
|
192 |
} |
193 |
|
194 |
/**
|
195 |
* geocoding Massive
|
196 |
*
|
197 |
* @throws DataException
|
198 |
* @throws CreateGeometryException
|
199 |
*/
|
200 |
public void testMassive() throws DataException, CreateGeometryException { |
201 |
|
202 |
Geocoder geocoder = GeocodingLocator.getInstance().getGeocoder(); |
203 |
((DataGeocoderImpl) geocoder).setPattern(pat); |
204 |
|
205 |
// Get addresses
|
206 |
List<Address> addresses = getAddresses();
|
207 |
|
208 |
for (Address addr : addresses) {
|
209 |
Set<GeocodingResult> results = null; |
210 |
try {
|
211 |
results = geocoder.geocode(addr); |
212 |
} catch (Exception e) { |
213 |
log.error("Geocoding", e);
|
214 |
} |
215 |
listResults.add(results); |
216 |
} |
217 |
assertEquals(6, listResults.size());
|
218 |
|
219 |
// Create DBF file
|
220 |
FeatureStore allResults = createDBFAllResults(); |
221 |
|
222 |
// Create Layer select results
|
223 |
FeatureStore selResults = createGeocodingResultsLayer(); |
224 |
fillSelectedResultsStore(selResults, allResults); |
225 |
} |
226 |
|
227 |
/**
|
228 |
* geocoding Massive
|
229 |
*
|
230 |
* @throws DataException
|
231 |
*/
|
232 |
private FeatureStore createDBFAllResults() throws DataException { |
233 |
|
234 |
// File dbfFile = File.createTempFile("allresults", "dbf", new
|
235 |
// File("c:/geoco"));
|
236 |
|
237 |
File dbfFile = new File("c:/geoco/allresults.dbf"); |
238 |
|
239 |
FeatureStore store = null;
|
240 |
DataManager manager = DALLocator.getDataManager(); |
241 |
|
242 |
if (dbfFile != null) { |
243 |
// build DBF store
|
244 |
File parentfile = dbfFile.getParentFile();
|
245 |
|
246 |
FilesystemServerExplorerParameters exParam = null;
|
247 |
try {
|
248 |
exParam = (FilesystemServerExplorerParameters) manager |
249 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
250 |
|
251 |
exParam.setRoot(parentfile.getAbsolutePath()); |
252 |
|
253 |
DataServerExplorer serverExplorer = manager |
254 |
.createServerExplorer(exParam); |
255 |
|
256 |
NewDataStoreParameters newParams = serverExplorer |
257 |
.getAddParameters(DBFStoreProvider.NAME); |
258 |
((FilesystemStoreParameters) newParams).setFile(dbfFile); |
259 |
EditableFeatureType featureType = generateFeatureTypeAllResults(listResults |
260 |
.get(0));
|
261 |
((DBFNewStoreParameters) newParams) |
262 |
.setDefaultFeatureType(featureType); |
263 |
serverExplorer.add(newParams, true);
|
264 |
|
265 |
// fill DBF store
|
266 |
int max = 10; |
267 |
|
268 |
DBFStoreParameters dbfParameters = (DBFStoreParameters) manager |
269 |
.createStoreParameters(DBFStoreProvider.NAME); |
270 |
dbfParameters.setFile(dbfFile); |
271 |
|
272 |
store = (FeatureStore) manager.createStore(dbfParameters); |
273 |
store.edit(); |
274 |
|
275 |
int id = 0; |
276 |
int idres = 0; |
277 |
|
278 |
Integer[] sels = { 0, 0, 0, 0, 0, 0 }; |
279 |
for (Set<GeocodingResult> set : listResults) { |
280 |
int sel = sels[idres];
|
281 |
int i = 0; |
282 |
int selec = 0; |
283 |
for (GeocodingResult res : set) {
|
284 |
if (i >= max) {
|
285 |
break;
|
286 |
} |
287 |
EditableFeature feature = store.createNewFeature(); |
288 |
// FIRST fields
|
289 |
feature.setInt("gID", id);
|
290 |
feature.setInt("gID_RESUL", idres);
|
291 |
if (selec == sel) {
|
292 |
feature.setInt("gSELECT", 1); |
293 |
} else {
|
294 |
feature.setInt("gSELECT", 0); |
295 |
} |
296 |
feature.setDouble("gSCORE", res.getScore());
|
297 |
Point pto = (Point) res.getGeometry(); |
298 |
feature.setDouble("gX", pto.getX());
|
299 |
feature.setDouble("gY", pto.getY());
|
300 |
// Dynamic address fields
|
301 |
List<AddressComponent> comps = getListAddressElements(res
|
302 |
.getAddress()); |
303 |
for (AddressComponent comp : comps) {
|
304 |
feature.setString(comp.getKeyElement(), comp |
305 |
.getValue()); |
306 |
} |
307 |
store.insert(feature); |
308 |
id++; |
309 |
i++; |
310 |
selec++; |
311 |
} |
312 |
idres++; |
313 |
} |
314 |
store.finishEditing(); |
315 |
store.dispose(); |
316 |
|
317 |
} catch (Exception e) { |
318 |
log.error("Creating dbf store", e);
|
319 |
} |
320 |
} |
321 |
assertTrue(dbfFile.exists()); |
322 |
return store;
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* get pattern
|
327 |
*
|
328 |
* @return
|
329 |
*/
|
330 |
private Patterngeocoding getPattern() {
|
331 |
|
332 |
assertNotNull(dataManager); |
333 |
dataManager.registerDefaultEvaluator(SQLJEPEvaluator.class); |
334 |
|
335 |
Patterngeocoding pat = new DefaultPatterngeocoding();
|
336 |
|
337 |
try {
|
338 |
pat.setPatternName("SimpleCentroidLines");
|
339 |
|
340 |
GeocodingSource source = new DefaultGeocodingSource();
|
341 |
source.setLayerSource(streetsStore); |
342 |
|
343 |
AbstractGeocodingStyle style = new SimpleCentroid();
|
344 |
FeatureType ftype = streetsStore.getDefaultFeatureType(); |
345 |
Literal relations = new DefaultLiteral();
|
346 |
relations.add(new DefaultRelationsComponent("Calle","STREET_NAM")); |
347 |
|
348 |
style.setRelationsLiteral(relations); |
349 |
source.setStyle(style); |
350 |
|
351 |
pat.setSource(source); |
352 |
|
353 |
} catch (Exception e) { |
354 |
log.error("Building a pattern", e);
|
355 |
} |
356 |
|
357 |
return pat;
|
358 |
} |
359 |
|
360 |
private List<Address> getAddresses() { |
361 |
List<Address> list = new ArrayList<Address>(); |
362 |
try {
|
363 |
FeatureSet features = masStore.getFeatureSet(); |
364 |
for (int i = 0; i < features.getSize(); i++) { |
365 |
list.add(getTableAddress(i)); |
366 |
} |
367 |
} catch (Exception e) { |
368 |
log.error("", e);
|
369 |
} |
370 |
|
371 |
return list;
|
372 |
|
373 |
} |
374 |
|
375 |
public Address getTableAddress(int row) { |
376 |
|
377 |
Address address = null;
|
378 |
|
379 |
try {
|
380 |
FeatureType type = masStore.getDefaultFeatureType(); |
381 |
FeatureAttributeDescriptor nameDesc = type |
382 |
.getAttributeDescriptor("tcalle");
|
383 |
|
384 |
// Get store from Gmodel and the feature
|
385 |
FeatureSet features = null;
|
386 |
Feature feature = null;
|
387 |
|
388 |
features = masStore.getFeatureSet(); |
389 |
Iterator<Feature> it = features.iterator(row);
|
390 |
feature = it.next(); |
391 |
|
392 |
// Create the address
|
393 |
address = new DefaultAddress();
|
394 |
DefaultLiteral literal = new DefaultLiteral();
|
395 |
|
396 |
for (int i = 0; i < features.getSize(); i++) { |
397 |
if (row == i) {
|
398 |
String key = "calle"; |
399 |
Object obj = feature.get(nameDesc.getName());
|
400 |
String value = obj.toString();
|
401 |
literal.add(new DefaultAddressComponent(key, value));
|
402 |
} |
403 |
|
404 |
} |
405 |
address.setMainLiteral(literal); |
406 |
|
407 |
} catch (DataException e) {
|
408 |
log.error("Get the feature of FeatureStore", e);
|
409 |
} |
410 |
|
411 |
return address;
|
412 |
} |
413 |
|
414 |
/**
|
415 |
* Build feature type dbf all results
|
416 |
*
|
417 |
* @return
|
418 |
*/
|
419 |
private EditableFeatureType generateFeatureTypeAllResults(
|
420 |
Set<GeocodingResult> result) {
|
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 = new DefaultEditableFeatureType();
|
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(); |
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 |
*/
|
574 |
private EditableFeatureType generateFeatureTypeSelectedResult() {
|
575 |
|
576 |
EditableFeatureType eFType = new DefaultEditableFeatureType();
|
577 |
|
578 |
eFType.add("gID_RESUL", DataTypes.INT).setSize(10); |
579 |
eFType.add("id", DataTypes.STRING).setSize(10); |
580 |
eFType.add("gSCORE", DataTypes.DOUBLE).setSize(10); |
581 |
eFType.add("gX", DataTypes.DOUBLE).setSize(14); |
582 |
eFType.add("gY", DataTypes.DOUBLE).setSize(14); |
583 |
// GEOM field
|
584 |
eFType.add("gGEOMETRY", DataTypes.GEOMETRY).setSize(14); |
585 |
eFType.setDefaultGeometryAttributeName("gGEOMETRY");
|
586 |
|
587 |
return eFType;
|
588 |
} |
589 |
|
590 |
/**
|
591 |
* Fill selected results store
|
592 |
*
|
593 |
* @param newstore
|
594 |
* @throws DataException
|
595 |
* @throws CreateGeometryException
|
596 |
*/
|
597 |
private void fillSelectedResultsStore(FeatureStore newstore, |
598 |
FeatureStore allResults) throws DataException,
|
599 |
CreateGeometryException { |
600 |
|
601 |
Integer[] sels = { 0, 0, 0, 0, 0, 0 }; |
602 |
|
603 |
newstore.edit(); |
604 |
int i = 0; |
605 |
for (Set<GeocodingResult> set : listResults) { |
606 |
int sel = sels[i];
|
607 |
|
608 |
GeocodingResult resu = null;
|
609 |
int j = 0; |
610 |
for (GeocodingResult res : set) {
|
611 |
if (j == sel) {
|
612 |
resu = res; |
613 |
break;
|
614 |
} |
615 |
j++; |
616 |
} |
617 |
|
618 |
EditableFeature feature = newstore.createNewFeature(); |
619 |
|
620 |
String fieldname = "id"; |
621 |
// feature.setInt(GeocodingTags.gID, i);
|
622 |
|
623 |
if (resu != null) { |
624 |
|
625 |
FeatureSet feats = allResults.getFeatureSet(); |
626 |
Iterator<Feature> it = feats.iterator(i);
|
627 |
Feature tableFeat = it.next(); |
628 |
Object obj = tableFeat.get(fieldname);
|
629 |
|
630 |
feature.setInt("gID_RESUL", i);
|
631 |
|
632 |
feature.set(fieldname, obj); |
633 |
|
634 |
feature.setDouble("gSCORE", resu.getScore());
|
635 |
Point pto = (Point) resu.getGeometry(); |
636 |
feature.setDouble("gX", pto.getX());
|
637 |
feature.setDouble("gY", pto.getY());
|
638 |
GeometryManager geomManager = GeometryLocator |
639 |
.getGeometryManager(); |
640 |
Point geom = (Point) geomManager.createPoint(pto.getX(), pto |
641 |
.getY(), Geometry.SUBTYPES.GEOM2D); |
642 |
|
643 |
feature.setGeometry("gGEOMETRY", geom);
|
644 |
} |
645 |
newstore.insert(feature); |
646 |
i++; |
647 |
} |
648 |
newstore.finishEditing(); |
649 |
newstore.dispose(); |
650 |
} |
651 |
|
652 |
} |