2016-11-29 49 views
-3

我曾与下面的代码试图读取和显示shape文件从我的SD卡如何在Android中使用形状文件显示地图?

ShapefileFeatureTable shapefileFeatureTable = null; 
    try { 
     shapefileFeatureTable = new ShapefileFeatureTable(Environment.getExternalStorageDirectory().getAbsolutePath()+"/India_SHP/INDIA.shp"); 
     featureLayer = new FeatureLayer(shapefileFeatureTable); 
     featureLayer.setRenderer(new SimpleRenderer(new SimpleMarkerSymbol(
       getResources().getColor(android.R.color.holo_blue_bright), 
       28, SimpleMarkerSymbol.STYLE.CIRCLE))); 

     mMapView.addLayer(featureLayer); 

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

这里是我的应用程序的build.gradle文件的详细信息

dependencies { 
repositories { 
    jcenter() 
    // Add the Esri public Bintray Maven repository 
    maven { 
     url 'https://esri.bintray.com/arcgis' 
    } 
} 
compile fileTree(dir: 'libs', include: ['*.jar']) 
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
    exclude group: 'com.android.support', module: 'support-annotations' 
}) 
compile 'com.android.support:appcompat-v7:25.0.1' 
testCompile 'junit:junit:4.12' 

compile 'com.esri.arcgis.android:arcgis-android:10.2.5' 

}

最后我正在变空黑色屏幕

任何人都可以帮我解决这个问题吗?我想最后我发现用Openmap库

这里的答案从过去三天

+0

尝试寻找这个:http://gis.stackexchange.com/questions/48191/how-to-display-esri-shapefile-in-android –

回答

0

这个例子是关于Android的使用Openmap.jar读取形文件和显示的步骤和样品的屏幕。

1)下载的样品形状文件拉链(我已经使用印度形状文件)

2)提取zip文件并选择一个文件,该文件具有的.shp

3终止)添加.shp文件在设备存储和获取文件位置

4)指定该文件的位置OpenMap图书馆的“SHAPEFILE”级(第一级)

5)“SHAPEFILE”类转换这个数据并存储为“ESRIRecord”级(第二级)

6),最后用 “ESRIRecord” 我们得到的PolygonOptions x和y点,这分配给在谷歌地图(第三级)

关于步骤显示形状: #1,#2,#3步将改变用不同类型的文件阅读。 例如:从我们的应用程序,我们可以从服务器下载需要的zip文件,并将该文件解压缩并存储在设备位置(或) 我们可以在项目级别存储该需求zip文件,然后解压并将该文件存储在设备位置等。

 File file = new File(getfile("INDIA.shp")); 

     if (file.exists()) { 
      Toast.makeText(getApplicationContext(), "File exists", 
        Toast.LENGTH_LONG).show(); 
     } else { 
      Toast.makeText(getApplicationContext(), "File not exists @@@@@", 
        Toast.LENGTH_LONG).show(); 
      return; 
     } 

    ShapeFile shapeFile = new ShapeFile(targetFilePath);  

     for (ESRIRecord esriRecord = shapeFile.getNextRecord(); esriRecord!=null;esriRecord = shapeFile.getNextRecord()){ 
      String shapeTypeStr = ShapeUtils.getStringForType(esriRecord.getShapeType()); 
      Log.v("myapp","shape type = " + esriRecord.getRecordNumber() + "-" + shapeTypeStr);    

      if (shapeTypeStr.equals("POLYGON")) { 
       // cast type after checking the type 
       ESRIPolygonRecord polyRec = (ESRIPolygonRecord)esriRecord; 

       Log.v("myapp","number of polygon objects = " + polyRec.polygons.length); 
       for (int i=0; i<polyRec.polygons.length; i++){ 
        // read for a few layers 
        ESRIPoly.ESRIFloatPoly poly = (ESRIPoly.ESRIFloatPoly)polyRec.polygons[i]; 

        PolygonOptions polygonOptions = new PolygonOptions(); 
        polygonOptions.strokeColor(Color.argb(150,200,0,0)); 
        polygonOptions.fillColor(Color.argb(150,0,0,150)); 
        polygonOptions.strokeWidth(2.0f); 

        Log.v("myapp","Points in the polygon = " + poly.nPoints); 

        for (int j=0; j<poly.nPoints; j++){ 
         //Log.v("myapp",poly.getY(j) + "," + poly.getX(j)); 
         polygonOptions.add(new LatLng(poly.getY(j), poly.getX(j))); 
        } 
        map.addPolygon(polygonOptions); 
        Log.v("myapp","polygon added"); 
       } 

      } 
      else { 
       Log.v("myapp","error polygon not found (type = " + esriRecord.getShapeType() + ")"); 
      } 

     } 

    } catch (Exception e) { 
     e.printStackTrace(); 
     Log.v("myapp","error=" + e); 
    } 

enter image description here

相关问题