Revision 32367 branches/v2_0_0_prep/libraries/org.gvsig.arcims/src/org/gvsig/remoteclient/arcims/ArcImsProtFeatureHandler.java
ArcImsProtFeatureHandler.java | ||
---|---|---|
27 | 27 |
*/ |
28 | 28 |
package org.gvsig.remoteclient.arcims; |
29 | 29 |
|
30 |
import java.awt.geom.Point2D; |
|
31 | 30 |
import java.awt.geom.Rectangle2D; |
32 | 31 |
import java.io.BufferedReader; |
33 | 32 |
import java.io.File; |
... | ... | |
41 | 40 |
import java.io.UnsupportedEncodingException; |
42 | 41 |
import java.net.MalformedURLException; |
43 | 42 |
import java.net.URL; |
44 |
import java.text.ParseException; |
|
45 | 43 |
import java.util.ArrayList; |
44 |
import java.util.Date; |
|
45 |
import java.util.Hashtable; |
|
46 | 46 |
import java.util.Iterator; |
47 | 47 |
import java.util.List; |
48 | 48 |
import java.util.StringTokenizer; |
49 | 49 |
import java.util.Vector; |
50 | 50 |
|
51 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
52 | 51 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
53 | 52 |
import org.gvsig.fmap.geom.Geometry; |
53 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
54 |
import org.gvsig.fmap.geom.GeometryManager; |
|
55 |
import org.gvsig.fmap.geom.aggregate.impl.MultiPoint2D; |
|
56 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
54 | 57 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
58 |
import org.gvsig.fmap.geom.primitive.Point; |
|
55 | 59 |
import org.gvsig.remoteclient.arcims.exceptions.ArcImsException; |
56 | 60 |
import org.gvsig.remoteclient.arcims.utils.ArcImsDownloadUtils; |
57 |
import org.gvsig.remoteclient.arcims.utils.ArcImsValueFactory; |
|
58 | 61 |
import org.gvsig.remoteclient.arcims.utils.FieldInformation; |
59 | 62 |
import org.gvsig.remoteclient.arcims.utils.GetFeaturesTags; |
60 | 63 |
import org.gvsig.remoteclient.arcims.utils.ServiceInfoTags; |
... | ... | |
62 | 65 |
import org.gvsig.remoteclient.arcims.utils.ServiceInformationLayerFeatures; |
63 | 66 |
import org.gvsig.remoteclient.utils.BoundaryBox; |
64 | 67 |
import org.kxml2.io.KXmlParser; |
65 |
import org.xmlpull.v1.XmlPullParserException; |
|
66 | 68 |
import org.slf4j.Logger; |
67 | 69 |
import org.slf4j.LoggerFactory; |
70 |
import org.xmlpull.v1.XmlPullParserException; |
|
68 | 71 |
|
69 | 72 |
/** |
70 | 73 |
* @author jsanz |
... | ... | |
76 | 79 |
private static Logger logger = LoggerFactory |
77 | 80 |
.getLogger(ArcImsProtFeatureHandler.class.getName()); |
78 | 81 |
|
79 |
/* |
|
80 |
* private ArcImsCache aic; |
|
81 |
* |
|
82 |
* public ArrayList getCacheMap(ArcImsVectStatus status) throws |
|
83 |
* ArcImsException{ if (aic==null) aic = new |
|
84 |
* ArcImsCache(this.getLayerExtent(status),1); |
|
85 |
* |
|
86 |
* aic.addStatus(status); |
|
87 |
* |
|
88 |
* return aic.getGeometries(status); } |
|
89 |
*/ |
|
90 |
|
|
91 | 82 |
/** |
92 | 83 |
* Method to retrieve an ArrayList of features from an ArcIMS FeatureService |
93 | 84 |
* |
... | ... | |
143 | 134 |
reader = br; |
144 | 135 |
|
145 | 136 |
logger.debug("Start features with attributes parsing"); |
146 |
array.addAll(getFeatures(reader, status.getServiceInfo(),
|
|
137 |
array.add(this.getFeatures(reader, status.getServiceInfo(),
|
|
147 | 138 |
layerId, status.getSubfields(), 1)); |
148 | 139 |
logger.debug("End features with attributes parsing"); |
149 | 140 |
} |
... | ... | |
183 | 174 |
* @return ArrayList of IFeatures or Value[] |
184 | 175 |
* @throws ArcImsException |
185 | 176 |
*/ |
186 |
private FeatureStore getFeatures(Reader lector, ServiceInformation si,
|
|
177 |
private Hashtable getFeatures(Reader lector, ServiceInformation si,
|
|
187 | 178 |
String layerId, String[] subfields, int withGeometries) |
188 | 179 |
throws ArcImsException { |
180 |
|
|
181 |
// TODO |
|
182 |
// clear features map |
|
183 |
// this.features.clear(); |
|
184 |
|
|
185 |
// fill features map |
|
189 | 186 |
FieldInformation fi = null; |
190 | 187 |
ServiceInformationLayerFeatures sil = (ServiceInformationLayerFeatures) si |
191 | 188 |
.getLayerById(layerId); |
... | ... | |
193 | 190 |
/* |
194 | 191 |
* Prepare a Value array to store every FEATURE tag information |
195 | 192 |
*/ |
196 |
Vector fieldsInfo = null; |
|
197 |
fieldsInfo = sil.getFieldsInfo(); |
|
193 |
Vector<FieldInformation> fieldsInfo = sil.getFieldsInfo(); |
|
198 | 194 |
|
199 | 195 |
// If flag == true, throw an Exception (no layerId found) |
200 | 196 |
if (fieldsInfo == null) { |
... | ... | |
202 | 198 |
} |
203 | 199 |
|
204 | 200 |
// We will store names and types in a hashmap |
205 |
ArrayList fieldsInfoA = new ArrayList();
|
|
201 |
List<FieldInformation> fieldsInfoA = new ArrayList<FieldInformation>();
|
|
206 | 202 |
|
207 | 203 |
/* |
208 | 204 |
* If subfields[0] is equal to #ALL we add the entire vector into the |
... | ... | |
210 | 206 |
*/ |
211 | 207 |
if (subfields[0].equals("#ALL#")) { |
212 | 208 |
for (int i = 0; i < fieldsInfo.size(); i++) { |
213 |
fi = ((FieldInformation) fieldsInfo.get(i));
|
|
209 |
fi = fieldsInfo.get(i);
|
|
214 | 210 |
fieldsInfoA.add(fi); |
215 | 211 |
} |
216 | 212 |
} else { |
... | ... | |
240 | 236 |
* Start parsing |
241 | 237 |
*/ |
242 | 238 |
int tag; |
243 |
KXmlParser kxmlParser = null; |
|
244 |
kxmlParser = new KXmlParser(); |
|
239 |
KXmlParser kxmlParser = new KXmlParser(); |
|
245 | 240 |
|
246 |
// FileReader fr = null;
|
|
241 |
FileReader fr = null; |
|
247 | 242 |
Geometry geom = null; |
248 |
Value[] values = new Value[fieldsInfoA.size()]; |
|
249 |
int[] position = new int[fieldsInfoA.size()]; |
|
250 |
|
|
251 |
// Initialize position array |
|
252 |
for (int i = 0; i < position.length; i++) |
|
253 |
position[i] = -1; |
|
254 |
|
|
255 |
// long timeFeat = 0; |
|
256 |
// long timeGeom = 0; |
|
257 |
// long timeTemp = 0; |
|
258 |
try { |
|
259 |
kxmlParser.setInput(lector); |
|
260 |
kxmlParser.nextTag(); |
|
261 |
|
|
262 |
if (kxmlParser.getEventType() != KXmlParser.END_DOCUMENT) { |
|
263 |
kxmlParser.require(KXmlParser.START_TAG, null, |
|
264 |
ServiceInfoTags.tARCXML); |
|
265 |
tag = kxmlParser.nextTag(); |
|
266 |
|
|
267 |
while (tag != KXmlParser.END_DOCUMENT) { |
|
268 |
switch (tag) { |
|
269 |
case KXmlParser.START_TAG: |
|
270 |
|
|
271 |
if (kxmlParser.getName().compareTo( |
|
272 |
GetFeaturesTags.FEATURE) == 0) { |
|
273 |
/* |
|
274 |
* parse FEATURES' tag |
|
275 |
*/ |
|
276 |
|
|
277 |
// FIRST ENVELOPE TAG (We hope that ENVELOPE will |
|
278 |
// ALLWAYS be returned at first...) |
|
279 |
if (withGeometries == 2) { |
|
280 |
// timeTemp = System.currentTimeMillis(); |
|
281 |
geom = parseEnvelopeFromFeatureTag(kxmlParser, |
|
282 |
delDec); |
|
283 |
} |
|
284 |
|
|
285 |
// SECOND FIELDS TAG |
|
286 |
// timeTemp = System.currentTimeMillis(); |
|
287 |
values = parseValuesFromFeatureTag(kxmlParser, // the |
|
288 |
// kxml |
|
289 |
// parser |
|
290 |
fieldsInfoA, // Hashmap with names and |
|
291 |
// FieldInformation objects) |
|
292 |
delDec, // the separators |
|
293 |
position // the relative positions of |
|
294 |
// returned values |
|
295 |
); |
|
296 |
|
|
297 |
// timeFeat += System.currentTimeMillis() - |
|
298 |
// timeTemp; |
|
299 |
|
|
300 |
// If geometries are neede we add to the ArrayList |
|
301 |
// the Ifeature |
|
302 |
if (withGeometries == 1) { |
|
303 |
// THIRD GEOMETRIES |
|
304 |
// timeTemp = System.currentTimeMillis(); |
|
305 |
geom = parseGeomFromFeatureTag(kxmlParser, // the |
|
306 |
// kxml |
|
307 |
// parser |
|
308 |
delTuple, delCoords, delDec // the |
|
309 |
// separators |
|
310 |
); |
|
311 |
|
|
312 |
// timeGeom += System.currentTimeMillis() - |
|
313 |
// timeTemp; |
|
314 |
} |
|
315 |
|
|
316 |
// If some geometry is created, we add a IFeature |
|
317 |
// into features ArrayList |
|
318 |
if (withGeometries > 0) { |
|
319 |
features.add(new DefaultFeature(geom, values)); |
|
320 |
} |
|
321 |
// Else we only need the Value[] array |
|
322 |
else { |
|
323 |
features.add(values); |
|
324 |
} |
|
325 |
} else if (kxmlParser.getName().compareTo( |
|
326 |
GetFeaturesTags.FEATURECOUNT) == 0) { |
|
327 |
String value = new String(); |
|
328 |
|
|
329 |
// Get the feature count |
|
330 |
value = kxmlParser.getAttributeValue("", |
|
331 |
GetFeaturesTags.COUNT); |
|
332 |
|
|
333 |
Integer intFeatCount = new Integer(value); |
|
334 |
featCount += intFeatCount.intValue(); |
|
335 |
|
|
336 |
// Get the hasmore boolean |
|
337 |
value = kxmlParser.getAttributeValue("", |
|
338 |
GetFeaturesTags.HASMORE); |
|
339 |
|
|
340 |
Boolean boHasMore = new Boolean(value); |
|
341 |
hasMore = boHasMore.booleanValue(); |
|
342 |
} else if (kxmlParser.getName().compareTo( |
|
343 |
ServiceInfoTags.tERROR) == 0) { |
|
344 |
logger.error("Error parsing GET_FEATURES:\r\n" |
|
345 |
+ kxmlParser.nextText()); |
|
346 |
throw new ArcImsException("arcims_server_error"); |
|
347 |
} |
|
348 |
|
|
349 |
break; |
|
350 |
|
|
351 |
case KXmlParser.END_TAG: |
|
352 |
break; |
|
353 |
|
|
354 |
case KXmlParser.TEXT: |
|
355 |
break; |
|
356 |
} |
|
357 |
|
|
358 |
tag = kxmlParser.next(); |
|
359 |
} |
|
360 |
|
|
361 |
kxmlParser.require(KXmlParser.END_DOCUMENT, null, null); |
|
362 |
} |
|
363 |
} catch (ParseException pe) { |
|
364 |
logger.error(pe.getMessage(), pe); |
|
365 |
throw new ArcImsException("arcims_no_features"); |
|
366 |
} catch (XmlPullParserException parser_ex) { |
|
367 |
logger.error(parser_ex.getMessage(), parser_ex); |
|
368 |
throw new ArcImsException("arcims_no_features"); |
|
369 |
} catch (IOException ioe) { |
|
370 |
logger.error(ioe.getMessage(), ioe); |
|
371 |
throw new ArcImsException("arcims_no_features"); |
|
372 |
} |
|
373 |
|
|
374 |
// logger.debug("Time for parsing features " + timeFeat + " msecs"); |
|
375 |
// logger.debug("Time for parsing geometries " + timeGeom + " msecs"); |
|
376 |
return features; |
|
243 |
// Value[] values = new Value[fieldsInfoA.size()]; |
|
244 |
// int[] position = new int[fieldsInfoA.size()]; |
|
245 |
// |
|
246 |
// // Initialize position array |
|
247 |
// for (int i = 0; i < position.length; i++) |
|
248 |
// position[i] = -1; |
|
249 |
// |
|
250 |
// // long timeFeat = 0; |
|
251 |
// // long timeGeom = 0; |
|
252 |
// // long timeTemp = 0; |
|
253 |
// try { |
|
254 |
// kxmlParser.setInput(lector); |
|
255 |
// kxmlParser.nextTag(); |
|
256 |
// |
|
257 |
// if (kxmlParser.getEventType() != KXmlParser.END_DOCUMENT) { |
|
258 |
// kxmlParser.require(KXmlParser.START_TAG, null, |
|
259 |
// ServiceInfoTags.tARCXML); |
|
260 |
// tag = kxmlParser.nextTag(); |
|
261 |
// |
|
262 |
// while (tag != KXmlParser.END_DOCUMENT) { |
|
263 |
// switch (tag) { |
|
264 |
// case KXmlParser.START_TAG: |
|
265 |
// |
|
266 |
// if (kxmlParser.getName().compareTo( |
|
267 |
// GetFeaturesTags.FEATURE) == 0) { |
|
268 |
// /* |
|
269 |
// * parse FEATURES' tag |
|
270 |
// */ |
|
271 |
// |
|
272 |
// // FIRST ENVELOPE TAG (We hope that ENVELOPE will |
|
273 |
// // ALLWAYS be returned at first...) |
|
274 |
// if (withGeometries == 2) { |
|
275 |
// // timeTemp = System.currentTimeMillis(); |
|
276 |
// geom = parseEnvelopeFromFeatureTag(kxmlParser, |
|
277 |
// delDec); |
|
278 |
// } |
|
279 |
// |
|
280 |
// // SECOND FIELDS TAG |
|
281 |
// // timeTemp = System.currentTimeMillis(); |
|
282 |
// values = parseValuesFromFeatureTag(kxmlParser, // the |
|
283 |
// // kxml |
|
284 |
// // parser |
|
285 |
// fieldsInfoA, // Hashmap with names and |
|
286 |
// // FieldInformation objects) |
|
287 |
// delDec, // the separators |
|
288 |
// position // the relative positions of |
|
289 |
// // returned values |
|
290 |
// ); |
|
291 |
// |
|
292 |
// // timeFeat += System.currentTimeMillis() - |
|
293 |
// // timeTemp; |
|
294 |
// |
|
295 |
// // If geometries are neede we add to the ArrayList |
|
296 |
// // the Ifeature |
|
297 |
// if (withGeometries == 1) { |
|
298 |
// // THIRD GEOMETRIES |
|
299 |
// // timeTemp = System.currentTimeMillis(); |
|
300 |
// geom = parseGeomFromFeatureTag(kxmlParser, // the |
|
301 |
// // kxml |
|
302 |
// // parser |
|
303 |
// delTuple, delCoords, delDec // the |
|
304 |
// // separators |
|
305 |
// ); |
|
306 |
// |
|
307 |
// // timeGeom += System.currentTimeMillis() - |
|
308 |
// // timeTemp; |
|
309 |
// } |
|
310 |
// |
|
311 |
// // If some geometry is created, we add a IFeature |
|
312 |
// // into features ArrayList |
|
313 |
// if (withGeometries > 0) { |
|
314 |
// features.add(new DefaultFeature(geom, values)); |
|
315 |
// } |
|
316 |
// // Else we only need the Value[] array |
|
317 |
// else { |
|
318 |
// features.add(values); |
|
319 |
// } |
|
320 |
// } else if (kxmlParser.getName().compareTo( |
|
321 |
// GetFeaturesTags.FEATURECOUNT) == 0) { |
|
322 |
// String value = new String(); |
|
323 |
// |
|
324 |
// // Get the feature count |
|
325 |
// value = kxmlParser.getAttributeValue("", |
|
326 |
// GetFeaturesTags.COUNT); |
|
327 |
// |
|
328 |
// Integer intFeatCount = new Integer(value); |
|
329 |
// featCount += intFeatCount.intValue(); |
|
330 |
// |
|
331 |
// // Get the hasmore boolean |
|
332 |
// value = kxmlParser.getAttributeValue("", |
|
333 |
// GetFeaturesTags.HASMORE); |
|
334 |
// |
|
335 |
// Boolean boHasMore = new Boolean(value); |
|
336 |
// hasMore = boHasMore.booleanValue(); |
|
337 |
// } else if (kxmlParser.getName().compareTo( |
|
338 |
// ServiceInfoTags.tERROR) == 0) { |
|
339 |
// logger.error("Error parsing GET_FEATURES:\r\n" |
|
340 |
// + kxmlParser.nextText()); |
|
341 |
// throw new ArcImsException("arcims_server_error"); |
|
342 |
// } |
|
343 |
// |
|
344 |
// break; |
|
345 |
// |
|
346 |
// case KXmlParser.END_TAG: |
|
347 |
// break; |
|
348 |
// |
|
349 |
// case KXmlParser.TEXT: |
|
350 |
// break; |
|
351 |
// } |
|
352 |
// |
|
353 |
// tag = kxmlParser.next(); |
|
354 |
// } |
|
355 |
// |
|
356 |
// kxmlParser.require(KXmlParser.END_DOCUMENT, null, null); |
|
357 |
// } |
|
358 |
// } catch (ParseException pe) { |
|
359 |
// logger.error(pe.getMessage(), pe); |
|
360 |
// throw new ArcImsException("arcims_no_features"); |
|
361 |
// } catch (XmlPullParserException parser_ex) { |
|
362 |
// logger.error(parser_ex.getMessage(), parser_ex); |
|
363 |
// throw new ArcImsException("arcims_no_features"); |
|
364 |
// } catch (IOException ioe) { |
|
365 |
// logger.error(ioe.getMessage(), ioe); |
|
366 |
// throw new ArcImsException("arcims_no_features"); |
|
367 |
// } |
|
368 |
// |
|
369 |
// // logger.debug("Time for parsing features " + timeFeat + " msecs"); |
|
370 |
// // logger.debug("Time for parsing geometries " + timeGeom + |
|
371 |
// " msecs"); |
|
372 |
// return features; |
|
373 |
return null; |
|
377 | 374 |
} |
378 | 375 |
|
379 | 376 |
/** |
... | ... | |
435 | 432 |
polyline.moveTo(bb.getXmin(), bb.getYmin()); |
436 | 433 |
polyline.lineTo(bb.getXmax(), bb.getYmax()); |
437 | 434 |
|
438 |
return ShapeFactory.createPolyline2D(polyline); |
|
435 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
436 |
Geometry curve = null; |
|
437 |
try { |
|
438 |
curve = geomManager.createCurve(polyline, |
|
439 |
Geometry.SUBTYPES.GEOM2D); |
|
440 |
} catch (CreateGeometryException e) { |
|
441 |
logger.error("Error creating curve", e); |
|
442 |
return null; |
|
443 |
} |
|
444 |
return curve; |
|
439 | 445 |
} else { |
440 | 446 |
return null; |
441 | 447 |
} |
448 |
|
|
442 | 449 |
} |
443 | 450 |
|
444 | 451 |
/** |
... | ... | |
449 | 456 |
* @return |
450 | 457 |
* @throws IOException |
451 | 458 |
* @throws XmlPullParserException |
459 |
* @throws IOException |
|
460 |
* @throws XmlPullParserException |
|
452 | 461 |
* @throws ArcImsException |
462 |
* @throws ArcImsException |
|
453 | 463 |
* @throws ParseException |
454 | 464 |
*/ |
455 |
private Value[] parseValuesFromFeatureTag(KXmlParser parser,
|
|
456 |
ArrayList fieldsInfoA, char delDec, int[] position)
|
|
457 |
throws XmlPullParserException, IOException, ArcImsException,
|
|
458 |
ParseException { |
|
465 |
private Object[] parseValuesFromFeatureTag(KXmlParser parser,
|
|
466 |
List fieldsInfoA, char delDec, int[] position) |
|
467 |
throws XmlPullParserException, IOException, ArcImsException {
|
|
468 |
|
|
459 | 469 |
int currentTag; |
460 | 470 |
boolean end = false; |
461 | 471 |
int f = 0; |
462 | 472 |
String att; |
463 |
String val;
|
|
473 |
String text;
|
|
464 | 474 |
int type; |
465 | 475 |
|
466 |
Value[] values = new Value[fieldsInfoA.size()];
|
|
476 |
Object[] values = new Object[fieldsInfoA.size()];
|
|
467 | 477 |
|
468 |
// parser.require(KXmlParser.START_TAG,null,GetFeaturesTags.FIELDS); |
|
469 | 478 |
currentTag = parser.next(); |
470 | 479 |
|
471 | 480 |
while (!end) { |
... | ... | |
474 | 483 |
|
475 | 484 |
if (parser.getName().equals(GetFeaturesTags.FIELD)) { |
476 | 485 |
att = parser.getAttributeValue("", GetFeaturesTags.NAME); |
477 |
val = parser.getAttributeValue("", GetFeaturesTags.VALUE);
|
|
486 |
text = parser.getAttributeValue("", GetFeaturesTags.VALUE);
|
|
478 | 487 |
|
479 | 488 |
/* |
480 | 489 |
* As NAME is known, we need to get the position of that |
... | ... | |
491 | 500 |
} |
492 | 501 |
|
493 | 502 |
// This way we can create a NullValue |
494 |
if (val.equals("")) {
|
|
495 |
val = null;
|
|
503 |
if (text.equals("")) {
|
|
504 |
text = null;
|
|
496 | 505 |
} |
497 | 506 |
|
498 | 507 |
/* |
... | ... | |
503 | 512 |
.getType(); |
504 | 513 |
|
505 | 514 |
// Add the Value into the correct position |
506 |
values[position[f]] = ArcImsValueFactory.createValueByType( |
|
507 |
val, type, delDec); |
|
508 |
|
|
509 |
// logger.info(att + " ("+type+")\t" + |
|
510 |
// values[f].toString()); |
|
511 |
f++; |
|
515 |
if (text == null) { |
|
516 |
values[position[f]] = null; |
|
517 |
} else { |
|
518 |
switch (type) { |
|
519 |
case FieldInformation.BOOLEAN: |
|
520 |
values[position[f]] = new Boolean(text); |
|
521 |
f++; |
|
522 |
break; |
|
523 |
case FieldInformation.SHAPE: |
|
524 |
case FieldInformation.STRING: |
|
525 |
values[position[f]] = new String(text); |
|
526 |
f++; |
|
527 |
break; |
|
528 |
case FieldInformation.DATE: |
|
529 |
values[position[f]] = new Date(Long.parseLong(text)); |
|
530 |
f++; |
|
531 |
break; |
|
532 |
case FieldInformation.FLOAT: |
|
533 |
String textfloat = text.replace(delDec, '.'); |
|
534 |
values[position[f]] = new Float(textfloat); |
|
535 |
f++; |
|
536 |
break; |
|
537 |
case FieldInformation.DOUBLE: |
|
538 |
String textdouble = text.replace(delDec, '.'); |
|
539 |
values[position[f]] = new Double(textdouble); |
|
540 |
f++; |
|
541 |
break; |
|
542 |
case FieldInformation.SMALLINT: |
|
543 |
values[position[f]] = new Short(text); |
|
544 |
f++; |
|
545 |
break; |
|
546 |
case FieldInformation.BIGINT: |
|
547 |
values[position[f]] = new Long(text); |
|
548 |
f++; |
|
549 |
break; |
|
550 |
case FieldInformation.ID: |
|
551 |
case FieldInformation.INTEGER: |
|
552 |
values[position[f]] = new Integer(text); |
|
553 |
f++; |
|
554 |
break; |
|
555 |
default: |
|
556 |
values[position[f]] = new String(text); |
|
557 |
f++; |
|
558 |
} |
|
559 |
} |
|
512 | 560 |
} |
513 | 561 |
|
514 | 562 |
break; |
... | ... | |
531 | 579 |
} |
532 | 580 |
|
533 | 581 |
return values; |
582 |
|
|
534 | 583 |
} |
535 | 584 |
|
536 | 585 |
/** |
... | ... | |
576 | 625 |
* @return @see com.hardcode.gdbms.engine.values.Value.IFeature |
577 | 626 |
* @throws IOException |
578 | 627 |
* @throws XmlPullParserException |
628 |
* @throws IOException |
|
629 |
* @throws XmlPullParserException |
|
630 |
* @throws CreateGeometryException |
|
579 | 631 |
* @throws ArcImsException |
632 |
* @throws CreateGeometryException |
|
633 |
* @throws ArcImsException |
|
580 | 634 |
*/ |
581 | 635 |
private Geometry parseGeomFromFeatureTag(KXmlParser parser, |
582 |
String delTuple, String delCoords, char delDec) throws IOException, |
|
583 |
XmlPullParserException, ArcImsException { |
|
636 |
String delTuple, String delCoords, char delDec) |
|
637 |
throws XmlPullParserException, IOException, |
|
638 |
CreateGeometryException, ArcImsException { |
|
639 |
|
|
640 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
584 | 641 |
int currentTag; |
585 | 642 |
boolean end = false; |
586 |
|
|
587 | 643 |
Geometry geom = null; |
588 |
|
|
589 | 644 |
currentTag = parser.next(); |
590 | 645 |
|
591 | 646 |
while (!end) { |
... | ... | |
593 | 648 |
|
594 | 649 |
switch (currentTag) { |
595 | 650 |
case KXmlParser.START_TAG: |
596 |
|
|
651 |
// ////////////////////////// |
|
652 |
// geometry type MULTIPOINT |
|
653 |
// ////////////////////////// |
|
597 | 654 |
if (featType.equals(GetFeaturesTags.MULTIPOINT)) { |
598 | 655 |
// Go to COORDS tag |
599 | 656 |
parser.nextTag(); |
... | ... | |
603 | 660 |
String strPoints = parser.nextText(); |
604 | 661 |
|
605 | 662 |
// Get the points from COORDS string |
606 |
ArrayList points = parseCoords(strPoints, delTuple,
|
|
663 |
List<Point> points = parseCoords(strPoints, delTuple,
|
|
607 | 664 |
delCoords, delDec); |
608 | 665 |
|
609 |
// Convert these collections to array of doubles |
|
610 |
// (primitive type) |
|
611 |
double[] xD = new double[points.size()]; |
|
612 |
double[] yD = new double[points.size()]; |
|
613 |
|
|
614 |
int size = xD.length; |
|
615 |
|
|
616 |
for (int i = 0; i < size; i++) { |
|
617 |
xD[0] = ((Point2D) points.get(i)).getX(); |
|
618 |
yD[0] = ((Point2D) points.get(i)).getY(); |
|
666 |
geom = geomManager.create(Geometry.TYPES.MULTIPOINT, |
|
667 |
Geometry.SUBTYPES.GEOM2D); |
|
668 |
MultiPoint2D mpoint = (MultiPoint2D) geom; |
|
669 |
for (Point point : points) { |
|
670 |
mpoint.addPoint(point); |
|
619 | 671 |
} |
620 |
|
|
621 |
// Get the geometry |
|
622 |
|
|
623 |
// BUG in 1.0 FMultiPoint2D(double[] x, double[] y) |
|
624 |
// geom = ShapeFactory.createMultipoint2D(xD,yD); |
|
625 |
|
|
626 |
// We will use another way to construct the geom object |
|
627 |
Point2D[] fpoints = new Point2D[size]; |
|
628 |
|
|
629 |
for (int i = 0; i < size; i++) { |
|
630 |
fpoints[i] = new Point2D(xD[i], yD[i]); |
|
631 |
} |
|
632 |
|
|
633 |
geom = new FMultiPoint2D(fpoints); |
|
634 | 672 |
} else { |
635 | 673 |
logger.error("Error parsing MULTIPOINT tag"); |
636 | 674 |
throw new ArcImsException("arcims_features_error"); |
637 | 675 |
} |
638 |
} else if (featType.equals(GetFeaturesTags.POLYLINE) |
|
676 |
} |
|
677 |
// //////////////////////////////////////////// |
|
678 |
// POLYLINE or POLYGON |
|
679 |
// //////////////////////////////////////////// |
|
680 |
else if (featType.equals(GetFeaturesTags.POLYLINE) |
|
639 | 681 |
|| featType.equals(GetFeaturesTags.POLYGON)) { |
640 | 682 |
// Parse while parser doesn't found </FEATURES> tag |
641 | 683 |
// The GeneralPath to store the different paths |
... | ... | |
652 | 694 |
String strPoints = parser.nextText(); |
653 | 695 |
|
654 | 696 |
// Get the points (Point2D) from COORDS string |
655 |
ArrayList points = parseCoords(strPoints,
|
|
697 |
List<Point> points = parseCoords(strPoints,
|
|
656 | 698 |
delTuple, delCoords, delDec); |
657 | 699 |
|
658 | 700 |
Iterator it = points.iterator(); |
659 |
Point2D point;
|
|
701 |
Point point; |
|
660 | 702 |
|
661 | 703 |
// First we MOVE to the first point of the path |
662 |
point = (Point2D) it.next();
|
|
704 |
point = (Point) it.next(); |
|
663 | 705 |
polyline.moveTo(point.getX(), point.getY()); |
664 | 706 |
|
665 | 707 |
// And now we can LINE to the rest of the points |
666 | 708 |
// of the path |
667 | 709 |
while (it.hasNext()) { |
668 |
point = (Point2D) it.next();
|
|
710 |
point = (Point) it.next(); |
|
669 | 711 |
polyline.lineTo(point.getX(), point.getY()); |
670 | 712 |
} |
671 | 713 |
} |
... | ... | |
690 | 732 |
} |
691 | 733 |
|
692 | 734 |
if (featType.equals(GetFeaturesTags.POLYLINE)) { |
693 |
geom = ShapeFactory.createPolyline2D(polyline); |
|
735 |
geom = geomManager.createMultiCurve(polyline, |
|
736 |
Geometry.SUBTYPES.GEOM2D); |
|
694 | 737 |
} else if (featType.equals(GetFeaturesTags.POLYGON)) { |
695 |
geom = ShapeFactory.createPolygon2D(polyline); |
|
738 |
geom = geomManager.createMultiSurface(polyline, |
|
739 |
Geometry.SUBTYPES.GEOM2D); |
|
696 | 740 |
} |
697 | 741 |
} |
698 | 742 |
|
... | ... | |
727 | 771 |
* @param delCoords |
728 | 772 |
* @param delDec |
729 | 773 |
* @return |
774 |
* @throws CreateGeometryException |
|
730 | 775 |
*/ |
731 |
private ArrayList parseCoords(String strCoords, String delTuple, |
|
732 |
String delCoords, char delDec) { |
|
776 |
private List<Point> parseCoords(String strCoords, String delTuple, |
|
777 |
String delCoords, char delDec) throws CreateGeometryException { |
|
778 |
|
|
779 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
780 |
List<Point> points = new ArrayList<Point>(); |
|
733 | 781 |
String tupla = new String(); |
734 |
ArrayList points = new ArrayList(); |
|
735 | 782 |
String[] tuplaPart; |
736 | 783 |
Double x; |
737 | 784 |
Double y; |
... | ... | |
757 | 804 |
x = new Double(tuplaPart[0]); |
758 | 805 |
y = new Double(tuplaPart[1]); |
759 | 806 |
|
760 |
// Version with in-loop replacing |
|
761 |
/* |
|
762 |
* if (delDec!='.'){ x = new |
|
763 |
* Double(tuplaPart[0].replace(delDec,'.')); y = new |
|
764 |
* Double(tuplaPart[1].replace(delDec,'.')); } else{ x = new |
|
765 |
* Double(tuplaPart[0]); y = new Double(tuplaPart[1]); } |
|
766 |
*/ |
|
767 |
points.add(new Point2D.Double(x.doubleValue(), y.doubleValue())); |
|
807 |
Point pto = geomManager.createPoint(x.doubleValue(), y |
|
808 |
.doubleValue(), Geometry.SUBTYPES.GEOM2D); |
|
809 |
points.add(pto); |
|
768 | 810 |
} |
769 | 811 |
|
770 |
// Return an array op Point2D objects
|
|
812 |
// Return an array of Point objects
|
|
771 | 813 |
return points; |
772 | 814 |
} |
773 | 815 |
|
... | ... | |
857 | 899 |
* @return |
858 | 900 |
* @throws ArcImsException |
859 | 901 |
*/ |
860 |
public ArrayList getAttributes(ArcImsVectStatus status, String[] subfields,
|
|
902 |
public List getAttributes(ArcImsVectStatus status, String[] subfields, |
|
861 | 903 |
String where, Rectangle2D envelope) throws ArcImsException { |
862 |
// //TEST |
|
863 |
// try { |
|
864 |
// boolean flag = true; |
|
865 |
// IntValue iv; |
|
866 |
// IdsReader ids = new IdsReader(status, "#ID#"); |
|
867 |
// while (flag) { |
|
868 |
// iv = ids.readId(); |
|
869 |
// if (iv!=null) |
|
870 |
// logger.info("ID = " + iv.intValue()); |
|
871 |
// else |
|
872 |
// flag = false; |
|
873 |
// } |
|
874 |
// } catch (IOException e) { |
|
875 |
// e.printStackTrace(); |
|
876 |
// } catch (ArcImsException e) { |
|
877 |
// e.printStackTrace(); |
|
878 |
// } |
|
904 |
|
|
879 | 905 |
logger.info("Start getAttributes"); |
880 | 906 |
|
881 |
ArrayList valuesArray = new ArrayList();
|
|
907 |
List valuesArray = new ArrayList(); |
|
882 | 908 |
|
883 | 909 |
// Clone the status and set temporal subfields and where clause |
884 | 910 |
ArcImsVectStatus statusCloned = status; |
885 | 911 |
|
886 | 912 |
String[] subTemp = status.getSubfields(); |
887 | 913 |
String whereTemp = status.getWhere(); |
888 |
Rectangle2D rectTemp = status.getExtent();
|
|
914 |
Rectangle2D rectTemp = status.getEnvelopeRect();
|
|
889 | 915 |
|
890 | 916 |
statusCloned.setSubfields(subfields); |
891 | 917 |
statusCloned.setWhere(where); |
... | ... | |
963 | 989 |
String layerId = (String) statusCloned.getLayerIds().get(0); |
964 | 990 |
logger.debug("Start attributes downloading and parsing (" |
965 | 991 |
+ featCount + ") ids retrieved"); |
966 |
valuesArray.addAll(getFeatures(br, statusCloned |
|
967 |
.getServiceInfo(), layerId, |
|
968 |
statusCloned.getSubfields(), 0)); |
|
992 |
valuesArray.add(getFeatures(br, statusCloned.getServiceInfo(), |
|
993 |
layerId, statusCloned.getSubfields(), 0)); |
|
969 | 994 |
logger.debug("End attributes downloading and parsing"); |
970 | 995 |
} |
971 | 996 |
|
... | ... | |
1003 | 1028 |
public ArrayList getAttributesWithEnvelope(ArcImsVectStatus status, |
1004 | 1029 |
String[] subfields, String where, Rectangle2D envelope) |
1005 | 1030 |
throws ArcImsException { |
1006 |
// //TEST |
|
1007 |
// try { |
|
1008 |
// boolean flag = true; |
|
1009 |
// IntValue iv; |
|
1010 |
// IdsReader ids = new IdsReader(status, "#ID#"); |
|
1011 |
// while (flag) { |
|
1012 |
// iv = ids.readId(); |
|
1013 |
// if (iv!=null) |
|
1014 |
// logger.info("ID = " + iv.intValue()); |
|
1015 |
// else |
|
1016 |
// flag = false; |
|
1017 |
// } |
|
1018 |
// } catch (IOException e) { |
|
1019 |
// e.printStackTrace(); |
|
1020 |
// } catch (ArcImsException e) { |
|
1021 |
// e.printStackTrace(); |
|
1022 |
// } |
|
1031 |
|
|
1023 | 1032 |
logger.info("Start getAttributesWihtEnvelope"); |
1024 | 1033 |
|
1025 | 1034 |
ArrayList valuesArray = new ArrayList(); |
... | ... | |
1029 | 1038 |
|
1030 | 1039 |
String[] subTemp = status.getSubfields(); |
1031 | 1040 |
String whereTemp = status.getWhere(); |
1032 |
Rectangle2D rectTemp = status.getExtent();
|
|
1041 |
Rectangle2D rectTemp = status.getEnvelopeRect();
|
|
1033 | 1042 |
|
1034 | 1043 |
statusCloned.setSubfields(subfields); |
1035 | 1044 |
statusCloned.setWhere(where); |
... | ... | |
1107 | 1116 |
String layerId = (String) statusCloned.getLayerIds().get(0); |
1108 | 1117 |
logger.debug("Start attributes downloading and parsing (" |
1109 | 1118 |
+ featCount + ") ids retrieved"); |
1110 |
valuesArray.addAll(getFeatures(br, statusCloned
|
|
1111 |
.getServiceInfo(), layerId,
|
|
1112 |
statusCloned.getSubfields(), 2)); // Here we request
|
|
1113 |
// envelopes instead
|
|
1114 |
// of geometries
|
|
1119 |
valuesArray.add(getFeatures(br, statusCloned.getServiceInfo(),
|
|
1120 |
layerId, statusCloned.getSubfields(), 2)); // Here we
|
|
1121 |
// request
|
|
1122 |
// envelopes instead |
|
1123 |
// of geometries |
|
1115 | 1124 |
logger.debug("End attributes downloading and parsing"); |
1116 | 1125 |
} |
1117 | 1126 |
|
Also available in: Unified diff