How can the Runtime .net programmatically make edits in local data, from .shp or .gdb?

4953
7
09-04-2014 06:15 AM
ThomasHansen
New Contributor

Hi

How do I make programmatic edits, like this one, in a local .shp og .gdb file?

Do I need to import it into .geodatabase first? If so, how?

private async void searchLocalGDB(string Path1, string Path2)

{

            // Open the geodatabases

            var gdbRead = await Esri.ArcGISRuntime.Data.Geodatabase.OpenAsync(Path1);

            var gdbWrite = await Esri.ArcGISRuntime.Data.Geodatabase.OpenAsync(Path2);

            // Get the first tables in the DB's

            var gdbWriteTable = gdbWrite.FeatureTables.FirstOrDefault();

            var gdbReadTable = gdbRead.FeatureTables.FirstOrDefault();

            // Set up filter, returning the first 7 rows

            var filter = new Esri.ArcGISRuntime.Data.QueryFilter();

            filter.MaximumRows = 7;

            filter.WhereClause = "1=1";

            // Query the Read table, and add to the write table

            var Q1 = await gdbReadTable.QueryAsync(filter);

            foreach (Esri.ArcGISRuntime.Data.GeodatabaseFeature F in Q1)

            {

                    await gdbWriteTable.AddAsync(F);

            }

}

0 Kudos
7 Replies
FreddieGibson
Regular Contributor II

The short answer is that Runtime currently doesn't support editing local data (i.e. shapefiles and file geodatabase data) directly. You could get the data into Runtime, but without using the synchronization workflow via a Feature Service you wouldn't be able to easily persist your changes back to the parent feature.

If you did want to edit local data without a sync-enabled service you'd have to use workflows where you load the data into runtime, manipulate the data, and then create new copies of it to persist the changes. These changes could not be returned to the original feature class. This approach could be accomplished using one of the following technologies.

  1. Runtime Content
    With this workflow you could copy your data into a sqlite geodatabase (*.geodatabase). This file could be directly edited in runtime and you can save changes to it. Once you complete you edits you'd need to convert this file back to a file geodatabase.

    https://developers.arcgis.com/net/sample-code/SyncGeodatabase/ NOTE: Ignore the portions of the sample that display how to sync the changes. You'll want to focus on the portion that shows how to edit the sqlite geodatabase.

  2. Shapefiles
    Shapefiles can be loaded into Runtime .NET, but after the data is loaded you cannot save the changes back to the original shapefile. To persist the changes you'd need to leverage geoprocessing within the runtime application to copy the layer back to a feature class.

    Feature Layer from Shapefile Sample
    https://developers.arcgis.com/net/sample-code/FeatureLayerFromShapefile/

    https://community.esri.com/thread/122651 NOTE: I included a sample on this geonet thread showing how to load a shapefile into runtime, manipulate it, and then export it back to a shapefile.

  3. Map Packages
    Map packages can be loaded into Runtime .NET, but changes will not be persisted in the Map Package. Instead when you load the Map Package it will be extracted on your machine. Once you finish editing, you'll need to locate the folder where the package was extracted and retrieve the files in this location. NOTE: I have a sample that display show to edit map packages if you need to review this workflow.
MarcoPorcari
New Contributor II

Hi Freddie ,   it is interesting what you say in particular "NOTE: I have a sample that display show to edit map packages if you need to review this workflow." .

Mpk file is actually an archive 7zip , can you suggest a sample for edit map packages ?

Thanks you

0 Kudos
AndreaLeone1
New Contributor

Hi,

i need to write an application for edit feature from a .mpk map package.
How i can locate the local folder where the mpk will be extracted?
And how i can save the changes to the original mpk?
Maybe your example it could be of help.

Thank you in advance

0 Kudos
FreddieGibson
Regular Contributor II

I'll look through my sample to see if I can find this specific sample. For the most part you wouldn't be able to manipulate the original map package, but you could overwrite it with the updated data where the package was extracted. You would accomplish this by locating where the package is extracted and zipping these updated files to persist the edits. Someone could retrieve the data from the zip file if need, but if they wanted to see the changes reflected in a map package I would need to overwrite the original map package by uploading the zipped folder to a geoprocessing service that could un-zip it, call the package map tool to create a new map package, and then download this to the clients machine. Do you think this workflow is something that'd work for you?

0 Kudos
AndreaLeone1
New Contributor

Yes it could work.


I didn't find a geoprocessing to re-create the mpk, the only geoprocessing is the "Package Map" but when i try to share for use it in a local server, it says me that "Tool Package Map is not licensed for use inArcGIG Runtime package" (and i have a full enteprise license, with sdk and engine (edn)). Another problem is that when the Arcgis runtime for .net extracts the mpk in the temporary folder it adds a random guid at the end of the folder name.

All these problems make me think to discard arcgisruntime for .net in favor of arcobject/engine solution, but with arcobject/engine i will work with an older developing environment (winform and com components) that limits the graphics capabilities of a .net application. Another way  could be to work with arcgispro sdk but the application will became an add-in of arcgis pro and the sdk is in beta release.

So i think the sceneario/workflow you have describe in a real example could be helpfull.

Thank you in advance

0 Kudos
FreddieGibson
Regular Contributor II

The package map tool isn't supported for offline use in Runtime. You would only be able to utilize it in a connected environment from runtime. Could you describe the workflow you're needing to accomplish in more detail?

0 Kudos
AndreaLeone1
New Contributor

Yes of course,

the application must be able to:

1) map editing (editing a layer created from a shapefile ),

2) create, store and mantain a local geodatabase file,

3) mosaic raster data (tiff),

4) store features, raster image (tiff) and mosaic dataset in a local geodatabase,

5) analysis ndvi,

all these requirements must be made in a off-line scenario.

0 Kudos