Does anyone know how to create file geodatabase using local sever?

2210
8
Jump to solution
10-18-2018 02:02 AM
saeidpahlevan
New Contributor II

I am trying to create a file geodatabase using local server but i can't find any samples for that. The only code i have seen is to add shape file to local map server

0 Kudos
1 Solution
8 Replies
saeidpahlevan
New Contributor II

I just found one way of accessing file geodatabase through the local server as follows.

private ArcGISMapImageSublayer _fileGeodatabaseSublayer;
private LocalServer _LocalServer;

public MainWindow()
{
InitializeComponent();
Initialize();
}
private async void Initialize()
{
// Create a map and add it to the view
MyMapView.Map = new Map(BasemapType.Topographic, 39.7294, -104.8319, 12);

try
{
// Start the local server instance
await LocalServer.Instance.StartAsync();
}
catch (InvalidOperationException ex)
{
MessageBox.Show(String.Format("Please ensure that local server is installed prior to using the sample. See instructions in readme.md or metadata.json. Message: {0}", ex.Message), "Local Server failed to start");
}
}
private void m_Button_Click(object sender, RoutedEventArgs e)
{
string filePath = "D:\\test\\test.gdb";
string fileName = "featureclass1";
StartLocalMapService(fileName, filePath);
}
private async void StartLocalMapService(string fileName, string filePath)
{
// any mpk file - don't know why
string mapServiceUrl = System.IO.Path.GetDirectoryName(filePath) + "\\mpk_blank.mpk";

// Create the local map service
var localMapService = new LocalMapService(mapServiceUrl);
FileGeodatabaseWorkspace ws = new FileGeodatabaseWorkspace("file_wkspc", filePath);
TableSublayerSource source = new TableSublayerSource(ws.Id, fileName);
_fileGeodatabaseSublayer = new ArcGISMapImageSublayer(0, source);
localMapService.SetDynamicWorkspaces(new List<DynamicWorkspace>()
{
ws
});
localMapService.StatusChanged += localMapService_StatusChanged;
await localMapService.StartAsync();
}
private async void localMapService_StatusChanged(object sender, StatusChangedEventArgs e)
{
if (e.Status == LocalServerStatus.Started)
{
if (!(sender is LocalMapService localService))
{
return;
}
ArcGISMapImageLayer imageryLayer = new ArcGISMapImageLayer(localService.Url);
imageryLayer.LoadStatusChanged += (q, ex) =>
{
// Add the layer to the map once loaded
if (ex.Status == Esri.ArcGISRuntime.LoadStatus.Loaded)
{
// Create a default symbol style
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 3);
// Apply the symbol style with a renderer
_fileGeodatabaseSublayer.Renderer = new SimpleRenderer(lineSymbol);
imageryLayer.Sublayers.Add(_fileGeodatabaseSublayer);
}
};
await imageryLayer.LoadAsync();
MyMapView.Map.OperationalLayers.Clear();
// Add the image layer to the map
MyMapView.Map.OperationalLayers.Add(imageryLayer);
}
}

0 Kudos
Shanmugapriya55
New Contributor III

Hi,

Is this working?

When I am trying this code, It shows no error.

But I am not able to see the features in the map.

It would be the great pleasure if you can help me with this.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

To create a File Geodatabase use the geoprocessing tool `Create File GDB` in the Data Management toolbox under the Workspace toolset (in either help doc below refer to the standalone python script example).

Pro: Create File Geodatabase—Data Management toolbox | ArcGIS Desktop 

ArcMap: Create File GDB—Help | ArcGIS Desktop 

http://pro.arcgis.com/en/pro-app/tool-reference/data-management/create-file-gdb.htm

You can use that tool either within a Model or a script. Once you have created a geoprocessing tool and run that successfully within Pro or ArcMap, then share the result and ensure you enable ArcGIS Runtime Support:

Pro: Package Result—Data Management toolbox | ArcGIS Desktop 

ArcMap: Sharing a geoprocessing package—ArcMap | ArcGIS Desktop 

To run via the API see Run a geoprocessing task—ArcGIS Runtime SDK for .NET | ArcGIS for Developers  

Cheers

Mike

saeidpahlevan
New Contributor II

Thanks Mike that's very helpful. My next question is if file geodatabase is created using the steps you mentioned then is it possible to add a georeferenced tiff file to the currently created file geodatabase using only the Runtime local server API or does it still need geoprocessing tool ?

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Adding a raster dataset in .tiff format to the new file geodatabase can be done via the geoprocessing tool Raster To Geodatabase—Conversion toolbox | ArcGIS Desktop (same workflow as above to create a geoprocessing package that you would run as a local geoprocessing service to add one or more raster datasets to a file geodatabase). Note you can also use ArcPy.

Depending on your workflow, it's also worth noting that the ArcGIS Runtime API provides a mechanism to directly create raster mosaics on disk (in a mobile geodatabase) and add raster datasets to the mosaic dataset:

MosaicDatasetRaster Constructor or MosaicDatasetRaster.Create Method (String, String, SpatialReference) 

MosaicDatasetRaster.AddRastersAsync Method 

You can also use ArcPy within scripts in geoprocessing packages with local geoprocessing services. ArcPy has functionality for creating, manipulating, and saving datasets.

Cheers

Mike

saeidpahlevan
New Contributor II

now assuming .gpk with the appropriate script tool has been created and shared with ArcGis Runtime, how to pass parameters to .gkp? are there any samples on running the geoprocessing package and passing the parameters through ArcGis Runtime local server?

0 Kudos
saeidpahlevan
New Contributor II

Thanks Mike, I managed to create the file geodatabase using runtime api local server and the geoprocessing package. I appreciate your help and time

0 Kudos