Exemplo n.º 1
0
 private async Task ExportFile(string download_path, string filename)
 {
     await QueuedTask.Run(async() => {
         try
         {
             Geodatabase gdb     = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@download_path)));
             string default_path = Path.GetDirectoryName(Project.Current.URI);
             await DownloadFile(default_path, filename);
             string fullPath       = Path.Combine(default_path, filename);
             string rasterFileName = Path.GetFileNameWithoutExtension(fullPath);
             string rasterName     = Regex.Replace(rasterFileName, @"[^0-9a-zA-Z_]", "_"); //string.Empty
             string outputRaster   = Path.Combine(download_path, rasterName);
             await Ag_Analytics_Module.CopyRaster(fullPath, outputRaster);
             await Ag_Analytics_Module.SetToClassifyColorizerFromLayerName(rasterName, 10, "Bathymetric Scale");
             // delete files in default path
             File.Delete(fullPath);
         }
         catch
         {
             await DownloadFile(download_path, filename);
             await Ag_Analytics_Module.AddLayerToMapAsync(Path.Combine(download_path, filename));
             await Ag_Analytics_Module.SetToClassifyColorizerFromLayerName(filename, 10, "Bathymetric Scale");
         }
     });
 }
Exemplo n.º 2
0
        private async Task ExportFile(string download_path, string filename, string shapefileUrl)
        {
            string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
            string dir_name  = filename + "_" + timestamp;

            await QueuedTask.Run(async() => {
                try
                {
                    Geodatabase gdb     = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@download_path)));
                    string default_path = Path.GetDirectoryName(Project.Current.URI);
                    string dir_path     = Path.Combine(default_path, dir_name);
                    Directory.CreateDirectory(dir_path);
                    await DownloadZipFile(dir_path, filename, shapefileUrl);
                    string featureClassName = Regex.Replace(filename, @"[^0-9a-zA-Z_]", "_") + "_" + timestamp;  //string.Empty
                    string outputUrl        = Path.Combine(download_path, featureClassName);
                    await Ag_Analytics_Module.CopyFeatures(Path.Combine(dir_path, filename + ".shp"), outputUrl);

                    if (_checkRasterizeShapefile)
                    {
                        ProgressMessage = "Rasterize...";
                        dynamic json    = await RasterizeShapefile(dir_path, filename);

                        if (json == null)
                        {
                            //ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed Rasterize Shapefile. Please try again.");
                            ResultErrorMessage += "\nFailed Rasterize Shapefile";
                            return;
                        }
                        try
                        {
                            foreach (dynamic item in json)
                            {
                                foreach (string fileUrl in item.raster)
                                {
                                    string ext = Path.GetExtension(fileUrl);
                                    string downloadFileName = filename + "_" + item.field + ext;
                                    await DownloadRasterizeFile(dir_path, downloadFileName, fileUrl);

                                    if (ext == ".tif")
                                    {
                                        string rasterFileName = filename + "_" + item.field + "_" + timestamp;
                                        string rasterName     = Regex.Replace(rasterFileName, @"[^0-9a-zA-Z_]", "_"); //string.Empty
                                        string outputRaster   = Path.Combine(download_path, rasterName);
                                        await Ag_Analytics_Module.CopyRaster(Path.Combine(dir_path, downloadFileName), outputRaster);
                                        await Ag_Analytics_Module.SetToClassifyColorizerFromLayerName(rasterName, 10, "Bathymetric Scale");
                                    }
                                    else if (ext == ".dbf")
                                    {
                                        string tableFileName = filename + "_" + item.field + "_Table_" + timestamp;
                                        string tableName     = Regex.Replace(tableFileName, @"[^0-9a-zA-Z_]", "_"); //string.Empty
                                        await Ag_Analytics_Module.CopyTable(Path.Combine(dir_path, downloadFileName), download_path, tableName);
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            //ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed Rasterize Shapefile. Please try again.");
                            ResultErrorMessage += "\nFailed Rasterize Shapefile:";
                            ResultErrorMessage += e.Message;
                            return;
                        }
                    }
                }
                catch
                {
                    string dir_path = Path.Combine(_downloadPath, dir_name);
                    Directory.CreateDirectory(dir_path);

                    await DownloadZipFile(dir_path, filename, shapefileUrl);

                    await Ag_Analytics_Module.AddLayerToMapAsync(Path.Combine(dir_path, filename + ".shp"));

                    if (_checkRasterizeShapefile)
                    {
                        ProgressMessage = "Rasterize...";

                        dynamic json = await RasterizeShapefile(dir_path, filename);

                        if (json == null)
                        {
                            //ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed Rasterize Shapefile. Please try again.");
                            ResultErrorMessage += "\nFailed Rasterize Shapefile";
                            return;
                        }
                        try
                        {
                            foreach (dynamic item in json)
                            {
                                foreach (string fileUrl in item.raster)
                                {
                                    string ext = Path.GetExtension(fileUrl);
                                    string downloadFileName = filename + "_" + item.field + ext;
                                    await DownloadRasterizeFile(dir_path, downloadFileName, fileUrl);
                                    if (ext == ".tif")
                                    {
                                        await Ag_Analytics_Module.AddLayerToMapAsync(Path.Combine(dir_path, downloadFileName));
                                        await Ag_Analytics_Module.SetToClassifyColorizerFromLayerName(downloadFileName, 10, "Bathymetric Scale");
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            //ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed Rasterize Shapefile. Please try again.");
                            ResultErrorMessage += "\nFailed Rasterize Shapefile:";
                            ResultErrorMessage += e.Message;
                            return;
                        }
                    }
                }
            });
        }