PROBLEM

Unable to use Buffer class in Java Connector correctly when the buffer layer is same as target layer

Last Published: April 25, 2020

Description

The Buffer class in Java Connector works as expected when the target layer is different than the buffer source layer. However, if the target layer is the same as the buffer source layer, as in the following example code, the result is incorrect.

Code:

int blayer = 5;
int tlayer = 5;
FeatureLayer bufferLayer = FeatureLayer)map.getLayers().item(blayer);
FeatureLayer targetLayer = FeatureLayer)map.getLayers().item(tlayer);
....
buffer.setBufferTargetLayer(targetLayer);
....
filter.setWhereExpression("NAME='San Jose'");
...
bufferLayer.setFilterObject(filter);
....

Cause

With the above code, the given filter which should have been applied only to the buffer source, would be applied to the buffer target as well. This will result into an incorrect ArcXML request and hence incorrect response.

Solution or Workaround



To avoid applying the filter twice, create a new target layer and set the Recordset as in the following example code:

Code:
int blayer = 5;
int tlayer = 5;
FeatureLayer bufferLayer = FeatureLayer)map.getLayers().item(blayer);
FeatureLayer targeLayer = new FeatureLayer(bufferLayer.getID(),bufferLayer.getMaxScale(), bufferLayer.getMinScale());
targeLayer.setRecordset(bufferLayer.getRecordset());
....
buffer.setBufferTargetLayer(targetLayer);
....
filter.setWhereExpression("NAME='San Jose'");
...
bufferLayer.setFilterObject(filter);
....

To get the features within the buffer, get the Buffer Layer first after calling map.refresh() as shown in the example below:

Code:

map.refresh();
::::::::::::::::
::::::::::::::::
FeatureLayer bufferLayer = null;
for(int i=0; i<map.getLayers().getCount(); i++){
if(map.getLayers().item(i).getName().equals("BufferLayer")){
bufferLayer = (FeatureLayer)map.getLayers().item(i);
break;
}
}
if(bufferLayer!=null){
out.println(bufferLayer.getRecordset().getCount());
}

Note:
This workaround works only with Java Connector 4.0.1

Article ID:000005922

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic