ArcGIS Runtime SDK for Android 100 获取要素图层属性信息

需求:

ArcGIS Runtime SDK for Android 100 获取要素图层属性信息

示例数据:

链接:https://pan.baidu.com/s/1AS48LQiP-QnrnWTywQ13Aw 
提取码:kjl8 


 

测试版本:

ArcGIS Runtime SDK for Android 100.10

示例代码:

package cn.geoscene.myapplication0303;

import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.esri.arcgisruntime.concurrent.ListenableFuture;
import com.esri.arcgisruntime.data.Feature;
import com.esri.arcgisruntime.data.FeatureQueryResult;
import com.esri.arcgisruntime.data.QueryParameters;
import com.esri.arcgisruntime.data.ShapefileFeatureTable;
import com.esri.arcgisruntime.layers.FeatureLayer;
import com.esri.arcgisruntime.loadable.LoadStatus;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.MapView;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private final static String TAG = MainActivity.class.getSimpleName();

    private MapView mMapView;
    private ShapefileFeatureTable shapefileFeatureTable;
    private FeatureLayer shapefileFeatureLayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // create a new map to display in the map view with a streets basemap
        mMapView = findViewById(R.id.mapView);
        ArcGISMap map = new ArcGISMap(Basemap.createLightGrayCanvas());
        mMapView.setMap(map);

        // load the shapefile with a local path
        shapefileFeatureTable = new ShapefileFeatureTable(
                getExternalFilesDir(null) + getString(R.string.bj3857_path1));

        // create a feature layer to display the shapefile
        shapefileFeatureLayer = new FeatureLayer(shapefileFeatureTable);
        // add the feature layer to the map
        mMapView.getMap().getOperationalLayers().add(shapefileFeatureLayer);

        shapefileFeatureTable.addDoneLoadingListener(() -> {
            if (shapefileFeatureTable.getLoadStatus() == LoadStatus.LOADED) {
                // zoom the map to the extent of the shapefile
                mMapView.setViewpointAsync(new Viewpoint(shapefileFeatureLayer.getFullExtent()));

                queryAttribute(shapefileFeatureLayer);
            } else {
                String error = "Shapefile feature table failed to load: " + shapefileFeatureTable.getLoadError().toString();
                Toast.makeText(MainActivity.this, error, Toast.LENGTH_LONG).show();
                Log.e(TAG, error);
            }
        });
    }


    /**
     *  属性查询
     * @param featureLayer

     */
    private void queryAttribute(FeatureLayer featureLayer) {


        QueryParameters query = new QueryParameters();
        query.setWhereClause("1=1");
        final ListenableFuture<FeatureQueryResult> featureQueryResult
                = featureLayer.getFeatureTable().queryFeaturesAsync(query);
        featureQueryResult.addDoneListener(new Runnable() {
            @Override
            public void run() {
                try {

                    List<Feature> mapQueryResult = new ArrayList<>();//查询统计结果

                    FeatureQueryResult result = featureQueryResult.get();
                    Iterator<Feature> iterator = result.iterator();
                    Feature feature;
                    int i=0;
                    while (iterator.hasNext()) {
                        feature = iterator.next();
                        mapQueryResult.add(feature);
                        i = i + 1;

                        Log.d("info", "i的值是: " + i);
                        Log.d("info", feature.getAttributes().toString());
                    }

                    Toast.makeText(MainActivity.this,"查询出"+mapQueryResult.size()+"个符合要求的结果",Toast.LENGTH_SHORT).show();

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        mMapView.pause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.resume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapView.dispose();
    }
}

上述设置查询条件query.setWhereClause("1=1");表示查询要素属性表所有属性信息。

输出结果:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值