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