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");表示查询要素属性表所有属性信息。

输出结果:

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:深蓝海洋 设计师:CSDN官方博客 返回首页
评论 1

打赏作者

gislaozhang

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值