Revision 32668 branches/v2_0_0_prep/libraries/org.gvsig.arcims/src/org/gvsig/remoteclient/arcims/ArcImsProtFeatureHandler.java
ArcImsProtFeatureHandler.java | ||
---|---|---|
52 | 52 |
import org.gvsig.fmap.geom.GeometryLocator; |
53 | 53 |
import org.gvsig.fmap.geom.GeometryManager; |
54 | 54 |
import org.gvsig.fmap.geom.aggregate.impl.MultiPoint2D; |
55 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
55 | 56 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
57 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
56 | 58 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
57 | 59 |
import org.gvsig.fmap.geom.primitive.Point; |
60 |
import org.gvsig.fmap.geom.primitive.impl.Point2D; |
|
58 | 61 |
import org.gvsig.remoteclient.arcims.exceptions.ArcImsException; |
59 | 62 |
import org.gvsig.remoteclient.arcims.utils.ArcImsDownloadUtils; |
60 | 63 |
import org.gvsig.remoteclient.arcims.utils.ArcImsFeature; |
... | ... | |
71 | 74 |
|
72 | 75 |
/** |
73 | 76 |
* @author jsanz |
77 |
* @author vsanjaime version 2.0 |
|
74 | 78 |
* |
75 | 79 |
*/ |
76 | 80 |
public class ArcImsProtFeatureHandler extends ArcImsProtocolHandler { |
... | ... | |
182 | 186 |
|
183 | 187 |
// fill features map |
184 | 188 |
FieldInformation fi = null; |
189 |
|
|
185 | 190 |
ServiceInformationLayerFeatures sil = (ServiceInformationLayerFeatures) si |
186 | 191 |
.getLayerById(layerId); |
187 | 192 |
|
... | ... | |
237 | 242 |
KXmlParser kxmlParser = new KXmlParser(); |
238 | 243 |
|
239 | 244 |
Geometry geom = null; |
240 |
//Object[] values = new Object[fieldsInfoA.size()]; |
|
245 |
Envelope envelope = null; |
|
246 |
// Object[] values = new Object[fieldsInfoA.size()]; |
|
241 | 247 |
// Value[] values = new Value[fieldsInfoA.size()]; |
242 | 248 |
int[] position = new int[fieldsInfoA.size()]; |
243 | 249 |
|
... | ... | |
258 | 264 |
tag = kxmlParser.nextTag(); |
259 | 265 |
|
260 | 266 |
while (tag != KXmlParser.END_DOCUMENT) { |
261 |
|
|
267 |
|
|
262 | 268 |
ArcImsFeature afeat = new ArcImsFeature(); |
263 |
|
|
269 |
|
|
264 | 270 |
switch (tag) { |
265 | 271 |
case KXmlParser.START_TAG: |
266 | 272 |
|
... | ... | |
274 | 280 |
// ALLWAYS be returned at first...) |
275 | 281 |
if (withGeometries == 2) { |
276 | 282 |
// timeTemp = System.currentTimeMillis(); |
277 |
geom = parseEnvelopeFromFeatureTag(kxmlParser,
|
|
278 |
delDec); |
|
279 |
afeat.putGeometry(geom); |
|
283 |
envelope = parseEnvelopeFromFeatureTag(
|
|
284 |
kxmlParser, delDec);
|
|
285 |
|
|
280 | 286 |
} |
281 | 287 |
|
282 | 288 |
// SECOND FIELDS TAG |
... | ... | |
288 | 294 |
// FieldInformation objects) |
289 | 295 |
delDec, // the separators |
290 | 296 |
position, // the relative positions of |
291 |
// returned values |
|
292 |
afeat |
|
293 |
); |
|
297 |
// returned values |
|
298 |
afeat); |
|
294 | 299 |
|
295 | 300 |
// timeFeat += System.currentTimeMillis() - |
296 | 301 |
// timeTemp; |
... | ... | |
305 | 310 |
// parser |
306 | 311 |
delTuple, delCoords, delDec // the |
307 | 312 |
// separators |
308 |
|
|
313 |
|
|
309 | 314 |
); |
310 |
afeat.putGeometry(geom); |
|
315 |
afeat.putGeometry(geom, envelope);
|
|
311 | 316 |
|
312 | 317 |
// timeGeom += System.currentTimeMillis() - |
313 | 318 |
// timeTemp; |
... | ... | |
354 | 359 |
case KXmlParser.TEXT: |
355 | 360 |
break; |
356 | 361 |
} |
357 |
if(afeat != null){
|
|
362 |
if (afeat != null) {
|
|
358 | 363 |
features.add(afeat); |
359 | 364 |
} |
360 | 365 |
tag = kxmlParser.next(); |
... | ... | |
388 | 393 |
* @throws XmlPullParserException |
389 | 394 |
* @throws IOException |
390 | 395 |
*/ |
391 |
private Geometry parseEnvelopeFromFeatureTag(KXmlParser parser, char delDec)
|
|
396 |
private Envelope parseEnvelopeFromFeatureTag(KXmlParser parser, char delDec)
|
|
392 | 397 |
throws XmlPullParserException, IOException { |
393 | 398 |
int currentTag; |
394 | 399 |
boolean end = false; |
... | ... | |
426 | 431 |
} |
427 | 432 |
} |
428 | 433 |
|
429 |
// If BoundaryBox object has been created, we can convert it into a
|
|
430 |
// IGeometry (polyline). |
|
434 |
// If BoundaryBox object has been created, we can convert it to Envelope
|
|
435 |
|
|
431 | 436 |
if (bb != null) { |
432 | 437 |
GeneralPathX polyline = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD); |
433 | 438 |
|
... | ... | |
435 | 440 |
polyline.lineTo(bb.getXmax(), bb.getYmax()); |
436 | 441 |
|
437 | 442 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
438 |
Geometry curve = null;
|
|
443 |
Envelope envelo = null;
|
|
439 | 444 |
try { |
440 |
curve = geomManager.createCurve(polyline, |
|
441 |
Geometry.SUBTYPES.GEOM2D); |
|
442 |
} catch (CreateGeometryException e) { |
|
445 |
envelo = geomManager.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
|
446 |
envelo.setLowerCorner(new Point2D(bb.getXmin(), bb.getYmin())); |
|
447 |
envelo.setUpperCorner(new Point2D(bb.getXmax(), bb.getYmax())); |
|
448 |
} catch (CreateEnvelopeException e) { |
|
443 | 449 |
logger.error("Error creating curve", e); |
444 | 450 |
return null; |
445 | 451 |
} |
446 |
return curve;
|
|
452 |
return envelo;
|
|
447 | 453 |
} else { |
448 | 454 |
return null; |
449 | 455 |
} |
... | ... | |
465 | 471 |
* @throws ParseException |
466 | 472 |
*/ |
467 | 473 |
private ArcImsFeature parseValuesFromFeatureTag(KXmlParser parser, |
468 |
List<FieldInformation> fieldsInfoA, char delDec, int[] position, ArcImsFeature afeat ) |
|
469 |
throws XmlPullParserException, IOException, ArcImsException { |
|
474 |
List<FieldInformation> fieldsInfoA, char delDec, int[] position, |
|
475 |
ArcImsFeature afeat) throws XmlPullParserException, IOException, |
|
476 |
ArcImsException { |
|
470 | 477 |
|
471 | 478 |
int currentTag; |
472 | 479 |
boolean end = false; |
... | ... | |
475 | 482 |
String text; |
476 | 483 |
int type; |
477 | 484 |
|
478 |
//Object[] values = new Object[fieldsInfoA.size()]; |
|
485 |
// Object[] values = new Object[fieldsInfoA.size()];
|
|
479 | 486 |
|
480 | 487 |
currentTag = parser.next(); |
481 | 488 |
|
... | ... | |
492 | 499 |
* attribute into the ArrayList of fieldInformation objects |
493 | 500 |
*/ |
494 | 501 |
if (position[f] == -1) { |
495 |
position[f] = getPosition(fieldsInfoA.iterator(), att);
|
|
502 |
position[f] = getPosition(fieldsInfoA.iterator(), att); |
|
496 | 503 |
} |
497 | 504 |
|
498 | 505 |
if (position[f] == -1) { |
... | ... | |
515 | 522 |
|
516 | 523 |
// Add the Value into the correct position |
517 | 524 |
if (text == null) { |
518 |
String fieldName = fieldsInfoA.get(position[f]).getName(); |
|
519 |
afeat.put(fieldName,null); |
|
525 |
String fieldName = fieldsInfoA.get(position[f]) |
|
526 |
.getName(); |
|
527 |
afeat.put(fieldName, null); |
|
520 | 528 |
} else { |
521 |
String fieldName = fieldsInfoA.get(position[f]).getName(); |
|
529 |
String fieldName = fieldsInfoA.get(position[f]) |
|
530 |
.getName(); |
|
522 | 531 |
switch (type) { |
523 | 532 |
case FieldInformation.BOOLEAN: |
524 |
afeat.put(fieldName,new Boolean(text)); |
|
533 |
afeat.put(fieldName, new Boolean(text));
|
|
525 | 534 |
f++; |
526 | 535 |
break; |
527 | 536 |
case FieldInformation.SHAPE: |
... | ... | |
530 | 539 |
f++; |
531 | 540 |
break; |
532 | 541 |
case FieldInformation.DATE: |
533 |
afeat.put(fieldName, new Date(Long.parseLong(text))); |
|
542 |
afeat |
|
543 |
.put(fieldName, new Date(Long |
|
544 |
.parseLong(text))); |
|
534 | 545 |
f++; |
535 | 546 |
break; |
536 | 547 |
case FieldInformation.FLOAT: |
... | ... | |
597 | 608 |
* @param att |
598 | 609 |
* @return |
599 | 610 |
*/ |
600 |
private int getPosition(Iterator it, String att) { |
|
611 |
private int getPosition(Iterator<FieldInformation> it, String att) {
|
|
601 | 612 |
int res = 0; |
602 | 613 |
FieldInformation fi; |
603 | 614 |
|
604 | 615 |
while (it.hasNext()) { |
605 |
fi = (FieldInformation) it.next();
|
|
616 |
fi = it.next(); |
|
606 | 617 |
|
607 | 618 |
if (fi.getName().equals(att)) { |
608 | 619 |
return res; |
... | ... | |
706 | 717 |
delTuple, delCoords, delDec); |
707 | 718 |
|
708 | 719 |
Iterator<Point> it = points.iterator(); |
709 |
Point point; |
|
710 |
|
|
711 | 720 |
// First we MOVE to the first point of the path |
712 |
point = (Point) it.next();
|
|
721 |
Point point = it.next();
|
|
713 | 722 |
polyline.moveTo(point.getX(), point.getY()); |
714 | 723 |
|
715 | 724 |
// And now we can LINE to the rest of the points |
716 | 725 |
// of the path |
717 | 726 |
while (it.hasNext()) { |
718 |
point = (Point) it.next();
|
|
719 |
polyline.lineTo(point.getX(), point.getY());
|
|
727 |
Point pto = it.next();
|
|
728 |
polyline.lineTo(pto.getX(), pto.getY());
|
|
720 | 729 |
} |
721 | 730 |
} |
722 | 731 |
|
... | ... | |
742 | 751 |
if (featType.equals(GetFeaturesTags.POLYLINE)) { |
743 | 752 |
geom = geomManager.createMultiCurve(polyline, |
744 | 753 |
Geometry.SUBTYPES.GEOM2D); |
754 |
|
|
745 | 755 |
} else if (featType.equals(GetFeaturesTags.POLYGON)) { |
746 | 756 |
geom = geomManager.createMultiSurface(polyline, |
747 | 757 |
Geometry.SUBTYPES.GEOM2D); |
... | ... | |
817 | 827 |
points.add(pto); |
818 | 828 |
} |
819 | 829 |
|
820 |
// Return an array of Point objects
|
|
830 |
// Return a list of Points
|
|
821 | 831 |
return points; |
822 | 832 |
} |
823 | 833 |
|
... | ... | |
995 | 1005 |
/* |
996 | 1006 |
* Parse response and return a Rectangle2D |
997 | 1007 |
*/ |
998 |
String layerId = (String) statusCloned.getLayersIdsSelected().get(0); |
|
1008 |
String layerId = (String) statusCloned.getLayersIdsSelected() |
|
1009 |
.get(0); |
|
999 | 1010 |
logger.debug("Start attributes downloading and parsing (" |
1000 | 1011 |
+ featCount + ") ids retrieved"); |
1001 | 1012 |
features.add(getFeatures(br, statusCloned.getServiceInfo(), |
... | ... | |
1122 | 1133 |
/* |
1123 | 1134 |
* Parse response and return a Rectangle2D |
1124 | 1135 |
*/ |
1125 |
String layerId = (String) statusCloned.getLayersIdsSelected().get(0); |
|
1136 |
String layerId = (String) statusCloned.getLayersIdsSelected() |
|
1137 |
.get(0); |
|
1126 | 1138 |
logger.debug("Start attributes downloading and parsing (" |
1127 | 1139 |
+ featCount + ") ids retrieved"); |
1128 | 1140 |
features.add(getFeatures(br, statusCloned.getServiceInfo(), |
... | ... | |
1164 | 1176 |
throw new ClassCastException( |
1165 | 1177 |
"Invalid request, this method is only valid for Image Services"); |
1166 | 1178 |
} |
1179 |
|
|
1180 |
|
|
1181 |
|
|
1182 |
/** |
|
1183 |
* Method to retrieve an ArrayList of features from an ArcIMS FeatureService |
|
1184 |
* |
|
1185 |
* @param status |
|
1186 |
* @return ArrayList of IFeatures with geometries and Id's to attribute |
|
1187 |
* table |
|
1188 |
* @throws ArcImsException |
|
1189 |
*/ |
|
1190 |
public List<ArcImsFeature> getFeaturesByEnvelope(ArcImsVectStatus status, String layerId) |
|
1191 |
throws ArcImsException { |
|
1192 |
logger.info("Start getMap"); |
|
1193 |
|
|
1194 |
List<ArcImsFeature> feats = new ArrayList<ArcImsFeature>(); |
|
1195 |
|
|
1196 |
try { |
|
1197 |
/* |
|
1198 |
* Build the request |
|
1199 |
*/ |
|
1200 |
URL url = new URL(buildCapabilitiesRequest(status)); |
|
1201 |
|
|
1202 |
hasMore = true; |
|
1203 |
featCount = 1; |
|
1204 |
|
|
1205 |
while (hasMore) { |
|
1206 |
/* |
|
1207 |
* Build the proper ArcXML |
|
1208 |
*/ |
|
1209 |
String request = ArcXMLFeatures.getFeaturesExtentRequest(status, featCount, layerId); |
|
1210 |
|
|
1211 |
if (status.verbose) { |
|
1212 |
System.err.println(request); |
|
1213 |
} |
|
1214 |
|
|
1215 |
/* |
|
1216 |
* Request the reader |
|
1217 |
*/ |
|
1218 |
logger.info("Start features downloading"); |
|
1219 |
|
|
1220 |
File f = ArcImsDownloadUtils.doRequestPost(url, request, |
|
1221 |
"getFeaturesEnvelope.xml"); |
|
1222 |
logger.info("End features downloading by envelope"); |
|
1223 |
|
|
1224 |
|
|
1225 |
// Deal with UTF-8 |
|
1226 |
Reader reader = null; |
|
1227 |
FileInputStream fis = new FileInputStream(f); |
|
1228 |
InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); |
|
1229 |
BufferedReader br = new BufferedReader(isr); |
|
1230 |
reader = br; |
|
1231 |
|
|
1232 |
logger.debug("Start features with attributes parsing"); |
|
1233 |
feats = this.getFeatures(reader, status |
|
1234 |
.getServiceInfo(), layerId, status.getSubfields(), 1); |
|
1235 |
|
|
1236 |
logger.debug("End features with attributes parsing"); |
|
1237 |
} |
|
1238 |
|
|
1239 |
hasMore = true; |
|
1240 |
featCount = 1; |
|
1241 |
} catch (MalformedURLException e) { |
|
1242 |
logger.error(e.getMessage(), e); |
|
1243 |
throw new ArcImsException("arcims_server_error"); |
|
1244 |
} catch (FileNotFoundException e) { |
|
1245 |
logger.error(e.getMessage(), e); |
|
1246 |
throw new ArcImsException("arcims_server_error"); |
|
1247 |
} catch (UnsupportedEncodingException e) { |
|
1248 |
logger.error(e.getMessage(), e); |
|
1249 |
} |
|
1250 |
|
|
1251 |
logger.debug("End getMap"); |
|
1252 |
|
|
1253 |
return feats; |
|
1254 |
} |
|
1167 | 1255 |
} |
Also available in: Unified diff