【问题标题】:Unable to read shape file in Android无法在 Android 中读取形状文件
【发布时间】:2015-11-24 05:00:15
【问题描述】:

我正在尝试使用 ShapefileFeatureTable() 来读取 android 中的形状文件。无论我给出什么路径,它都会显示“找不到文件”异常。

try 
{
    ShapefileFeatureTable shpFileFeatTable = new ShapefileFeatureTable("/storage/sdcard/map.shp");
} 
catch (FileNotFoundException e) 
{
    e.printStackTrace();
} 
catch(Exception e)
{
    e.printStackTrace();
}

谁能帮帮我?

注意:我正在开发 Android 模拟器。我也在使用 arcGIS 库。

【问题讨论】:

  • 尝试使用Environment.getExternalStorageDirectory()获取路径

标签: android maps arcgis


【解决方案1】:
【解决方案2】:

您的应用可能未请求从外部存储读取的权限。您需要在 AndroidManifest.xml 中添加以下内容:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

目前,ShapefileFeatureTable 是只读的,但如果将来此类获得编辑功能并且您想要进行编辑,您的应用也需要请求写入权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

更多详情请见http://developer.android.com/guide/topics/manifest/uses-permission-element.html

也有可能(但不太可能)您的文件路径不正确。如果您请求读取权限并且仍然获得FileNotFoundException,请检查new File("/path/to/file.shp").exists() 的值。如果 Android 看不到文件,ArcGIS 也看不到文件。

【讨论】:

    【解决方案3】:

    事实证明,它正在显示 shapefile。我必须将 MapView 设为空白才能看到它。

    <com.esri.android.map.MapView
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </com.esri.android.map.MapView>
    

    【讨论】:

    • 您必须空白 MapView?那是什么意思?以及如何在加载 shapefile 时修复您的 FileNotFoundException?
    【解决方案4】:

    我有同样的问题。确保与 map.shp 相关的其他文件位于同一文件夹的旁边。其他与map.shp相关的文件扩展名有:.dbf .prj .sbn .sbx .shp.xml .shx

    【讨论】:

      猜你喜欢
      • 2014-03-30
      • 2016-02-22
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-27
      • 2011-01-05
      • 2018-04-10
      相关资源
      最近更新 更多