svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extGeocoding / src / org / gvsig / geocoding / export / MasiveExportThread.java @ 31946
History | View | Annotate | Download (19 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 |
* 2009 Prodevelop S.L main developer
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.geocoding.export; |
29 |
|
30 |
import java.io.File; |
31 |
import java.util.Iterator; |
32 |
import java.util.List; |
33 |
import java.util.Map; |
34 |
import java.util.Set; |
35 |
|
36 |
import javax.swing.JFileChooser; |
37 |
|
38 |
import org.gvsig.andami.PluginServices; |
39 |
import org.gvsig.app.project.Project; |
40 |
import org.gvsig.app.project.ProjectManager; |
41 |
import org.gvsig.app.project.documents.table.TableDocument; |
42 |
import org.gvsig.app.project.documents.table.TableManager; |
43 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
44 |
import org.gvsig.app.project.documents.view.gui.IView; |
45 |
|
46 |
import org.gvsig.fmap.dal.DALLocator; |
47 |
import org.gvsig.fmap.dal.DataManager; |
48 |
import org.gvsig.fmap.dal.DataServerExplorer; |
49 |
import org.gvsig.fmap.dal.DataTypes; |
50 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
51 |
import org.gvsig.fmap.dal.exception.DataException; |
52 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
53 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
54 |
import org.gvsig.fmap.dal.feature.Feature; |
55 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
56 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
57 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
58 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
59 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
60 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
61 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
62 |
import org.gvsig.fmap.dal.store.dbf.DBFNewStoreParameters; |
63 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters; |
64 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider; |
65 |
import org.gvsig.fmap.dal.store.shp.SHPNewStoreParameters; |
66 |
import org.gvsig.fmap.dal.store.shp.SHPStoreProvider; |
67 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
68 |
import org.gvsig.fmap.geom.primitive.Point; |
69 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
70 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
71 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
72 |
import org.gvsig.geocoding.address.Address; |
73 |
import org.gvsig.geocoding.address.ComposedAddress; |
74 |
import org.gvsig.geocoding.address.Literal; |
75 |
import org.gvsig.geocoding.address.impl.DefaultLiteral; |
76 |
import org.gvsig.geocoding.extension.GeocodingController; |
77 |
import org.gvsig.geocoding.result.GeocodingResult; |
78 |
import org.gvsig.geocoding.utils.GeocodingExtTags; |
79 |
import org.gvsig.geocoding.utils.GeocodingUtils; |
80 |
import org.gvsig.tools.ToolsLocator; |
81 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
82 |
import org.gvsig.utils.GenericFileFilter; |
83 |
import org.slf4j.Logger; |
84 |
import org.slf4j.LoggerFactory; |
85 |
|
86 |
/**
|
87 |
* This class generates a Layer with geocoding results and dbf file with all
|
88 |
* results
|
89 |
*
|
90 |
* @author Jorge Gaspar Sanz Salinas (jsanz@prodevelop.es)
|
91 |
* @author Vicente Sanjaime Calvet (vsanjaime@prodevelop.es)
|
92 |
*
|
93 |
*/
|
94 |
|
95 |
public class MasiveExportThread extends Thread { |
96 |
|
97 |
private Logger log = LoggerFactory.getLogger(MasiveExportThread.class); |
98 |
private GeocodingController control = null; |
99 |
|
100 |
/**
|
101 |
* Contructor
|
102 |
*
|
103 |
* @param control
|
104 |
*/
|
105 |
public MasiveExportThread(GeocodingController control) {
|
106 |
super();
|
107 |
this.control = control;
|
108 |
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* Run export process
|
113 |
*/
|
114 |
public void run() { |
115 |
// get file name
|
116 |
File exportFile = getFilesExportResults();
|
117 |
if (exportFile != null) { |
118 |
// Build dbf name
|
119 |
File suffixfile = GeocodingUtils.addSuffixFile(exportFile,
|
120 |
GeocodingExtTags.GEOCODINGALLRESULTS); |
121 |
File dbfFile = GeocodingUtils.addDBFSuffix(suffixfile);
|
122 |
// Create DBF Store Results
|
123 |
FeatureStore dbfStore = createDBFStoreAllResults(dbfFile); |
124 |
// Load dbf all results in gvSIG proyect
|
125 |
TableDocument table = loadTableAllResults(dbfStore, dbfFile); |
126 |
// Build shp name
|
127 |
File shpFile = GeocodingUtils.addSHPSuffix(exportFile);
|
128 |
// create layer
|
129 |
FLyrVect flyr = createGeocodingResultsLayer(shpFile); |
130 |
if (flyr != null) { |
131 |
try {
|
132 |
fillStoreWithSelectedResults(flyr.getFeatureStore()); |
133 |
} catch (Exception e) { |
134 |
log.error("filling store gocoding layer", e);
|
135 |
} |
136 |
// relate table all results to layer
|
137 |
flyr.setProperty(GeocodingExtTags.GEOCODINGPROPERTY, table); |
138 |
// add layer to view
|
139 |
IView view = control.getCurrentView(); |
140 |
FLayers lyrs = view.getMapControl().getMapContext().getLayers(); |
141 |
lyrs.addLayer(flyr); |
142 |
} |
143 |
} |
144 |
} |
145 |
|
146 |
/**
|
147 |
* Create dbf store all results
|
148 |
*
|
149 |
* @param dbfFile
|
150 |
* @return store
|
151 |
*/
|
152 |
private FeatureStore createDBFStoreAllResults(File dbfFile) { |
153 |
|
154 |
FeatureStore store = null;
|
155 |
DataManager manager = DALLocator.getDataManager(); |
156 |
|
157 |
if (dbfFile != null) { |
158 |
|
159 |
// build DBF store
|
160 |
File parentfile = dbfFile.getParentFile();
|
161 |
|
162 |
FilesystemServerExplorerParameters exParam = null;
|
163 |
try {
|
164 |
exParam = (FilesystemServerExplorerParameters) manager |
165 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
166 |
|
167 |
exParam.setRoot(parentfile.getAbsolutePath()); |
168 |
|
169 |
DataServerExplorer serverExplorer = manager |
170 |
.createServerExplorer(exParam); |
171 |
|
172 |
NewDataStoreParameters newDBFParams = serverExplorer |
173 |
.getAddParameters(DBFStoreProvider.NAME); |
174 |
((DBFNewStoreParameters) newDBFParams).setDBFFile(dbfFile); |
175 |
EditableFeatureType featureType = generateFeatureTypeAllResults(newDBFParams); |
176 |
((DBFNewStoreParameters) newDBFParams) |
177 |
.setDefaultFeatureType(featureType.getNotEditableCopy()); |
178 |
|
179 |
serverExplorer.add(newDBFParams, true);
|
180 |
|
181 |
// fill DBF store
|
182 |
int max = control.getGmodel().getPattern().getSettings()
|
183 |
.getResultsNumber(); |
184 |
|
185 |
DBFStoreParameters dbfParameters = (DBFStoreParameters) manager |
186 |
.createStoreParameters(DBFStoreProvider.NAME); |
187 |
dbfParameters.setFile(dbfFile); |
188 |
|
189 |
store = (FeatureStore) manager.createStore(dbfParameters); |
190 |
store.edit(); |
191 |
|
192 |
List<Set<GeocodingResult>> results = control.getGmodel() |
193 |
.getAllResults(); |
194 |
|
195 |
int id = 0; |
196 |
int idres = 0; |
197 |
|
198 |
Integer[] sels = control.getGmodel().getExportElements(); |
199 |
for (Set<GeocodingResult> set : results) { |
200 |
int sel = sels[idres];
|
201 |
int i = 0; |
202 |
int selec = 0; |
203 |
for (GeocodingResult res : set) {
|
204 |
if (i >= max) {
|
205 |
break;
|
206 |
} |
207 |
EditableFeature feature = store.createNewFeature(); |
208 |
// FIRST fields
|
209 |
feature.setInt(GeocodingExtTags.gID, id); |
210 |
feature.setInt(GeocodingExtTags.gID_RESUL, idres); |
211 |
if (selec == sel) {
|
212 |
feature.setInt(GeocodingExtTags.gSELECT, 1);
|
213 |
} else {
|
214 |
feature.setInt(GeocodingExtTags.gSELECT, 0);
|
215 |
} |
216 |
feature.setDouble(GeocodingExtTags.gSCORE, res |
217 |
.getScore()); |
218 |
Point pto = (Point) res.getGeometry(); |
219 |
feature.setDouble(GeocodingExtTags.gX, pto.getX()); |
220 |
feature.setDouble(GeocodingExtTags.gY, pto.getY()); |
221 |
// Dynamic address fields
|
222 |
Literal listLit = getListAddressElements(res |
223 |
.getAddress()); |
224 |
for (Map.Entry<String, String> ele : listLit.entrySet()) { |
225 |
feature.setString(ele.getKey(), ele.getValue()); |
226 |
} |
227 |
|
228 |
store.insert(feature); |
229 |
id++; |
230 |
i++; |
231 |
selec++; |
232 |
} |
233 |
idres++; |
234 |
} |
235 |
store.finishEditing(); |
236 |
store.dispose(); |
237 |
|
238 |
} catch (Exception e) { |
239 |
log.error("Creating dbf store", e);
|
240 |
} |
241 |
} |
242 |
return store;
|
243 |
} |
244 |
|
245 |
// /**
|
246 |
// * Create dbf store all results
|
247 |
// *
|
248 |
// * @param dbfFile
|
249 |
// * @return store
|
250 |
// */
|
251 |
// private FeatureStore createDBFStoreAllResults2(File dbfFile) {
|
252 |
//
|
253 |
// FeatureStore store = null;
|
254 |
// DataManager manager = DALLocator.getDataManager();
|
255 |
//
|
256 |
// if (dbfFile != null) {
|
257 |
// // build DBF store
|
258 |
// File parentfile = dbfFile.getParentFile();
|
259 |
//
|
260 |
// FilesystemServerExplorerParameters exParam = null;
|
261 |
// try {
|
262 |
// exParam = (FilesystemServerExplorerParameters) manager
|
263 |
// .createServerExplorerParameters(FilesystemServerExplorer.NAME);
|
264 |
//
|
265 |
// exParam.setRoot(parentfile.getAbsolutePath());
|
266 |
//
|
267 |
// DataServerExplorer serverExplorer = manager
|
268 |
// .createServerExplorer(exParam);
|
269 |
//
|
270 |
// NewDataStoreParameters newParams = serverExplorer
|
271 |
// .getAddParameters(DBFStoreProvider.NAME);
|
272 |
// ((FilesystemStoreParameters) newParams).setFile(dbfFile);
|
273 |
// EditableFeatureType featureType = generateFeatureTypeAllResults();
|
274 |
// ((NewFeatureStoreParameters) newParams)
|
275 |
// .setDefaultFeatureType(featureType);
|
276 |
// serverExplorer.add(newParams, true);
|
277 |
//
|
278 |
// // fill DBF store
|
279 |
// int max = control.getGmodel().getPattern().getSettings()
|
280 |
// .getResultsNumber();
|
281 |
//
|
282 |
// DBFStoreParameters dbfParameters = (DBFStoreParameters) manager
|
283 |
// .createStoreParameters(DBFStoreProvider.NAME);
|
284 |
// dbfParameters.setFile(dbfFile);
|
285 |
//
|
286 |
// store = (FeatureStore) manager.createStore(dbfParameters);
|
287 |
// store.edit();
|
288 |
//
|
289 |
// List<Set<GeocodingResult>> results = control.getGmodel()
|
290 |
// .getAllResults();
|
291 |
//
|
292 |
// int id = 0;
|
293 |
// int idres = 0;
|
294 |
//
|
295 |
// Integer[] sels = control.getGmodel().getExportElements();
|
296 |
// for (Set<GeocodingResult> set : results) {
|
297 |
// int sel = sels[idres];
|
298 |
// int i = 0;
|
299 |
// int selec = 0;
|
300 |
// for (GeocodingResult res : set) {
|
301 |
// if (i >= max) {
|
302 |
// break;
|
303 |
// }
|
304 |
// EditableFeature feature = store.createNewFeature();
|
305 |
// // FIRST fields
|
306 |
// feature.setInt(GeocodingTags.gID, id);
|
307 |
// feature.setInt(GeocodingTags.gID_RESUL, idres);
|
308 |
// if (selec == sel) {
|
309 |
// feature.setInt(GeocodingTags.gSELECT, 1);
|
310 |
// } else {
|
311 |
// feature.setInt(GeocodingTags.gSELECT, 0);
|
312 |
// }
|
313 |
// feature.setDouble(GeocodingTags.gSCORE, res.getScore());
|
314 |
// Point pto = (Point) res.getGeometry();
|
315 |
// feature.setDouble(GeocodingTags.gX, pto.getX());
|
316 |
// feature.setDouble(GeocodingTags.gY, pto.getY());
|
317 |
// // Dynamic address fields
|
318 |
// List<AddressComponent> comps = getListAddressElements(res
|
319 |
// .getAddress());
|
320 |
// for (AddressComponent comp : comps) {
|
321 |
// feature.setString(comp.getKeyElement(), comp
|
322 |
// .getValue());
|
323 |
// }
|
324 |
// store.insert(feature);
|
325 |
// id++;
|
326 |
// i++;
|
327 |
// selec++;
|
328 |
// }
|
329 |
// idres++;
|
330 |
// }
|
331 |
// store.finishEditing();
|
332 |
// store.dispose();
|
333 |
//
|
334 |
// } catch (Exception e) {
|
335 |
// log.error("Creating dbf store", e);
|
336 |
// }
|
337 |
// }
|
338 |
// return store;
|
339 |
// }
|
340 |
|
341 |
/**
|
342 |
* Build feature type dbf all results
|
343 |
*
|
344 |
* @return
|
345 |
*/
|
346 |
private EditableFeatureType generateFeatureTypeAllResults(
|
347 |
NewDataStoreParameters params) { |
348 |
|
349 |
boolean compose = false; |
350 |
boolean cross = true; |
351 |
|
352 |
// address fields
|
353 |
Set<GeocodingResult> result = control.getGmodel().getAllResults()
|
354 |
.get(0);
|
355 |
Address address = null;
|
356 |
for (GeocodingResult res : result) {
|
357 |
address = res.getAddress(); |
358 |
break;
|
359 |
} |
360 |
Literal mainLiteral = address.getMainLiteral(); |
361 |
int cant = mainLiteral.size();
|
362 |
String[] fields = new String[cant]; |
363 |
int i = 0; |
364 |
for (String key : mainLiteral.keySet()) { |
365 |
fields[i] = key; |
366 |
i++; |
367 |
} |
368 |
if (address instanceof ComposedAddress) { |
369 |
compose = true;
|
370 |
ComposedAddress caddress = (ComposedAddress) address; |
371 |
List<Literal> inter = caddress.getIntersectionLiterals();
|
372 |
if (inter.size() == 2) { |
373 |
cross = false;
|
374 |
} |
375 |
} |
376 |
|
377 |
EditableFeatureType eFType = (EditableFeatureType) ((NewFeatureStoreParameters) params) |
378 |
.getDefaultFeatureType(); |
379 |
eFType.add(GeocodingExtTags.gID, DataTypes.INT).setSize(10);
|
380 |
eFType.add(GeocodingExtTags.gID_RESUL, DataTypes.INT).setSize(10);
|
381 |
eFType.add(GeocodingExtTags.gSELECT, DataTypes.INT).setSize(10);
|
382 |
eFType.add(GeocodingExtTags.gSCORE, DataTypes.DOUBLE).setSize(10);
|
383 |
eFType.add(GeocodingExtTags.gX, DataTypes.DOUBLE).setSize(14);
|
384 |
eFType.add(GeocodingExtTags.gY, DataTypes.DOUBLE).setSize(14);
|
385 |
|
386 |
// no compose address
|
387 |
if (!compose) {
|
388 |
for (String field : fields) { |
389 |
eFType.add(field, DataTypes.STRING).setSize(20);
|
390 |
} |
391 |
} |
392 |
// compose address
|
393 |
else {
|
394 |
for (String field : fields) { |
395 |
eFType.add(field + "_1", DataTypes.STRING).setSize(20); |
396 |
} |
397 |
for (String field : fields) { |
398 |
eFType.add(field + "_2", DataTypes.STRING).setSize(20); |
399 |
} |
400 |
// compose between address
|
401 |
if (!cross) {
|
402 |
for (String field : fields) { |
403 |
eFType.add(field + "_3", DataTypes.STRING).setSize(20); |
404 |
} |
405 |
} |
406 |
} |
407 |
return eFType;
|
408 |
} |
409 |
|
410 |
/**
|
411 |
* get list address elements
|
412 |
*
|
413 |
* @param address
|
414 |
* @return
|
415 |
*/
|
416 |
private Literal getListAddressElements(Address address) {
|
417 |
|
418 |
Literal listLit = new DefaultLiteral();
|
419 |
Literal mainLiteral = address.getMainLiteral(); |
420 |
|
421 |
for (Map.Entry<String, String> ele : mainLiteral.entrySet()) { |
422 |
listLit.put(ele.getKey(), ele.getValue()); |
423 |
} |
424 |
if (address instanceof ComposedAddress) { |
425 |
ComposedAddress caddress = (ComposedAddress) address; |
426 |
List<Literal> inter = caddress.getIntersectionLiterals();
|
427 |
if (inter.size() == 1) { |
428 |
Literal seclit = inter.get(0);
|
429 |
for (Map.Entry<String, String> ele : seclit.entrySet()) { |
430 |
listLit.put(ele.getKey(), ele.getValue()); |
431 |
} |
432 |
} |
433 |
if (inter.size() == 2) { |
434 |
Literal thilit = inter.get(1);
|
435 |
for (Map.Entry<String, String> ele : thilit.entrySet()) { |
436 |
listLit.put(ele.getKey(), ele.getValue()); |
437 |
} |
438 |
|
439 |
} |
440 |
} |
441 |
return listLit;
|
442 |
} |
443 |
|
444 |
/**
|
445 |
* Load in gvSIG the dbf with all results
|
446 |
*
|
447 |
* @param store
|
448 |
* @param file
|
449 |
* @return
|
450 |
*/
|
451 |
private TableDocument loadTableAllResults(FeatureStore store,
|
452 |
File file) {
|
453 |
|
454 |
ProjectManager pdf = ProjectManager.getInstance(); |
455 |
Project proj = pdf.getCurrentProject(); |
456 |
TableManager tmanager = new TableManager();
|
457 |
|
458 |
TableDocument pt = (TableDocument)tmanager.create(); |
459 |
pt.setName(file.getName()); |
460 |
pt.setStore(store); |
461 |
pt.setProject(proj); |
462 |
|
463 |
return pt;
|
464 |
} |
465 |
|
466 |
/**
|
467 |
* Get the file to export the geocoding results process
|
468 |
*
|
469 |
* @return
|
470 |
*/
|
471 |
private File getFilesExportResults() { |
472 |
File thefile = null; |
473 |
JFileChooser jfc = new JFileChooser(); |
474 |
jfc.setDialogTitle(PluginServices.getText(this, "exportresults")); |
475 |
String[] extensions = { "shp" }; |
476 |
jfc.setCurrentDirectory(new File("")); |
477 |
jfc.addChoosableFileFilter(new GenericFileFilter(extensions,
|
478 |
PluginServices.getText(this, "shp_file"))); |
479 |
int returnval = jfc.showSaveDialog((java.awt.Component) PluginServices
|
480 |
.getMainFrame()); |
481 |
if (returnval == JFileChooser.APPROVE_OPTION) { |
482 |
thefile = jfc.getSelectedFile(); |
483 |
log.debug("file opened: " + thefile);
|
484 |
} else {
|
485 |
return null; |
486 |
} |
487 |
if (thefile != null) { |
488 |
thefile = GeocodingUtils.delSHPSuffix(thefile); |
489 |
} |
490 |
return thefile;
|
491 |
} |
492 |
|
493 |
/**
|
494 |
* Fill selected results store
|
495 |
*
|
496 |
* @param newstore
|
497 |
* @throws DataException
|
498 |
* @throws CreateGeometryException
|
499 |
*/
|
500 |
private void fillStoreWithSelectedResults(FeatureStore newstore) |
501 |
throws DataException, CreateGeometryException {
|
502 |
|
503 |
Integer[] sels = control.getGmodel().getExportElements(); |
504 |
List<Set<GeocodingResult>> results = control.getGmodel() |
505 |
.getAllResults(); |
506 |
|
507 |
FeatureStore table = control.getGmodel().getSelectedTableStore(); |
508 |
|
509 |
newstore.edit(); |
510 |
int i = 0; |
511 |
for (Set<GeocodingResult> set : results) { |
512 |
int sel = sels[i];
|
513 |
GeocodingResult result = null;
|
514 |
int j = 0; |
515 |
for (GeocodingResult res : set) {
|
516 |
if (j == sel) {
|
517 |
result = res; |
518 |
break;
|
519 |
} |
520 |
j++; |
521 |
} |
522 |
|
523 |
EditableFeature feature = newstore.createNewFeature(); |
524 |
String fieldname = control.getGmodel().getIdMasiveTable();
|
525 |
|
526 |
if (result != null) { |
527 |
|
528 |
FeatureSet feats = table.getFeatureSet(); |
529 |
Iterator<Feature> it = feats.iterator(i);
|
530 |
Feature tableFeat = it.next(); |
531 |
Object obj = tableFeat.get(fieldname);
|
532 |
|
533 |
Point pto = (Point) result.getGeometry(); |
534 |
// fill fields
|
535 |
feature.setInt(GeocodingExtTags.gID_RESUL, i); |
536 |
feature.set(fieldname, obj); |
537 |
feature.setDouble(GeocodingExtTags.gSCORE, result.getScore()); |
538 |
feature.setDouble(GeocodingExtTags.gX, pto.getX()); |
539 |
feature.setDouble(GeocodingExtTags.gY, pto.getY()); |
540 |
feature.setGeometry(GeocodingExtTags.gGEOMETRY, pto); |
541 |
} |
542 |
newstore.insert(feature); |
543 |
i++; |
544 |
} |
545 |
newstore.dispose(); |
546 |
newstore.finishEditing(); |
547 |
} |
548 |
|
549 |
/**
|
550 |
* Build layer with selected geocoding results
|
551 |
*
|
552 |
* @param shpFile
|
553 |
* @return
|
554 |
*/
|
555 |
private FLyrVect createGeocodingResultsLayer(File shpFile) { |
556 |
|
557 |
FLyrVect lyr = null;
|
558 |
FilesystemServerExplorerParameters explorerParam = null;
|
559 |
|
560 |
DataManager manager = DALLocator.getDataManager(); |
561 |
|
562 |
File directory = shpFile.getParentFile();
|
563 |
|
564 |
try {
|
565 |
explorerParam = (FilesystemServerExplorerParameters) manager |
566 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
567 |
explorerParam.setRoot(directory.getAbsolutePath()); |
568 |
|
569 |
DataServerExplorer serverExplorer = manager |
570 |
.createServerExplorer(explorerParam); |
571 |
|
572 |
SHPNewStoreParameters newShpParams = (SHPNewStoreParameters) serverExplorer |
573 |
.getAddParameters(SHPStoreProvider.NAME); |
574 |
newShpParams.setFile(shpFile); |
575 |
String proj = ((DefaultViewPanel)this.control.getCurrentView()).getProjection().getAbrev(); |
576 |
newShpParams.setSRSID(proj); |
577 |
newShpParams.setDynValue("SRSOriginalParameters", proj);
|
578 |
|
579 |
EditableFeatureType featureType = generateFeatureTypeSelectedResult(); |
580 |
newShpParams.setDefaultFeatureType(featureType); |
581 |
serverExplorer.add(newShpParams, true);
|
582 |
|
583 |
LayerFactory factory = LayerFactory.getInstance(); |
584 |
String name = shpFile.getName();
|
585 |
lyr = (FLyrVect) factory.createLayer(name, newShpParams); |
586 |
|
587 |
} catch (Exception e) { |
588 |
log.error("ERROR building FLayer");
|
589 |
} |
590 |
|
591 |
return lyr;
|
592 |
} |
593 |
|
594 |
/**
|
595 |
* Build feature type of the selected results store
|
596 |
*
|
597 |
* @return
|
598 |
* @throws DataException
|
599 |
*/
|
600 |
private EditableFeatureType generateFeatureTypeSelectedResult()
|
601 |
throws DataException {
|
602 |
|
603 |
String fname = control.getGmodel().getIdMasiveTable();
|
604 |
|
605 |
FeatureStore table = control.getGmodel().getSelectedTableStore(); |
606 |
|
607 |
FeatureAttributeDescriptor desc = table.getDefaultFeatureType() |
608 |
.getAttributeDescriptor(fname); |
609 |
|
610 |
EditableFeatureType eFType = new DefaultEditableFeatureType();
|
611 |
|
612 |
eFType.add(GeocodingExtTags.gID_RESUL, DataTypes.INT).setSize(10);
|
613 |
eFType.add(fname, desc.getDataType()).setSize(desc.getSize()); |
614 |
eFType.add(GeocodingExtTags.gSCORE, DataTypes.DOUBLE).setSize(10);
|
615 |
eFType.add(GeocodingExtTags.gX, DataTypes.DOUBLE).setSize(14);
|
616 |
eFType.add(GeocodingExtTags.gY, DataTypes.DOUBLE).setSize(14);
|
617 |
// GEOM field
|
618 |
eFType.add(GeocodingExtTags.gGEOMETRY, DataTypes.GEOMETRY); |
619 |
eFType.setDefaultGeometryAttributeName(GeocodingExtTags.gGEOMETRY); |
620 |
|
621 |
return eFType;
|
622 |
} |
623 |
|
624 |
} |