English

FAQ: How can a complete geometry of a selected feature be returned in a FeatureLayer using Java Connector?

Question

How can a complete geometry of a selected feature be returned in a FeatureLayer using Java Connector?

Answer

The article in the Related Information section below describes how to retrieve the coordinate list for a feature using the com.esri.aims.mtier.model.map.layer.query.Geometry class.

However, while using the class mentioned above, it is not possible to determine different Paths that make a PolyLine feature, or Rings and Holes that make a Polygon feature.

To get complete geometric information of an individual part of a feature, use the com.esri.aims.mtier.model.map.layer.query.GeometryRecordset class.

It is necessary to pass an ArcXML response in the String format as an argument to this class. The example code given below illustrates how to get an ArcXML response in String format and pass it to the GeometryRecordset class to get the complete geometry information of a feature.

Example Code (for World service from ArcIMS tutorial data)

<%@ page import="com.esri.aims.mtier.io.*,com.esri.aims.mtier.model.map.layer.FeatureLayer,
com.esri.aims.mtier.model.map.layer.query.*,com.esri.aims.mtier.model.acetate.Point,
com.esri.aims.mtier.model.acetate.Points,com.esri.aims.mtier.model.acetate.Polygon,
com.esri.aims.mtier.model.acetate.Hole,com.esri.aims.mtier.model.acetate.Ring" %>

<jsp:useBean id="connection" class="com.esri.aims.mtier.io.ConnectionProxy" scope="page" />
<jsp:useBean id="map" class="com.esri.aims.mtier.model.map.Map" scope="page" />
<HTML><HEAD><TITLE>Geometry Test</TITLE></HEAD>
<BODY bgcolor="#ffffff"><p align="left">

<%
//define server parameters
String hostName = "localhost"; //replace with app. server host name
int port = 5300; //replace with app. server port number
String serviceName = "world"; //replace with image service name

//define where expression
String whereExpression = "CNTRY_NAME='South Africa'"; //replace with where expression for filter

//define layer index
int index = 1; //replace with layer index

//set connection parameters
connection.setConnectionType(connection.TCP);
connection.setHost(hostName);
connection.setPort(port);
connection.setService(serviceName);

//initialize map
map.initMap(connection, 0, true, true, true, true);
map.setWidth(500);
map.setHeight(350);

//get feature layer and setGeometry=true
FeatureLayer fLayer = (FeatureLayer)map.getLayers().item(index);
map.getLayers().setGeometry(true);

//create and apply filter to layer
com.esri.aims.mtier.model.map.layer.query.Filter filter = new com.esri.aims.mtier.model.map.layer.query.Filter();
filter.setWhereExpression(whereExpression);
fLayer.setFilterObject(filter);

GeometryRecordset geometry = new GeometryRecordset();

//get current ArcXML request prepared by Map object
String arcxmlReq = map.getArcXML();

//send String axl request and get back String response
String arcXMLResponse = map.sendArcXML(arcxmlReq,map.GET_FEATURE);

// Stores all the Geometry Result after parsing
java.util.Vector vectorGeometry = new java.util.Vector();
vectorGeometry = geometry.getGeometry(null,null,arcXMLResponse);

//print out geometry of each parts
for (int i=0;i<vectorGeometry.size();i++){
// Iterate through only Polygon Object
if (vectorGeometry.get(i) instanceof Polygon){
Polygon polygon = (Polygon) vectorGeometry.get(i);
out.println("Polygon - Ring Count : " + polygon.getRingsCount());
out.println("<BR>");
// Iterate through only Ring Object
Ring ring = null;
for (int j=0;j<polygon.getRingsCount();j++){
ring = polygon.getRing(j);
for (int k=0;k<ring.getHolesCount();k++){
Hole hole = ring.getHole(k);
Points pts = hole.getPoints();
for (int l=0;l<pts.getCount();l++){
Point tPoint = pts.getPointObject(l);
out.println("Hole: X = "+ tPoint.getX() + ",Y="+ tPoint.getY());
out.println("<BR>");
}
}
Points ringPoints = ring.getPoints();
for (int k=0;k<ringPoints.getCount();k++){
Point tempPoint = ringPoints.getPointObject(k);
out.println("Ring " + (j+1) + " : X = "+ tempPoint.getX() + ",Y="+ tempPoint.getY());
out.println("<BR>");
}
out.println ("******************************");
out.println("<BR>");
}
}
}

%>

</td></tr></table>
</BODY>
</HTML>
   

Related Information