Hi,
I want to be able to add features to a runtime content dataset (.geodatabase) with the following scenario: I have a points-dataset (points.geodatabase) stored on my android device, I built an app that views these points, and I want to edit this dataset from my android device by adding a new point feature (with 150,000 x-coordinate and 160000 y-coordinate) to it. I tried the standard guide in this link and wrote the code below but still, the dataset is not edited and the new point is not added.
My question is: How can I add features to a .geodatabase dataset from my android device?
Any help is highly appreciated
Hani
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//make a map of attributes
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("Name_English", "PointA");
/*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 (gft) gft.addFeature(gdbFeature);
s.addGraphic(new Graphic(point, new SimpleMarkerSymbol(Color.RED,15,SimpleMarkerSymbol.STYLE.CIRCLE)));
} catch (TableException e) {
// report errors, e.g. to console
}
Toast.makeText(getApplicationContext(), "Saved!", 3000).show();
}
});
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//make a map of attributes
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("Name_English", "PointA");
/*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 (gft) gft.addFeature(gdbFeature);
s.addGraphic(new Graphic(point, new SimpleMarkerSymbol(Color.RED,15,SimpleMarkerSymbol.STYLE.CIRCLE)));
} catch (TableException e) {
// report errors, e.g. to console
}
Toast.makeText(getApplicationContext(), "Saved!", 3000).show();
}
});
Solved! Go to Solution.
Are you using Geodatabase created as replica from online service? If you are using geodatabase created with ARcmap as runtime content it will not work at all - the database is readonly.
With a cursory look it seems like the code should work. Have you debugged and caught the table exception if there is one? It could be that the point is outside of the GDB extent. When you created the offline .geodatabase an extent was needed.
Instead of creating the point from a static x-y coordinate I would use a map tap event to get the x-y like so
public boolean onSingleTap(final MotionEvent e) { mMapView.toMapPoint(new Point(e.getX(), e.getY())) }
Hope that helps.
Thank you for the suggestion Forrest,
Seems that the issue is not with the extent, it is related to the read-only nature of the .geodatabase shared as a runtime content from ArcMap.
It looks like you're setting two onclicklisteners on the same button. Is this intended?
Sorry Paul,
The code has been duplicated when I copied it to this post, but in the app it is written one time.
Sorry for inconvenience,
Are you using Geodatabase created as replica from online service? If you are using geodatabase created with ARcmap as runtime content it will not work at all - the database is readonly.
Many Thanks for the valuable input Tero,
That’s right, I am using a .geodatabase created from ArcMap as runtime content, and when I explored the exporting options, I found that the resultant .geodatabase is for read-only purposes (in the screenshot below).
BTW, do you have any idea of how to make it editable?
When you use ArcMap to create Runtime Content, the geodatabase will always be READ-ONLY. For editable geodatabases, use the "Services Pattern" to get the geodatabase. You can read more about this here: Create an offline map—ArcGIS Runtime SDK for Android | ArcGIS for Developers
I hope this helps!
Thank you for the helpful resources Eric