How to use MosaicDatasetRaster Class Locally

1820
9
03-25-2019 09:32 PM
MohamadFathin
New Contributor II

Hi,

I need to convert multiple raster tile map to mosaic dataset by using MosaicDatasetRaster Class. I look at the documentation it need to create on data base. Is there a way for me to create the mosaic dataset locally on the fly?

0 Kudos
9 Replies
PreetiMaske
Esri Contributor

Hi,

 

Did you look at the guide topic that provides an example of how to use the MosaicDatasetRaster class: Add raster data—ArcGIS Runtime SDK for .NET | ArcGIS for Developers 

- Preeti

0 Kudos
MohamadFathin
New Contributor II

Hi,

I already look at the link you mention before, the example shows that i create the mosaicdataset by using geodatabase. My current issues is how can create the mosaicdataset by retrieving the raster data from my local directory folder?

0 Kudos
PreetiMaske
Esri Contributor

There is a section in that guide topic shows how you can add rasters from a local folder.But currently the way ArcGIS SDK Runtime works is that local raster files need to be added to a sqlite geodatabase. 

Section is titled: "Create a new mobile mosaic dataset and add raster files to it".

We would be interested in understanding your use case as to why do you prefer/need to load rasters from a local folder directly to create MosaicRasterDataset instead of loading into a Sqlite geodatabase. What are the limitations you are facing by having them load into a database ? how does it affect your workflow?

0 Kudos
MohamadFathin
New Contributor II

Hi Preeti Maske‌,

Thank you for a reply. I am not quiet familiar with the sqlite and other data base. I though i can just convert it using SDK on the fly just by the mosaicdataset class access my raster file on local computer directory. My project requirement is to use the raster map locally without access to server or internet.

1. If I install the sqlite then follow the example from the Section is titled: "Create a new mobile mosaic dataset and add raster files to it", how can I retrieve the mosaic dataset from the sqlite?

2. I am planning to purchase the runtime .net sdk , is there diferent in performance in using the desktop and sdk product in term of convert the raster to mosaic dataset and display it and rendered?

Regards,

0 Kudos
PreetiMaske
Esri Contributor

You, won't have to install anything for Rasters to load to a sqlite gdb for a MosaicRasterDataset. Hopefully code below will help. First code is a button click code that will create mosaic raster dataset and second will add the created mosaicraster to map. 

private async void Create_MosaicClick(object sender, RoutedEventArgs e)

{

try

{

RasterLayer layer;                
string destinationSQLiteGDB = "C:\temp\MosaicLocation\GdbWithRasters.geodatabase";// This will be qlite gdb which will get created and will hold all your rasters.                string rasterType = "*.tif"; \\change to format of rasters in your folder.                string filterType = ".tif$";                string localFolderPath = "C:\FolderWithRasters";// path to folder containing raster files
SpatialReference sr= new SpatialRefernce(wkid); // specify the spatialrefernce of your mosaic raster dataset    

if (!System.IO.File.Exists(destinationSQLiteGDB))

{ MosaicDatasetRaster raster = MosaicDatasetRaster.Create(destinationSQLiteGDB, "myMosaicRasterds", sr);

await raster.AddRastersAsync(new AddRastersParameters() { InputDirectory = localFolderPath, Filter = filterType });

}

}

catch (System.Exception ex)

{

MessageBox.Show(ex.Message, "Error");

return;

}

}



