【问题标题】:Display ShapeFiles with WhirlyGlobe使用 WhirlyGlobe 显示 ShapeFiles
【发布时间】:2019-02-26 10:21:19
【问题描述】:

谁能告诉我如何使用 WhirlyGlobe SDK 在 Android 中显示本地 shapefile?

我正在使用 readFromFile 但我总是错误的。 http://mousebird.github.io/WhirlyGlobe/reference/android_2_5/index.html

我的代码:字符串是带有 shapefile 的文件夹的路径

@Override
protected void onPostExecute(String string) {

    VectorInfo vectorInfo = new VectorInfo();
    vectorInfo.setColor(Color.RED);
    vectorInfo.setLineWidth(4.f);

    VectorObject object = new VectorObject();

    File fileShape = new File(string + "/poly.shp");

    String shapefile = "";
    if (fileShape .exists()){
        shapefile = fileShape.getAbsolutePath();
    }



    if(object.readFromFile(shapefile)){
        controller.addVector(object,vectorInfo,MaplyBaseController.ThreadMode.ThreadAny);
    }

    //if (object1.fromGeoJSON(shapefile)) {
    //   controller.addVector(object, vectorInfo, MaplyBaseController.ThreadMode.ThreadAny);
    //}
}

GeoJSON 的示例运行良好。 http://mousebird.github.io/WhirlyGlobe/tutorial/android/vector-data.html

【问题讨论】:

    标签: java android gis shapefile


    【解决方案1】:

    您尝试调用的 readFromFile 方法应该在读取以前使用 writeToFile 方法写入的二进制文件时使用,作为缓存数据的一种方式,而不是用于读取 shapefile,尽管 shapefile 是二进制的文件。

    由于 GeoJSON 示例运行良好,并且由于没有 fromShapeFile 方法,您唯一的选择是解析 shapefile 并将其转换为 GeoJSON,以便您可以使用 fromGeoJSON 方法读取它。

    Android lib to read or parse shapefile

    【讨论】:

    猜你喜欢
    • 2014-11-16
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 2011-12-06
    • 1970-01-01
    • 2011-03-02
    • 2020-12-26
    • 1970-01-01
    相关资源
    最近更新 更多