ArcGis for Android shp

一. ArcGis for Android 加载本地shp文件

首先在使用Arcgis for Android之前必须对此添加依赖

  1. 在project的build.gradle中添加以下代码
allprojects {
    repositories {
        jcenter()
        maven {
            url 'http://dl.bintray.com/esri/arcgis'
        }
    }
}
  1. Module中如下
android {
     packagingOptions {
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        }
   }
dependencies {
   compile 'com.esri.arcgis.android:arcgis-android:10.2.7'
   }

下面就是核心代码

String shpPath = getPath()+"/dilikuangja/路线.shp";
try {
    //传入文件路径
    ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(shpPath);
    FeatureLayer featureLayer = new FeatureLayer(shapefileFeatureTable);
    featureLayer1.setRenderer(new SimpleRenderer(new SimpleFillSymbol(Color.BLUE)));
    mMapView.addLayer(featureLayer);
    } catch (Exception e) {
       e.printStackTrace();
    }

   //getPath()方法
 public String getSDPath() {
        String sdDir = null;
        boolean sdCardExist = Environment.getExternalStorageState()
                .equals(android.os.Environment.MEDIA_MOUNTED);   //判断sd卡是否存在
        if (sdCardExist) {
            sdDir = Environment.getExternalStorageDirectory().getAbsolutePath();//获取跟目录
        }
        return sdDir.toString();

    }

添上测试的shp文件
http://download.csdn.net/download/mosquitoes_fly/10149579

你可能感兴趣的:(Android)