Android应用开发之arcgis for Android 100.2 加载shp
白羽 2018-12-19 来源 :网络 阅读 884 评论 0

摘要:本文将带你了解Android应用开发arcgis for Android 100.2 加载shp,希望本文对大家学Android有所帮助。

    本文将带你了解Android应用开发arcgis for Android 100.2 加载shp,希望本文对大家学Android有所帮助。



        

arcgis for Android 100.2 加载shp。

1、显示效果

2、实现代码


package com.arcgis.activity;

 

import android.graphics.Color;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.util.Log;

import android.view.MotionEvent;

 

import com.arcgis.R;

import com.arcgis.until.FilePathManage;

import com.esri.arcgisruntime.concurrent.ListenableFuture;

import com.esri.arcgisruntime.data.Feature;

import com.esri.arcgisruntime.data.FeatureQueryResult;

import com.esri.arcgisruntime.data.FeatureTable;

import com.esri.arcgisruntime.data.QueryParameters;

import com.esri.arcgisruntime.data.ShapefileFeatureTable;

import com.esri.arcgisruntime.geometry.Envelope;

import com.esri.arcgisruntime.geometry.Geometry;

import com.esri.arcgisruntime.geometry.GeometryType;

import com.esri.arcgisruntime.geometry.Point;

import com.esri.arcgisruntime.geometry.SpatialReference;

import com.esri.arcgisruntime.layers.FeatureLayer;

import com.esri.arcgisruntime.mapping.ArcGISMap;

import com.esri.arcgisruntime.mapping.Basemap;

import com.esri.arcgisruntime.mapping.view.DefaultMapViewOnTouchListener;

import com.esri.arcgisruntime.mapping.view.Graphic;

import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;

import com.esri.arcgisruntime.mapping.view.MapView;

import com.esri.arcgisruntime.mapping.view.SketchEditor;

import com.esri.arcgisruntime.mapping.view.SketchStyle;

import com.esri.arcgisruntime.symbology.SimpleFillSymbol;

import com.esri.arcgisruntime.symbology.SimpleLineSymbol;

import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol;

import com.esri.arcgisruntime.symbology.SimpleRenderer;

import java.util.Iterator;

import java.util.Map;

import java.util.concurrent.ExecutionException;

 

/**

 * 数据量大的时候,加载速度比较慢,有时候还没加载出来,一直在找

 * 最后又pc上软件知道shp的位置,比较好测试

 *

 * 还有shp 必须有least three files (.shp, .shx, .dbf) 如果有prj文件那就更好。位置准确

 *

 * 受之前10的版本影响,我一直在找怎么设置投影,其实是多余的。不用设置,接口都没有。里面已经处理好

 *

 */

public class ArcgisShpMapActivity extends AppCompatActivity {

 private MapView mMapView;

 private ShapefileFeatureTable shapefileFeatureTable;

 private ArcGISMap arcGISMap;

 private FeatureLayer featureLayer;

 private SketchEditor mainSketchEditor;

 private SketchStyle mainSketchStyle;

 

 private String shpName = "/DLJX.shp";

// private String shpName = "/未命名_20171130163924.shp";

 

 @Override

 protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_map);

  mMapView = (MapView) findViewById(R.id.map_view);

 

 

  showShapefile();

//  openShp();

 }

 

 //加载shp方式一

 private void openShp() {

  // 构建ShapefileFeatureTable,引入本地存储的shapefile文件

  shapefileFeatureTable = new ShapefileFeatureTable(

 FilePathManage.GetInstance().getShpDirectory() + shpName);

  shapefileFeatureTable.loadAsync();

  // 构建featureLayerr

  featureLayer = new FeatureLayer(shapefileFeatureTable);

  // 设置Shapefile文件的渲染方式

  SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.RED, 1.0f);

  SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.YELLOW, lineSymbol);

  SimpleRenderer renderer = new SimpleRenderer(fillSymbol);

  featureLayer.setRenderer(renderer);

  // 添加到地图的业务图层组中

  arcGISMap = new ArcGISMap(Basemap.createTopographic());

  arcGISMap.getOperationalLayers().add(featureLayer);

  // set the map to the map view

  mMapView.setMap(arcGISMap);

 }

 

 //加载shp方式二

 private void showShapefile() {

  mMapView.setAttributionTextVisible(false);

  arcGISMap = new ArcGISMap(new Basemap().createImageryWithLabelsVector());

  mMapView.setMap(arcGISMap);

  final ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(

 FilePathManage.GetInstance().getShpDirectory() + shpName);

  shapefileFeatureTable.loadAsync();

  shapefileFeatureTable.addDoneLoadingListener(new Runnable() {

@Override

public void run() {

 GeometryType gt = shapefileFeatureTable.getGeometryType();

 String name = shapefileFeatureTable.getTableName();

 featureLayer = new FeatureLayer(shapefileFeatureTable);

 if (featureLayer.getFullExtent() != null) {

  mMapView.setViewpointGeometryAsync(featureLayer.getFullExtent());

 } else {

  featureLayer.addDoneLoadingListener(new Runnable() {

@Override

public void run() {

 mMapView.setViewpointGeometryAsync(featureLayer.getFullExtent());

}

  });

 }

 arcGISMap.getOperationalLayers().add(featureLayer);

}

  });

 

 

  SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.RED, 1.0f);

  SimpleFillSymbol fillSymbol = n    

   

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Android频道!


本文由 @白羽 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程