HOW TO

Buffer and select features from a single layer in the Java Connector

Last Published: April 25, 2020

Summary

Instructions provided describe how to buffer and select features from a single layer in the Java Connector. To retrieve a list of features from the same layer being buffered requires an additional step that is not required when the buffer layer and selection layer are different. An example of this type of query is: How many cities are within 8 miles from the city San Jose?

Procedure

The extra step requires creating a new layer to use as the buffer layer. An incorrect result occurs when applying a filter that buffers and selects from the same layer without this step.

  1. Create a connection and initialize a Map object. The loadRecordset argument in Map.initMap() must be true.

    Code:
    map.initMap(connection,0,false,false,true,false);

  2. Reference the buffer layer.

    Code:
    FeatureLayer fLayer = (FeatureLayer)map.getLayers().item(5); //buffer layer

  3. Create a duplicate of the buffer layer to serve as the target layer for selecting features. Since the layers have the same underly innformation the new layer has the same layerID, MaxScale, MinScale, and Recordset.

    Code:
    FeatureLayer tLayer = new FeatureLayer(fLayer.getID(),fLayer.getMaxScale(),fLayer.getMinScale());
    tLayer.setRecordset(fLayer.getRecordset()); //tLayer is the target layer

  4. Create Filter and Buffer objects, set their properties, and apply them to the buffer layer.

    Code:
    Filter filter = new Filter();
    filter.setWhereExpression("NAME='San Jose'");
    Buffer buffer=new Buffer();
    buffer.setBufferUnits(Buffer.MILES);
    buffer.setBufferDistance(8);
    buffer.setPerformBuffer(true);
    buffer.setBufferRegionSymbol(ps);
    buffer.setBufferSelectionSymbol(ms);
    buffer.setBufferTargetLayer(tLayer);
    filter.setBufferObject(buffer);
    fLayer.setFilterObject(filter);

  5. The query result is found in a layer with the name 'bufferLayer'.

    Code:
    FeatureLayer resultLayer=null;
    Recordset recordset = null;
    for (int i=0;i<map.getLayers().getCount();i++){
    if (map.getLayers().item(i).getName().equalsIgnoreCase("bufferLayer")){
    resultLayer = (FeatureLayer)map.getLayers().item(i);
    break;
    }
    }

  6. To view a complete sample, create a service named SantaClara based on the SantaClara.axl, found in the ...\samples\TutorialData\Axl directory. Download and deploy BufferIsTarger.zip which buffers and retrieves information about all cities within 8 miles of San Jose.

Article ID:000006681

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