Reputation: 667
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
Upvotes: 0
Views: 173
Reputation: 2206
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
Upvotes: 1