0

I'm using ArcGIS Android SDK for first time. I have worked on a sample project and am able to get a World map using this..

map = (MapView) findViewById(R.id.map);
map.addLayer(new ArcGISDynamicMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"));

But my problem is:
I have some *.shp (shapefile) files and I would like to show them on mapview.

How can i do that?

  • to run without RuntimeException we should have three type of files in a single directory 1 .dbf 2 .shp 3.shx – user86298 Nov 14 '16 at 12:20
2

You cannot add data from a shapefile directly to the MapView. You can only add various types of Layers to the Map View. See this Page for more details: Map layer types

You could however create a Map Tile Package from a mapservice and use it instead if you desire offline access, by using it in a Local Tile Layer

| improve this answer | |
1
  1. Download the shapefile to the device.
  2. Make sure that your app has permission to read files from your storage:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> (having permission to write implicitly grants you this permission)

Then, do something like:

    try {
        ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(shapeFilePath);
    } catch (FileNotFoundException ex) {
        Toast.makeText(this, R.string.shapefile_not_found, Toast.LENGTH_LONG).show();
        ex.printStackTrace();
        return;
    }

and to add it to the map:

    FeatureLayer featureLayer = new FeatureLayer(shapefileFeatureTable);
    featureLayer.setRenderer(new SimpleRenderer(new SimpleFillSymbol(
            getResources().getColor(android.R.color.holo_blue_bright),
            SimpleFillSymbol.STYLE.SOLID)));
    map.addLayer(featureLayer);

This should show the feature with a thin black border.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.