ArcGIS for Android 10.2.9(10):加载本地shp文件和shp文件要素查询

1.加载本地shp文件

/**
     * 加载本地shp文件
     */
    private void getLocalShpfile() {

        try {
            ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(shpPath);
            mFeatureLayer = new FeatureLayer(shapefileFeatureTable);
            mFeatureLayer.setRenderer(new SimpleRenderer(new SimpleFillSymbol(Color.RED)));
            mMapView.addLayer(mFeatureLayer);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

查询api:

featureTable.queryFeatures(QueryParameters query, CallbackListener<FeatureResult> callback)
featureTable.queryIds(QueryParameters query, CallbackListener callback)

2.点击查询shp文件要素

  /**
     * 点击查询
     */
    private void queryShpDataByClick() {
        mMapView.setOnSingleTapListener(new OnSingleTapListener() {
            @Override
            public void onSingleTap(float v, float v1) {
                Point point = mMapView.toMapPoint(v, v1);
                QueryParameters queryParameters = new QueryParameters();
                queryParameters.setGeometry(point);
                queryParameters.setReturnGeometry(true);
                mFeatureLayer.getFeatureTable().queryFeatures(queryParameters, new CallbackListener() {
                    @Override
                    public void onCallback(FeatureResult result) {
                        if (result != null) {

                            Iterator iterator = result.iterator();
                            while (iterator.hasNext()) {
                                Feature feature = (Feature) iterator.next();
                                Map attributes = feature.getAttributes();
                                Geometry geometry = feature.getGeometry();
                                Symbol symbol = feature.getSymbol();

                                //高亮显示
                                SimpleRenderer simpleRenderer = new SimpleRenderer(new SimpleFillSymbol(Color.RED));
                                mGraphicsLayer.setRenderer(simpleRenderer);
                                Graphic graphic = new Graphic(geometry, symbol, attributes);
                                mGraphicsLayer.removeAll();
                                mGraphicsLayer.addGraphic(graphic);

                                Set> entries = attributes.entrySet();
                                for (Map.Entry entry : entries) {
                                    Log.e("xyh", "getShpData: " + entry.getKey() + "===" + entry.getValue());
                                }
                            }
                        }
                    }

                    @Override
                    public void onError(Throwable throwable) {

                    }
                });

            }
        });
    }
 
  

也可采用featureTable.queryIds方法


                //也可采用featureTable.queryIds方法
                mFeatureLayer.getFeatureTable().queryIds(queryParameters, new CallbackListener<long[]>() {
                    @Override
                    public void onCallback(long[] ids) {
                        if (ids != null && ids.length > 0) {
                            for (long id : ids) {
                                Feature feature = mFeatureLayer.getFeature(id);
                                Map attributes = feature.getAttributes();
                                Geometry geometry = feature.getGeometry();
                                Symbol symbol = feature.getSymbol();

                                //....
                            }
                        }

                    }

                    @Override
                    public void onError(Throwable throwable) {

                    }
                });

3.条件语句查询shp文件要素

  /**
     * 条件语句查询
     */
    private void queryShpDataByWhereClause() {
        FeatureTable featureTable = mFeatureLayer.getFeatureTable();
        QueryParameters parameters = new QueryParameters();

        //查询条件:查询某个字段的值
        String whereClause = "FID='921'";
        parameters.setWhere(whereClause);
        parameters.setReturnGeometry(true);

        featureTable.queryFeatures(parameters, new CallbackListener() {
            @Override
            public void onCallback(FeatureResult result) {
                if (result != null) {
                    Iterator iterator = result.iterator();
                    while (iterator.hasNext()) {
                        Feature feature = (Feature) iterator.next();
                        Map attributes = feature.getAttributes();
                        Geometry geometry = feature.getGeometry();
                        Symbol symbol = feature.getSymbol();

                        //高亮显示
                        SimpleRenderer simpleRenderer = new SimpleRenderer(new SimpleFillSymbol(Color.RED));
                        mGraphicsLayer.setRenderer(simpleRenderer);
                        Graphic graphic = new Graphic(geometry, symbol, attributes);
                        mGraphicsLayer.removeAll();
                        mGraphicsLayer.addGraphic(graphic);

                        Set> entries = attributes.entrySet();
                        for (Map.Entry entry : entries) {
                            Log.e("xyh", "getShpData2: " + entry.getKey() + "===" + entry.getValue());
                        }
                    }
                }
            }

            @Override
            public void onError(Throwable throwable) {

            }
        });
    } 
  

其他查询方法:

 featureLayer.getFeatureIDs(float x, float y, int tolerance):屏幕坐标,半径
 mGraphicsLayer.getGraphicIDs(float x, float y, int tolerance):屏幕坐标,半径

GraphicsLayer的点击查询

 int[] graphicIds = graphicsLayer.getGraphicIDs(x, y, 8);  
    if (graphicIds!=null&&graphicIds.length>0) {  
        for (int i = 0; i < graphicIds.length; i++) {  
            Graphic graphic = graphicsLayer.getGraphic(graphicIds[i]);  
            Map<String,Object> attr = graphic.getAttributes();  
            Log.i(TAG, attr.get("name")+"===="+attr.get("mark"));  
        }  
    }  

你可能感兴趣的:(ArcGIS,for,Android10.2.9)