//TO ADD MOSAIC DATASET CREATED ABOVE TO MAP YOU WILL DO SOMETHING LIKE THIS
private void AddToMap_Click(object sender, RoutedEventArgs e)
{
try
{
var mdsRaster = new MosaicDatasetRaster(destinationSQLiteGDB, "myMosaicRasterds");
layer = new RasterLayer(mdsRaster);
layer.LoadStatusChanged += Layer_LoadStatusChanged;
mapView.Map = new Esri.ArcGISRuntime.Mapping.Map(new Basemap(layer));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
0 Kudos
MohamadFathin
New Contributor II

Hi Preeti Maske

Thank you for your reply. It really work, I able to create the local data base and view all the map. But there is something i need clarification regarding this both product that is ArcGIS dekstop and ArcGIS SDK.

1. I barely able to try the ArcGIS dekstop, using data management tools it able to compile all the raster map into one bigger map.Did I able to make the mosaic dataset raster just like in ArcGIS Desktop data management tools using ArcGIS SDK?

2. If i can't do it just like in Dekstop product, how can i speed up the map loading on my screen?

 MyMapView.Map = new Map(new SpatialReference(4326));

 // Open the shapefile
 ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(path);

 // Create a feature layer to display the shapefile
 FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile);

 // Add the feature layer to the map
 MyMapView.Map.OperationalLayers.Add(newFeatureLayer);

 await myShapefile.LoadAsync();


 await MyMapView.SetViewpointAsync(new Viewpoint(5.838198, 100.417164, 383267));

 await MyMapView.Map.LoadAsync();
 //Get mosaic dataset names in the SQLite database.
 var names = MosaicDatasetRaster.GetNames(destinationSQLiteGDB);
 var rasterName = names[0];

 //Create a raster from a mosaic dataset
 MosaicDatasetRaster raster = new MosaicDatasetRaster(destinationSQLiteGDB, "RasterMosaic.tif");


 // Create a RasterLayer to display the Raster
 RasterLayer rasterLayer = new RasterLayer(raster);

 MyMapView.Map.OperationalLayers.Add(rasterLayer);

 await rasterLayer.LoadAsync();


 await MyMapView.SetViewpointAsync(new Viewpoint(4.359075,102.077903, 383267));

 await MyMapView.Map.LoadAsync();

Regards, 

Fathin

0 Kudos
PreetiMaske
Esri Contributor

Creating and loading Mosaic Raster data is possible through ArcGIS Runtime SDK as we saw in code that I sent earlier. But if the data is too big you need to evaluate your need and chose the best practice. Essentially it depends on the needs of the application. One would dynamically create inside the app using SDK if data changes are very frequent, size is small.

If that is not the case then I recommend creating them pre-hand.

You have multiple options if you want the map to load 

- Create raster dataset in Desktop and open using SDK. Too big of data will take time to load and render.

- Create Mosaic using GeoPackage Data Management tools and use Runtime SDK to open raster from geopackage.

- You can also publish them as ImageServices using an ArcGIS Server.

- If data is changing frequently and is smaller in size it mosaic raster can be created in the app also.

0 Kudos
MohamadFathin
New Contributor II

Hi Preeti Maske

Hi may i know is there a limit of mosaicdatasetraster .sqlite file that i can create using the sdk if i still not buy it yet? I try to create a new sqlite file but it does not retrieve my raster map from the local directory that contain raster map. May i know why after it create the sqlite file it will close the application? 

private async void createMosaic_Click(object sender, RoutedEventArgs e)
{
try

{


// This will be qlite gdb which will get created and will hold all your rasters. string rasterType = "*.tif"; \\change to format of rasters in your folder. string filterType = ".tif$"; string localFolderPath = "C:\FolderWithRasters";// path to folder containing raster files
// specify the spatialrefernce of your mosaic raster dataset
// Create a new mobile mosaic dataset.
MosaicDatasetRaster rasterMosaic = MosaicDatasetRaster.Create(destinationSQLiteGDB, "Raster.tif", SpatialReferences.Wgs84);

// When the new mosaic dataset is ready, add some raster files.
rasterMosaic.LoadStatusChanged += (s, q) =>
{
// If loaded successfully, start adding rasters
if (q.Status == Esri.ArcGISRuntime.LoadStatus.Loaded)
{
AddRastersParameters parameters = new AddRastersParameters
{
InputDirectory = rasterPath,
Filter = "*.tif"
};
rasterMosaic.AddRastersAsync(parameters);
}
};

await rasterMosaic.LoadAsync();

//if (!System.IO.File.Exists(destinationSQLiteGDB))
//{
// rasterMosaic = MosaicDatasetRaster.Create(destinationSQLiteGDB, "myMosaicRasterds", sr);

// await rasterMosaic.AddRastersAsync(new AddRastersParameters() { InputDirectory = @"C:\Users\User\Desktop\User Stuff\New folder", Filter = "*.tif" });

}

catch (System.Exception ex)
{

MessageBox.Show(ex.Message, "Error");

return;

}
}

0 Kudos
PreetiMaske
Esri Contributor

It may be difficult to answer this accurately because it depends on so many factors like size of data, hardware used.

As to why you application crashed , you will have to provide you test code with data or you may also contact support for help.

Cheers,

Preeti

0 Kudos