-3

I have tried with below code for read and display shapefile from my SD card

    ShapefileFeatureTable shapefileFeatureTable = null;
    try {
        shapefileFeatureTable = new ShapefileFeatureTable(Environment.getExternalStorageDirectory().getAbsolutePath()+"/India_SHP/INDIA.shp");
        featureLayer = new FeatureLayer(shapefileFeatureTable);
        featureLayer.setRenderer(new SimpleRenderer(new SimpleMarkerSymbol(
                getResources().getColor(android.R.color.holo_blue_bright),
                28, SimpleMarkerSymbol.STYLE.CIRCLE)));

        mMapView.addLayer(featureLayer);

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

And here is the my app build.gradle file details

 dependencies {
repositories {
    jcenter()
    // Add the Esri public Bintray Maven repository
    maven {
        url 'https://esri.bintray.com/arcgis'
    }
}
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
testCompile 'junit:junit:4.12'

compile 'com.esri.arcgis.android:arcgis-android:10.2.5'

}

And finally I am getting empty black screen

Can any one help me regarding this? I am trying this example from past three days

Peddiraju G
  • 168
  • 3
  • 19

2 Answers2

1

Finally I find the answer using Openmap library

Here is the steps and sample screens regarding shape file read and display using Openmap.jar in Android.

1) Download the sample shape file zip (I have used India shape file)

2) Extract the zip file and pick one file which ends with .shp

3) Add that .shp file in device storage and get that file location

4) Assign that file location to OpenMap library's "ShapeFile" class (First level)

5) The "ShapeFile" class convert this data and store as "ESRIRecord" class (Second level)

6) And finally using "ESRIRecord" we get PolygonOptions x and y points which assigns to display shape on Google Map (Third level)

Regarding steps : #1,#2 and #3 steps will change with different types of file reading. For example : From our app we can download the desire zip file from server and unzip and store that files in device location (or) We can store that desire zip file in project level then unzip and store that files in device location etc.

      File file = new File(getfile("INDIA.shp"));

        if (file.exists()) {
            Toast.makeText(getApplicationContext(), "File exists",
                    Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(getApplicationContext(), "File not exists @@@@@",
                    Toast.LENGTH_LONG).show();
            return;
        }

  ShapeFile shapeFile = new ShapeFile(targetFilePath);      

      for (ESRIRecord esriRecord = shapeFile.getNextRecord(); esriRecord!=null;esriRecord = shapeFile.getNextRecord()){
            String shapeTypeStr = ShapeUtils.getStringForType(esriRecord.getShapeType());
            Log.v("myapp","shape type = " + esriRecord.getRecordNumber() + "-" + shapeTypeStr);               

            if (shapeTypeStr.equals("POLYGON")) {
                // cast type after checking the type
                ESRIPolygonRecord polyRec = (ESRIPolygonRecord)esriRecord;

                Log.v("myapp","number of polygon objects = " + polyRec.polygons.length);
                for (int i=0; i<polyRec.polygons.length; i++){
                    // read for a few layers
                    ESRIPoly.ESRIFloatPoly poly = (ESRIPoly.ESRIFloatPoly)polyRec.polygons[i];

                    PolygonOptions polygonOptions = new PolygonOptions();
                    polygonOptions.strokeColor(Color.argb(150,200,0,0));
                    polygonOptions.fillColor(Color.argb(150,0,0,150));
                    polygonOptions.strokeWidth(2.0f);

                    Log.v("myapp","Points in the polygon = " + poly.nPoints);

                    for (int j=0; j<poly.nPoints; j++){
                        //Log.v("myapp",poly.getY(j) + "," + poly.getX(j));
                        polygonOptions.add(new LatLng(poly.getY(j), poly.getX(j)));
                    }
                    map.addPolygon(polygonOptions);
                    Log.v("myapp","polygon added");
                }

            }
            else {
                Log.v("myapp","error polygon not found (type = " + esriRecord.getShapeType() + ")");
            }

        }

    } catch (Exception e) {
        e.printStackTrace();
        Log.v("myapp","error=" + e);
    }

enter image description here

Peddiraju G
  • 168
  • 3
  • 19
0

using ArcGIS Runtime SDK for Android you can display shapefile

https://developers.arcgis.com/android/latest/sample-code/symbolize-shapefile.htm

https://developers.arcgis.com/android/latest/java/sample-code/feature-layer-shapefile/

creativecoder
  • 1,470
  • 1
  • 14
  • 23