Select to view content in your preferred language

edit a ".geodatabase" dataset

3824
2
03-18-2015 02:58 AM
HaniDraidi
Frequent Contributor

I am writing an app that edits local data stored on my android device, the application aims to save my location that is derived from the location services as point in a .geodatabase layer.

The application includes basemap, and a points-dataset (“points.geodatabase” that should store the saved locations).

I’ve referred to Esri tutorial for editing data (this link), but I didn’t understand  this guide.

At this level, the application can view my current position on the map as a point (in the screenshot below); I want to save this location as a new point feature in “points.geodatabase” dataset by pressing a button. How can I do this?

Any help is highly appreciated

Hani

Clip_988.jpg

0 Kudos
2 Replies
omega_cancer
Frequent Contributor

Please be more specific, share the code and let people know what is the point where you are stuck. Somebody might be able to help you out then.

This is the code copied form the link:

//make a map of attributes

Map<String, Object> attributes = new HashMap<String, Object>();

attributes.put("TYPDAMAGE", "Minor");

attributes.put("PRIMCAUSE" , "Earthquake");

attributes.put("TYPDAMAGE_INT", new Integer(3)); 

try

{

//Create a feature with these attributes at the given point GeodatabaseFeature gdbFeature = new GeodatabaseFeature(attributes, point, geodatabaseFeatureTable); 

//Add the feature into the geodatabase table returning the new feature ID long fid = geodatabaseFeatureTable.addFeature(gdbFeature); 

String geomStr = geodatabaseFeatureTable.getFeature(fid).getGeometry().toString();

Log.d(TAG, "added fid = " + fid + " " + geomStr);

}

catch (TableException e)

{

// report errors, e.g. to console

Log.e(TAG, "", e);

}

You need to write this code when geoDB is initialized:

map.setOnStatusChangedListener(new OnStatusChangedListener()

{

private static final long serialVersionUID = 1L;

@Override

public void onStatusChanged(Object source, STATUS status)

{

if(source == map && STATUS.INITIALIZED == status)

{

//Your code goes here

}

}

});

0 Kudos
HaniDraidi
Frequent Contributor

Many Thanks for the prompt reply Abdul Razzaq , and sorry for the late reply

I tried your suggestion, but still it does not work with me

Lets make it simpler; assume that I have a points runtime content (points.geodatabase), I want to add a point which has these coordinates: x=150000, y= 160000

I used the code below, but it did not work:

/*Define the Geodatabase*/

            Geodatabase geodatabase;

            try {

                 

                 

                 

                  geodatabase = new Geodatabase ("storage/extSdCard/a/a.geodatabase");

                  /*Define Geodatabase Feature Table*/

                  gft=geodatabase.getGeodatabaseFeatureTableByLayerId(0);

                 

                  /*Create a Layer*/

                FeatureLayer fl=new FeatureLayer(gft);

                 

                /*Display the layer on the map*/

                mMapView.addLayer(fl);

               

               

                  } catch (FileNotFoundException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

                 

                 

            }

//make a map of attributes

             Map<String, Object> attributes = new HashMap<String, Object>();

             attributes.put("Name_English", "AlRam");

            

             /*point=(Point) locgraphic.getGeometry();*/

             point=new Point(150000, 160000);

             try {

               //Create a feature with these attributes at the given point

               GeodatabaseFeature gdbFeature = new GeodatabaseFeature(attributes, point, gft);

               //Add the feature into the geodatabase table returning the new feature ID

               gft.addFeature(gdbFeature);

           

              

              

             } catch (TableException e) {

               // report errors, e.g. to console

              

             }

0 Kudos