English

FAQ: Can I get the geometry of a selected feature in the Recordset using Java Connector?

Question

Can I get the geometry of a selected feature in the Recordset using Java Connector?

Answer

Yes, set Geometry to true on Layers as shown below:

Code:
//Do not forget to set the geometry to true
map.getLayers().setGeometry(true);
FeatureLayer fLayer = (FeatureLayer)map.getLayers().item(5);
Filter filter = new Filter();
filter.setWhereExpression("NAME = 'Campbell'");
fLayer.setFilterObject(filter);
map.refresh();
//get number of geometries returned
int geometryCount = fLayer.getRecordset().getGeometryCount();
//get the geometry of first feature in recordset
Geometry geom = fLayer.getRecordset().getGeometry(0);