svn-gvsig-desktop / trunk / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / fmap / drivers / FMapFeatureArcImsDriver.java @ 8300
History | View | Annotate | Download (25 KB)
1 |
package es.prodevelop.cit.gvsig.arcims.fmap.drivers; |
---|---|
2 |
|
3 |
import java.awt.Rectangle; |
4 |
import java.awt.geom.Rectangle2D; |
5 |
import java.awt.geom.Rectangle2D.Double; |
6 |
import java.io.File; |
7 |
import java.io.IOException; |
8 |
import java.net.ProtocolException; |
9 |
import java.net.URL; |
10 |
import java.util.ArrayList; |
11 |
import java.util.HashMap; |
12 |
import java.util.Random; |
13 |
import java.util.TreeMap; |
14 |
|
15 |
import javax.swing.JFileChooser; |
16 |
|
17 |
import org.apache.log4j.Logger; |
18 |
import org.gvsig.remoteClient.arcims.ArcImsClientP; |
19 |
import org.gvsig.remoteClient.arcims.ArcImsFeatureClient; |
20 |
import org.gvsig.remoteClient.arcims.ArcImsStatus; |
21 |
import org.gvsig.remoteClient.arcims.ArcImsVectStatus; |
22 |
import org.gvsig.remoteClient.arcims.exceptions.ArcImsException; |
23 |
import org.gvsig.remoteClient.arcims.utils.FieldInformation; |
24 |
import org.gvsig.remoteClient.arcims.utils.ServiceInfoTags; |
25 |
import org.gvsig.remoteClient.arcims.utils.ServiceInformationLayerFeatures; |
26 |
import org.gvsig.remoteClient.exceptions.ServerErrorException; |
27 |
import org.gvsig.remoteClient.utils.BoundaryBox; |
28 |
import org.gvsig.remoteClient.wms.ICancellable; |
29 |
|
30 |
import com.hardcode.driverManager.DriverLoadException; |
31 |
import com.hardcode.gdbms.engine.data.DataSource; |
32 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
33 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
34 |
import com.hardcode.gdbms.engine.data.object.ObjectSourceInfo; |
35 |
import com.hardcode.gdbms.engine.instruction.EvaluationException; |
36 |
import com.hardcode.gdbms.engine.instruction.SemanticException; |
37 |
import com.hardcode.gdbms.engine.values.IntValue; |
38 |
import com.hardcode.gdbms.engine.values.Value; |
39 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
40 |
import com.hardcode.gdbms.parser.ParseException; |
41 |
import com.iver.andami.PluginServices; |
42 |
import com.iver.andami.ui.mdiManager.IWindow; |
43 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
44 |
import com.iver.cit.gvsig.fmap.core.FShape; |
45 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
46 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
47 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
48 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
49 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
50 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
51 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
52 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
53 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
54 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
55 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
56 |
import com.iver.cit.gvsig.project.Project; |
57 |
import com.iver.cit.gvsig.project.ProjectFactory; |
58 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
59 |
import com.iver.cit.gvsig.project.documents.view.ProjectView; |
60 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
61 |
|
62 |
import es.prodevelop.cit.gvsig.arcims.fmap.drivers.ArcImsAttributesDataSourceAdapter; |
63 |
import es.prodevelop.cit.gvsig.arcims.fmap.layers.FFeatureLyrArcIMS; |
64 |
import es.prodevelop.cit.gvsig.arcims.gui.wizards.ArcImsWizard; |
65 |
|
66 |
public class FMapFeatureArcImsDriver implements ArcImsDriver, VectorialDriver { |
67 |
|
68 |
private static Logger logger = Logger.getLogger(FMapFeatureArcImsDriver.class.getName()); |
69 |
|
70 |
private ArcImsFeatureClient client;
|
71 |
private String server; |
72 |
private String service; |
73 |
private String serviceType; |
74 |
private String remoteLayerName; |
75 |
private ArcImsAttributesDataSourceAdapter attsDataSourceAdapter;
|
76 |
private SelectableDataSource dataSource = null; |
77 |
private DriverAttributes drvAtts;
|
78 |
private ArrayList geometries; |
79 |
private HashMap pseudoGeometries; |
80 |
private int shapeType = FShape.NULL; |
81 |
private FFeatureLyrArcIMS layer;
|
82 |
|
83 |
private HashMap overallIndexToVisibleIndex; |
84 |
private HashMap visibleIndexToOverallIndex; |
85 |
|
86 |
private DataSourceFactory dataSourceFactory = null; |
87 |
|
88 |
private Rectangle2D fullExtent; |
89 |
private IGeometry invisiblePoint = ShapeFactory.createPoint2D(0.0, 0.0); |
90 |
|
91 |
private VectorialEditableAdapter eadapter;
|
92 |
|
93 |
/**
|
94 |
* The constructor needs the server's URL and the name of the service to be used.
|
95 |
*
|
96 |
* @param host server's URL
|
97 |
* @param service name of the service, chosen among the ones retrieved after a
|
98 |
* request with the parameter <tt>ServiceName=Catalog</tt>
|
99 |
*/
|
100 |
public FMapFeatureArcImsDriver(String host, String service, String theRemoteLayerName) { |
101 |
remoteLayerName = theRemoteLayerName; |
102 |
init(host, service); |
103 |
overallIndexToVisibleIndex = new HashMap(); |
104 |
visibleIndexToOverallIndex = new HashMap(); |
105 |
pseudoGeometries = new HashMap(); |
106 |
} |
107 |
|
108 |
/**
|
109 |
* The constructor needs the server's URL and the name of the service to be used.
|
110 |
*
|
111 |
* @param host server's URL
|
112 |
* @param service name of the service, chosen among the ones retrieved after a
|
113 |
* request with the parameter <tt>ServiceName=Catalog</tt>
|
114 |
*/
|
115 |
public FMapFeatureArcImsDriver(String host, String service) { |
116 |
remoteLayerName = "None";
|
117 |
init(host, service); |
118 |
overallIndexToVisibleIndex = new HashMap(); |
119 |
visibleIndexToOverallIndex = new HashMap(); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* This method is called by the constructor and creates the
|
124 |
* <tt>client</tt> object.
|
125 |
* @param host
|
126 |
* @param service
|
127 |
*/
|
128 |
public void init(String host, String svc) { |
129 |
server = host; |
130 |
service = svc; |
131 |
// This class is part of libArcIMS:
|
132 |
client = new ArcImsFeatureClient(host, service, ServiceInfoTags.vFEATURESERVICE);
|
133 |
} |
134 |
|
135 |
private String getIdName() { |
136 |
|
137 |
String id = (String) this.layer.getArcimsStatus().getLayerIds().get(0); |
138 |
ServiceInformationLayerFeatures silf = (ServiceInformationLayerFeatures) client.getServiceInformation().getLayerById(id); |
139 |
|
140 |
ArrayList fi = silf.getFieldInformationByType(FieldInformation.ID);
|
141 |
|
142 |
if (fi.size() != 1) { |
143 |
logger.error("ID does not have cardinality one: " + fi.size());
|
144 |
} |
145 |
return ((FieldInformation) fi.get(0)).getName(); |
146 |
} |
147 |
|
148 |
private ArrayList getClientsColumnNames() { |
149 |
String id = (String) layer.getArcimsStatus().getLayerIds().get(0); |
150 |
ServiceInformationLayerFeatures silf = |
151 |
(ServiceInformationLayerFeatures) client.getServiceInformation().getLayerById(id); |
152 |
int length = silf.getFieldsInfo().size();
|
153 |
|
154 |
ArrayList resp = new ArrayList(); |
155 |
for (int i=0; i<length; i++) { |
156 |
resp.add(silf.getFieldInformation(i).getName()); |
157 |
} |
158 |
return resp;
|
159 |
} |
160 |
|
161 |
private ArrayList getClientsColumnTypes() { |
162 |
String id = (String) layer.getArcimsStatus().getLayerIds().get(0); |
163 |
ServiceInformationLayerFeatures silf = |
164 |
(ServiceInformationLayerFeatures) client.getServiceInformation().getLayerById(id); |
165 |
int length = silf.getFieldsInfo().size();
|
166 |
|
167 |
ArrayList resp = new ArrayList(); |
168 |
for (int i=0; i<length; i++) { |
169 |
resp.add(new Integer(silf.getFieldInformation(i).getType())); |
170 |
} |
171 |
return resp;
|
172 |
} |
173 |
|
174 |
public void closeDataSource() { |
175 |
try {
|
176 |
dataSource.stop(); |
177 |
} catch (DriverException e) {
|
178 |
logger.error("While closing data source ", e);
|
179 |
} |
180 |
} |
181 |
|
182 |
public SelectableDataSource getRecordSet() {
|
183 |
return getRecordSet(null); |
184 |
} |
185 |
|
186 |
public SelectableDataSource getRecordSet(String mustHaveThisName) { |
187 |
|
188 |
if (dataSource != null) return dataSource; |
189 |
|
190 |
String subf[] = new String[1]; |
191 |
subf[0] = getIdName();
|
192 |
|
193 |
ArrayList ids = new ArrayList(); |
194 |
try {
|
195 |
// ids = getTestIds();
|
196 |
ids = client.getAttributes(layer.getArcimsStatus(), subf, "", null); |
197 |
} catch (ArcImsException e1) {
|
198 |
logger.error("While getting attributes initially ", e1);
|
199 |
} |
200 |
|
201 |
Value[] idval = getAsValueArray(ids);
|
202 |
|
203 |
dataSourceFactory = LayerFactory.getDataSourceFactory(); |
204 |
|
205 |
// dataSourceFactory.
|
206 |
// FakeObjectDriver driver = new FakeObjectDriver();
|
207 |
attsDataSourceAdapter = new ArcImsAttributesDataSourceAdapter(getClientsColumnNames(),
|
208 |
getClientsColumnTypes(), idval, dataSourceFactory, this, mustHaveThisName);
|
209 |
|
210 |
dataSourceFactory.addDataSource(attsDataSourceAdapter, attsDataSourceAdapter.getTableName()); |
211 |
|
212 |
ObjectSourceInfo osi = (ObjectSourceInfo) dataSourceFactory.getDriverInfo(attsDataSourceAdapter.getTableName()); |
213 |
osi.name = attsDataSourceAdapter.getTableName(); |
214 |
osi.driverName = "ArcImsAttributesDataSourceAdapter";
|
215 |
|
216 |
// String tablename = attsDataSourceAdapter.getTableName();
|
217 |
// String sqlstr = "select * from " + tablename + " where " + ArcImsSqlUtils.rowIndexFieldName + " = 8;";
|
218 |
// DataSource result = null;
|
219 |
// int n = -1;
|
220 |
|
221 |
try {
|
222 |
// attsDataSourceAdapter.start();
|
223 |
// result = dataSourceFactory.executeSQL(sqlstr, DataSourceFactory.AUTOMATIC_OPENING);
|
224 |
// attsDataSourceAdapter.stop();
|
225 |
//
|
226 |
// n = (int) result.getRowCount();
|
227 |
dataSource = new SelectableDataSource(attsDataSourceAdapter);
|
228 |
} catch (DriverException e) {
|
229 |
logger.error("While creating DataSource ", e);
|
230 |
} |
231 |
return dataSource;
|
232 |
} |
233 |
|
234 |
public void declareTable() { |
235 |
try {
|
236 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
237 |
|
238 |
if (v == null) { |
239 |
|
240 |
ProjectView pv = new ProjectView();
|
241 |
pv.setName("Nueva");
|
242 |
View newview = (View) pv.createWindow(); |
243 |
newview.setModel(pv); |
244 |
Project newproj = new Project();
|
245 |
newproj.setName("nuevo");
|
246 |
newproj.addDocument(pv); |
247 |
// newproj.addView(newprojview);
|
248 |
v = newview; |
249 |
} |
250 |
|
251 |
ProjectView pv = (ProjectView) ((View) v).getModel();
|
252 |
ProjectTable pt = ProjectFactory.createTable(attsDataSourceAdapter.getName(), eadapter); |
253 |
pv.getProject().addDocument(pt); |
254 |
} catch (Exception e) { |
255 |
logger.error("While creating DataSource ", e);
|
256 |
e.printStackTrace(); |
257 |
} |
258 |
} |
259 |
|
260 |
public void loadRecordSet() { |
261 |
|
262 |
if (dataSource != null) return; |
263 |
|
264 |
String subf[] = new String[1]; |
265 |
subf[0] = getIdName();
|
266 |
|
267 |
ArrayList ids = new ArrayList(); |
268 |
try {
|
269 |
// ids = getTestIds();
|
270 |
ids = client.getAttributes(layer.getArcimsStatus(), subf, "", null); |
271 |
} catch (ArcImsException e1) {
|
272 |
logger.error("While getting attributes initially ", e1);
|
273 |
} |
274 |
|
275 |
Value[] idval = getAsValueArray(ids);
|
276 |
|
277 |
dataSourceFactory = LayerFactory.getDataSourceFactory(); |
278 |
|
279 |
// dataSourceFactory.
|
280 |
// FakeObjectDriver driver = new FakeObjectDriver();
|
281 |
attsDataSourceAdapter = new ArcImsAttributesDataSourceAdapter(getClientsColumnNames(),
|
282 |
getClientsColumnTypes(), idval, dataSourceFactory, this, null); |
283 |
dataSourceFactory.addDataSource(attsDataSourceAdapter, attsDataSourceAdapter.getTableName()); |
284 |
try {
|
285 |
dataSource = new SelectableDataSource(attsDataSourceAdapter);
|
286 |
} catch (DriverException e) {
|
287 |
logger.error("While loading selectable data source");
|
288 |
} |
289 |
|
290 |
// try {
|
291 |
// dataSource = new SelectableDataSource(attsDataSourceAdapter);
|
292 |
// View v = PluginServices.getMDIManager().getActiveView();
|
293 |
//
|
294 |
// if (v == null) {
|
295 |
// ProjectView newprojview = ProjectView.createView("Nueva");
|
296 |
// com.iver.cit.gvsig.gui.View newview = new com.iver.cit.gvsig.gui.View();
|
297 |
// newview.setModel(newprojview);
|
298 |
// Project newproj = new Project();
|
299 |
// newproj.setName("nuevo");
|
300 |
// newproj.addView(newprojview);
|
301 |
// v = newview;
|
302 |
// }
|
303 |
// ProjectView pv = ((com.iver.cit.gvsig.gui.View) v).getModel();
|
304 |
// ProjectTable pt = ProjectTable.createTable(attsDataSourceAdapter.getName(), dataSource);
|
305 |
// pv.getProject().addTable(pt);
|
306 |
// } catch (Exception e) {
|
307 |
// logger.error("While creating DataSource ", e);
|
308 |
// e.printStackTrace();
|
309 |
// }
|
310 |
} |
311 |
|
312 |
private Value[] getAsValueArray(ArrayList ids) { |
313 |
Value[] resp = new Value[ids.size()]; |
314 |
for (int i=0; i<ids.size(); i++) { |
315 |
resp[i] = ((Value []) ids.get(i))[0]; |
316 |
} |
317 |
return resp;
|
318 |
} |
319 |
|
320 |
public void getCapabilities(URL server, ICancellable cancel) throws ArcImsException, IOException, ProtocolException { |
321 |
logger.error("Empty method: nothing done in method getCapabilities(URL) - class: " +
|
322 |
getClass().toString()); |
323 |
} |
324 |
|
325 |
public Object getMap(ArcImsStatus status) throws ArcImsException, IOException, ProtocolException { |
326 |
|
327 |
String[] fieldquery = ((ArcImsVectStatus) status).getSubfields(); |
328 |
int nooffields = fieldquery.length;
|
329 |
|
330 |
try {
|
331 |
geometries = client.getMap((ArcImsVectStatus) status); |
332 |
if (geometries.size() > 0) { |
333 |
logger.info("Start updating attributes");
|
334 |
updateIndexHashMaps(geometries, fieldquery, nooffields); |
335 |
logger.info("End updating attributes");
|
336 |
} else {
|
337 |
updateIndexHashMaps(geometries, fieldquery, nooffields); |
338 |
logger.warn("No geometries retrieved from client ");
|
339 |
} |
340 |
} catch (ServerErrorException e) {
|
341 |
ArcImsException aie = new ArcImsException(e.getMessage());
|
342 |
logger.error("While getting map ", aie);
|
343 |
throw aie;
|
344 |
} |
345 |
return geometries;
|
346 |
} |
347 |
|
348 |
|
349 |
// **************************
|
350 |
//
|
351 |
// **************************
|
352 |
private void updateIndexHashMaps(ArrayList iFeatArrayList, String[] f_query, int n_of_fields) { |
353 |
|
354 |
int added_row_ind;
|
355 |
|
356 |
// ------------ get id position --------------
|
357 |
int idfieldind = -1; |
358 |
for (int i=0; i<n_of_fields; i++) { |
359 |
if (f_query[i].compareTo(getIdName()) == 0) { |
360 |
idfieldind = i; |
361 |
} |
362 |
} |
363 |
if (idfieldind == -1) { |
364 |
logger.error("ID not found in query ");
|
365 |
} |
366 |
// -------------------------------------------
|
367 |
|
368 |
IntValue id; |
369 |
|
370 |
try {
|
371 |
overallIndexToVisibleIndex.clear(); |
372 |
visibleIndexToOverallIndex.clear(); |
373 |
|
374 |
for (int i = 0; i < iFeatArrayList.size(); i++) { |
375 |
IFeature ifeat = (IFeature) iFeatArrayList.get(i); |
376 |
id = (IntValue) ifeat.getAttribute(idfieldind); |
377 |
added_row_ind = attsDataSourceAdapter.getRowIndex(id.getValue()); |
378 |
|
379 |
addPseudoGeometry(ifeat.getGeometry(), added_row_ind); |
380 |
|
381 |
// Value[] newrow = new Value[n_of_fields];
|
382 |
// for (int j = 0; j < n_of_fields; j++)
|
383 |
// newrow[j] = ifeat.getAttribute(j);
|
384 |
// // System.err.println("Updating row with id = " + ((IntValue) newrow[1]).getValue());
|
385 |
// attsDataSourceAdapter..getRowIndex()
|
386 |
// added_row_ind = attsDataSourceAdapter.updateRow(newrow, f_query);
|
387 |
|
388 |
// logger.debug("Added pair: Visible: " + i + ", Overall: " + added_row_ind);
|
389 |
overallIndexToVisibleIndex.put(new Integer(added_row_ind), new Integer(i)); |
390 |
visibleIndexToOverallIndex.put(new Integer(i), new Integer(added_row_ind)); |
391 |
} |
392 |
// }
|
393 |
} catch (DriverException e) {
|
394 |
logger.error("While updating attributes ", e);
|
395 |
} |
396 |
} |
397 |
|
398 |
public String getFeatureInfo(ArcImsStatus status, int i, int j, |
399 |
int max_value) throws ArcImsException, IOException, |
400 |
ProtocolException {
|
401 |
// TODO comment
|
402 |
return ""; |
403 |
} |
404 |
|
405 |
// public ArrayList getGeometries() {
|
406 |
// if (geometries == null) {
|
407 |
// // geometris = client.get.....
|
408 |
// setTestGeometries();
|
409 |
// }
|
410 |
// return geometries;
|
411 |
// }
|
412 |
//
|
413 |
/**
|
414 |
* This method starts a connection with the server and sends
|
415 |
* a <tt>getCapabilities</tt> request.
|
416 |
* @return <b>true</b> if the connection was successful, <b>false</b>
|
417 |
* otherwise (bad or no server URL, for example)
|
418 |
*/
|
419 |
public boolean connect(ICancellable cancel) { |
420 |
|
421 |
return client.connect(cancel);
|
422 |
// File csvFile = null;
|
423 |
// // This method is in libArcIMS
|
424 |
// // csvFile = client....connect(); (por ejemplo)
|
425 |
//
|
426 |
// JFileChooser jfc = new JFileChooser();
|
427 |
// jfc.setDialogTitle("Indice archivo CSV con los atributos de las geometrias");
|
428 |
// int returnVal = jfc.showOpenDialog(null);
|
429 |
// if (returnVal != JFileChooser.APPROVE_OPTION) {
|
430 |
// return false;
|
431 |
// }
|
432 |
// csvFile = jfc.getSelectedFile();
|
433 |
// if (! jfc.accept(csvFile)) return false;
|
434 |
//
|
435 |
// // csv =
|
436 |
// // .....
|
437 |
// dataSource = getRecordSet(csvFile);
|
438 |
// // return client.connect();
|
439 |
// return true;
|
440 |
} |
441 |
|
442 |
/**
|
443 |
* Gets available layers from the current server and service
|
444 |
*
|
445 |
* @return a TreeMap with available layers
|
446 |
*/
|
447 |
public TreeMap getLayers() { |
448 |
return null; |
449 |
// This method is in libArcIMS
|
450 |
// return client.getLayers();
|
451 |
} |
452 |
|
453 |
/**
|
454 |
* Gets the <tt>ArcImsClientP client</tt> object, onto which requests
|
455 |
* are passed.
|
456 |
*
|
457 |
* @return the inner object that actually performs requests.
|
458 |
*/
|
459 |
public ArcImsClientP getClient() {
|
460 |
if (client == null) { |
461 |
init(server, service); |
462 |
} |
463 |
return client;
|
464 |
} |
465 |
|
466 |
// ========== VECTORIAL DRIVER INTERFACE == START =======
|
467 |
|
468 |
public int getShapeType() { |
469 |
|
470 |
if (shapeType == FShape.NULL) {
|
471 |
|
472 |
ServiceInformationLayerFeatures silf = |
473 |
(ServiceInformationLayerFeatures) client.getServiceInformation().getLayerById(remoteLayerName); |
474 |
|
475 |
shapeType = libArcImsShapeTypeToGvSigType(silf.getIntFclassType()); |
476 |
} |
477 |
return shapeType;
|
478 |
} |
479 |
|
480 |
public int getShapeCount() throws IOException { |
481 |
try {
|
482 |
// return geometries.size();
|
483 |
return (int) getRecordSet().getRowCount(); |
484 |
} catch (DriverException e) {
|
485 |
IOException ioe = new IOException(e.getMessage()); |
486 |
throw ioe;
|
487 |
} |
488 |
} |
489 |
|
490 |
public DriverAttributes getDriverAttributes() {
|
491 |
if (drvAtts != null) return drvAtts; |
492 |
drvAtts = new DriverAttributes();
|
493 |
drvAtts.setLoadedInMemory(true);
|
494 |
return drvAtts;
|
495 |
} |
496 |
|
497 |
public Rectangle2D getFullExtent() throws IOException { |
498 |
return fullExtent;
|
499 |
} |
500 |
|
501 |
// public IGeometry getShape(int index) throws IOException {
|
502 |
// return ((IFeature) geometries.get(index)).getGeometry();
|
503 |
// }
|
504 |
|
505 |
private void addPseudoGeometry(IGeometry igeom, int row) { |
506 |
pseudoGeometries.put(new Integer(row), igeom); |
507 |
} |
508 |
|
509 |
public IGeometry getShape(int index) throws IOException { |
510 |
Integer overallIndex = new Integer(index); |
511 |
Integer visibleIndex = (Integer) overallIndexToVisibleIndex.get(overallIndex); |
512 |
|
513 |
if (visibleIndex == null) { |
514 |
// Somebody asked for a non-visible shape.
|
515 |
IGeometry igeo = (IGeometry) pseudoGeometries.get(overallIndex); |
516 |
if (igeo != null) { |
517 |
return igeo;
|
518 |
} |
519 |
|
520 |
// We dont have the geometry and we dont have its pseudo envelope
|
521 |
// (this happens when loading a project with a selection and the user
|
522 |
// performs a zoom to selection)
|
523 |
String id = layer.getLayerQuery();
|
524 |
BoundaryBox bb = client.getServiceInformation().getLayerById(id).getEnvelope(); |
525 |
|
526 |
double[] fullx = new double[4]; |
527 |
double[] fully = new double[4]; |
528 |
|
529 |
fullx[0] = bb.getXmin();
|
530 |
fullx[1] = bb.getXmin();
|
531 |
fullx[2] = bb.getXmax();
|
532 |
fullx[3] = bb.getXmax();
|
533 |
fully[0] = bb.getYmin();
|
534 |
fully[1] = bb.getYmax();
|
535 |
fully[2] = bb.getYmin();
|
536 |
fully[3] = bb.getYmax();
|
537 |
|
538 |
IGeometry full = ShapeFactory.createMultipoint2D(fullx, fully); |
539 |
return full;
|
540 |
|
541 |
} else {
|
542 |
return ((IFeature) geometries.get(visibleIndex.intValue())).getGeometry();
|
543 |
} |
544 |
} |
545 |
|
546 |
public String getName() { |
547 |
return "FMapFeatureArcImsDriver"; |
548 |
} |
549 |
|
550 |
// ========== VECTORIAL DRIVER INTERFACE == END =======
|
551 |
|
552 |
// private void setTestGeometries() {
|
553 |
// IGeometry g;
|
554 |
// File wktfile = null;
|
555 |
// JFileChooser jfc = new JFileChooser();
|
556 |
// try {
|
557 |
// jfc.setDialogTitle("Indice archivo WKT con " + getShapeCount() + " geometrias");
|
558 |
// } catch (IOException e) {
|
559 |
// logger.error("Error while opening WKT file. ", e);
|
560 |
// }
|
561 |
// int returnVal = jfc.showOpenDialog(null);
|
562 |
// if (returnVal != JFileChooser.APPROVE_OPTION) return;
|
563 |
// wktfile = jfc.getSelectedFile();
|
564 |
// if (! jfc.accept(wktfile)) return;
|
565 |
// WKTFGeometryReader reader = new WKTFGeometryReader(wktfile);
|
566 |
// g = reader.getNextFGeometry();
|
567 |
// geometries = new ArrayList();
|
568 |
// while (g != null) {
|
569 |
// geometries.add(g);
|
570 |
// g = reader.getNextFGeometry();;
|
571 |
// }
|
572 |
// }
|
573 |
|
574 |
public void setFullExtent(Rectangle2D fullExtent) { |
575 |
this.fullExtent = fullExtent;
|
576 |
} |
577 |
|
578 |
public FFeatureLyrArcIMS getLayer() {
|
579 |
return layer;
|
580 |
} |
581 |
|
582 |
public void setLayer(FFeatureLyrArcIMS layer) { |
583 |
this.layer = layer;
|
584 |
} |
585 |
|
586 |
// private ArrayList getTestIds() throws ArcImsException {
|
587 |
// Value[] ids = new Value[252];
|
588 |
//
|
589 |
// for (int i=0; i<252; i++) {
|
590 |
// ids[i] = ValueFactory.createValue(i);
|
591 |
// }
|
592 |
// ArrayList resp = new ArrayList();
|
593 |
// resp.add(ids);
|
594 |
// return resp;
|
595 |
// }
|
596 |
|
597 |
public int getOverallIndex(int i) { |
598 |
Integer ov = (Integer) visibleIndexToOverallIndex.get(new Integer(i)); |
599 |
return ov.intValue();
|
600 |
} |
601 |
|
602 |
public void requestFeatureAttributes(FBitSet fbs) throws ArcImsException { |
603 |
if (fbs.cardinality() == 0) return; |
604 |
FBitSet needRequest = leaveBitsThatNeedRequest(fbs); |
605 |
|
606 |
requestFeatureAttributesWithoutChecking(needRequest); |
607 |
} |
608 |
|
609 |
public void requestBlockWithoutChecking(int[] indlimits) throws ArcImsException { |
610 |
|
611 |
FBitSet fbs = new FBitSet();
|
612 |
fbs.set(indlimits[0], indlimits[1] + 1); |
613 |
|
614 |
int length = fbs.cardinality();
|
615 |
if (length == 0) return; |
616 |
|
617 |
int[] ids = new int[length]; |
618 |
int rowinds[] = new int[length]; |
619 |
int idind = 0; |
620 |
|
621 |
try {
|
622 |
for (int i = fbs.nextSetBit(0); i >= 0; i = fbs.nextSetBit(i + 1)) { |
623 |
ids[idind] = attsDataSourceAdapter.getRowId(i); |
624 |
rowinds[idind] = i; |
625 |
idind++; |
626 |
} |
627 |
|
628 |
String minval = Integer.toString(attsDataSourceAdapter.getRowId(indlimits[0])); |
629 |
String maxval = Integer.toString(attsDataSourceAdapter.getRowId(indlimits[1])); |
630 |
|
631 |
int idcolindex = attsDataSourceAdapter.getIdIndex();
|
632 |
String idFieldName = attsDataSourceAdapter.getOriginalFieldName(idcolindex);
|
633 |
String whereClause = idFieldName + " >= " + minval + " and " + |
634 |
idFieldName + " <= " + maxval;
|
635 |
|
636 |
System.err.println("WHERE = " + whereClause); |
637 |
|
638 |
String subflds[] = new String[1]; |
639 |
subflds[0] = "#ALL#"; |
640 |
|
641 |
logger.debug("Justo antes de llamar a client.getAttributes(...)");
|
642 |
|
643 |
// ---------------- with geometries -----------------------
|
644 |
// ArrayList atts = client.getAttributes(layer.getArcimsStatus(),
|
645 |
// subflds, whereClause, null);
|
646 |
ArrayList atts = client.getAttributesWithEnvelope(layer.getArcimsStatus(),
|
647 |
subflds, whereClause, null);
|
648 |
// --------------------------------------------------------
|
649 |
|
650 |
logger.debug("Justo despues de llamar a client.getAttributes(...)");
|
651 |
|
652 |
logger.debug("Justo antes de llamar a attsDataSourceAdapter.updateRow(...) " + atts.size() + " veces"); |
653 |
|
654 |
for (int i = (atts.size() - 1); i >= 0; i--) { |
655 |
Value[] newrow = ((DefaultFeature) atts.get(i)).getAttributes();
|
656 |
// Value[] newrow = (Value[]) atts.get(i);
|
657 |
attsDataSourceAdapter.updateRow(newrow, subflds, rowinds[i]); |
658 |
} |
659 |
|
660 |
// -------------- pseudo geometries:
|
661 |
for (int i = (atts.size() - 1); i >= 0; i--) { |
662 |
IGeometry ig = ((DefaultFeature) atts.get(i)).getGeometry(); |
663 |
addPseudoGeometry(ig, rowinds[i]); |
664 |
} |
665 |
// --------------
|
666 |
|
667 |
logger.debug("Justo despues de llamar a attsDataSourceAdapter.updateRow(...)");
|
668 |
logger.debug("Justo antes de llamar a attsDataSourceAdapter.addAsRequested(...)");
|
669 |
|
670 |
attsDataSourceAdapter.addAsRequested(fbs); |
671 |
|
672 |
logger.debug("Justo despues de llamar a attsDataSourceAdapter.addAsRequested(...)");
|
673 |
|
674 |
} catch (DriverException e) {
|
675 |
ArcImsException aie = new ArcImsException("datasource_error"); |
676 |
logger.error("While requesting features ", aie);
|
677 |
throw aie;
|
678 |
} |
679 |
} |
680 |
|
681 |
public void requestFeatureAttributesWithoutChecking(FBitSet fbs) throws ArcImsException { |
682 |
|
683 |
int length = fbs.cardinality();
|
684 |
if (length == 0) return; |
685 |
|
686 |
int rowcount = 0; |
687 |
int firstnonreq = 0; |
688 |
try {
|
689 |
rowcount = (int) attsDataSourceAdapter.getRowCount();
|
690 |
} catch (DriverException e1) {
|
691 |
logger.error("Unexpected error while getting row count ");
|
692 |
return;
|
693 |
} |
694 |
|
695 |
firstnonreq = fbs.nextClearBit(fbs.nextSetBit(0));
|
696 |
if (firstnonreq >= rowcount) {
|
697 |
firstnonreq = 0;
|
698 |
} |
699 |
if (length < 10) { |
700 |
fbs.or( |
701 |
attsDataSourceAdapter.getNonRequestedFromHere( |
702 |
firstnonreq, |
703 |
attsDataSourceAdapter.getRowsPerRequest() - length |
704 |
) |
705 |
); |
706 |
length = fbs.cardinality(); |
707 |
} |
708 |
|
709 |
int[] ids = new int[length]; |
710 |
int rowinds[] = new int[length]; |
711 |
int idind = 0; |
712 |
|
713 |
try {
|
714 |
for (int i = fbs.nextSetBit(0); i >= 0; i = fbs.nextSetBit(i + 1)) { |
715 |
ids[idind] = attsDataSourceAdapter.getRowId(i); |
716 |
rowinds[idind] = i; |
717 |
idind++; |
718 |
} |
719 |
|
720 |
String inParenthesis = getInIntParenthesis(ids);
|
721 |
int idcolindex = attsDataSourceAdapter.getIdIndex();
|
722 |
String idFieldName = attsDataSourceAdapter.getOriginalFieldName(idcolindex);
|
723 |
String whereClause = idFieldName + " " + inParenthesis; |
724 |
String subflds[] = new String[1]; |
725 |
subflds[0] = "#ALL#"; |
726 |
|
727 |
// -------------- with geometries -------------------------
|
728 |
ArrayList atts = client.getAttributesWithEnvelope(layer.getArcimsStatus(),
|
729 |
subflds, whereClause, null);
|
730 |
// ArrayList atts = client.getAttributes(layer.getArcimsStatus(),
|
731 |
// subflds, whereClause, null);
|
732 |
// --------------------------------------------------------
|
733 |
|
734 |
// -------------- pseudo geometries:
|
735 |
for (int i = (atts.size() - 1); i >= 0; i--) { |
736 |
IGeometry ig = ((DefaultFeature) atts.get(i)).getGeometry(); |
737 |
addPseudoGeometry(ig, rowinds[i]); |
738 |
} |
739 |
// --------------
|
740 |
|
741 |
|
742 |
for (int i = (atts.size() - 1); i >= 0; i--) { |
743 |
Value[] newrow = ((DefaultFeature) atts.get(i)).getAttributes();
|
744 |
// Value[] newrow = (Value[]) atts.get(i);
|
745 |
attsDataSourceAdapter.updateRow(newrow, subflds, rowinds[i]); |
746 |
} |
747 |
attsDataSourceAdapter.addAsRequested(fbs); |
748 |
} catch (DriverException e) {
|
749 |
ArcImsException aie = new ArcImsException("datasource_error"); |
750 |
logger.error("While requesting features ", aie);
|
751 |
throw aie;
|
752 |
} |
753 |
|
754 |
} |
755 |
|
756 |
|
757 |
private FBitSet leaveBitsThatNeedRequest(FBitSet fbs) {
|
758 |
FBitSet resp = (FBitSet) fbs.clone(); |
759 |
|
760 |
for(int i=resp.nextSetBit(0); i>=0; i=resp.nextSetBit(i+1)) { |
761 |
if (! attsDataSourceAdapter.isNonRequestedRow(i)) {
|
762 |
resp.clear(i); |
763 |
} |
764 |
} |
765 |
return resp;
|
766 |
} |
767 |
|
768 |
private String getInIntParenthesis(int[] ids) { |
769 |
String resp = "IN ("; |
770 |
for (int i=0; i<ids.length; i++) { |
771 |
resp = resp + " " + ids[i] + ","; |
772 |
} |
773 |
resp = resp.substring(0, resp.length() - 1); |
774 |
resp = resp + ")";
|
775 |
return resp;
|
776 |
} |
777 |
|
778 |
private int libArcImsShapeTypeToGvSigType(int type) { |
779 |
|
780 |
int resp = type;
|
781 |
|
782 |
switch (type) {
|
783 |
|
784 |
case FShape.MULTIPOINT:
|
785 |
resp = FShape.POINT; |
786 |
break;
|
787 |
} |
788 |
|
789 |
return resp;
|
790 |
} |
791 |
|
792 |
public void setAdapter(VectorialEditableAdapter adapter) { |
793 |
eadapter = adapter; |
794 |
} |
795 |
|
796 |
public VectorialEditableAdapter getAdapter() {
|
797 |
return eadapter;
|
798 |
} |
799 |
|
800 |
public void reload() throws IOException, DriverException { |
801 |
} |
802 |
|
803 |
public boolean isWritable() { |
804 |
return false; |
805 |
} |
806 |
|
807 |
public String getRemoteLayerName() { |
808 |
return remoteLayerName;
|
809 |
} |
810 |
|
811 |
public void setRemoteLayerName(String remoteLayerName) { |
812 |
this.remoteLayerName = remoteLayerName;
|
813 |
} |
814 |
|
815 |
} |