0

can anyone tell me how to display local shapefiles in Android with the WhirlyGlobe SDK?

I'm using readFromFile but I get always false. http://mousebird.github.io/WhirlyGlobe/reference/android_2_5/index.html

My Code: string is the path to the folder with the shapefiles

@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);
    //}
}

The example with GeoJSON works fine. http://mousebird.github.io/WhirlyGlobe/tutorial/android/vector-data.html

BR75
  • 633
  • 7
  • 25

1 Answers1

1

The readFromFile method you're trying to invoke is supposed to be used when reading a binary file previously written with the writeToFile method, as a way to cache data, and not for reading shapefiles, although shapefiles are binary files.

Since the GeoJSON example is working fine , and since there's no fromShapeFile method, your only alternative is to parse the shapefile and convert it to GeoJSON so that you can read it with the fromGeoJSON method.

Android lib to read or parse shapefile

LuisTavares
  • 2,146
  • 2
  • 12
  • 18
  • 1
    My mistake, there is a fromShapefile method but not in the 2.5 version. You can download aar 2.6.2 here http://mousebird.github.io/WhirlyGlobe/builds/builds.html – BR75 Mar 09 '19 at 10:52