Ejemplo n.º 1
0
        private async Task ClipLayersAsync(bool clipSwe, bool clipPrism, bool clipSnotel, bool clipSnowCos,
                                           bool clipRoads, bool clipPublicLands, bool clipVegetation, bool clipLandcover)
        {
            try
            {
                if (String.IsNullOrEmpty(Module1.Current.Aoi.Name))
                {
                    MessageBox.Show("No AOI selected for analysis !!", "BAGIS-PRO");
                    return;
                }

                if (clipSwe == false && clipPrism == false &&
                    clipSnotel == false && clipSnowCos == false && clipRoads == false &&
                    clipPublicLands == false && clipVegetation == false && clipLandcover == false)
                {
                    MessageBox.Show("No layers selected to clip !!", "BAGIS-PRO");
                    return;
                }

                var cmdShowHistory = FrameworkApplication.GetPlugInWrapper("esri_geoprocessing_showToolHistory") as ICommand;
                if (cmdShowHistory != null)
                {
                    if (cmdShowHistory.CanExecute(null))
                    {
                        cmdShowHistory.Execute(null);
                    }
                }

                var           layersPane = (DockpaneLayersViewModel)FrameworkApplication.DockPaneManager.Find("bagis_pro_DockpaneLayers");
                BA_ReturnCode success    = BA_ReturnCode.Success;

                // Check for PRISM units
                string strPrismPath = GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Prism, true)
                                      + PrismFile.Annual.ToString();
                string pBufferDistance = "";
                string pBufferUnits    = "";
                string strBagisTag     = await GeneralTools.GetBagisTagAsync(strPrismPath, Constants.META_TAG_XPATH);

                if (!string.IsNullOrEmpty(strBagisTag))
                {
                    pBufferDistance = GeneralTools.GetValueForKey(strBagisTag, Constants.META_TAG_BUFFER_DISTANCE, ';');
                    pBufferUnits    = GeneralTools.GetValueForKey(strBagisTag, Constants.META_TAG_XUNIT_VALUE, ';');
                }
                // Apply default buffer if left null
                if (string.IsNullOrEmpty(PrismBufferDistance))
                {
                    PrismBufferDistance = (string)Module1.Current.BatchToolSettings.PrecipBufferDistance;
                    PrismBufferUnits    = (string)Module1.Current.BatchToolSettings.PrecipBufferUnits;
                }

                if (clipPrism)
                {
                    success = await AnalysisTools.ClipLayersAsync(Module1.Current.Aoi.FilePath, Constants.DATA_TYPE_PRECIPITATION,
                                                                  pBufferDistance, pBufferUnits, PrismBufferDistance, PrismBufferUnits);

                    if (success == BA_ReturnCode.Success)
                    {
                        success = await AnalysisTools.UpdateSitesPropertiesAsync(Module1.Current.Aoi.FilePath, SiteProperties.Precipitation);
                    }
                    if (success == BA_ReturnCode.Success)
                    {
                        layersPane.ReclipPrism_Checked = false;
                        layersPane.Prism_Checked       = true;
                    }
                }
                if (clipSwe)
                {
                    success = await AnalysisTools.ClipSweLayersAsync(pBufferDistance, pBufferUnits,
                                                                     SWEBufferDistance, SWEBufferUnits);

                    if (success == BA_ReturnCode.Success)
                    {
                        layersPane.ReclipSwe_Checked = false;
                        layersPane.SWE_Checked       = true;
                    }
                }

                if (clipSnotel || clipSnowCos)
                {
                    string snotelBufferDistance  = "";
                    string snowCosBufferDistance = "";
                    double dblDistance           = -1;
                    bool   isDouble = Double.TryParse(SnotelBufferDistance, out dblDistance);
                    if (clipSnotel && isDouble && dblDistance > 0)
                    {
                        snotelBufferDistance = SnotelBufferDistance + " " + SnotelBufferUnits;
                    }
                    isDouble = Double.TryParse(SnowCosBufferDistance, out dblDistance);
                    if (clipSnowCos && isDouble && dblDistance > 0)
                    {
                        snowCosBufferDistance = SnowCosBufferDistance + " " + SnowCosBufferUnits;
                    }

                    success = await AnalysisTools.ClipSnoLayersAsync(Module1.Current.Aoi.FilePath, clipSnotel, snotelBufferDistance,
                                                                     clipSnowCos, snowCosBufferDistance);

                    if (success == BA_ReturnCode.Success)
                    {
                        if (clipSnotel)
                        {
                            layersPane.ReclipSNOTEL_Checked = false;
                            layersPane.SNOTEL_Checked       = true;
                        }
                        if (clipSnowCos)
                        {
                            layersPane.ReclipSnowCos_Checked = false;
                            layersPane.SnowCos_Checked       = true;
                        }
                    }
                }

                if (clipRoads)
                {
                    string strOutputFc = GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Layers, true)
                                         + Constants.FILE_ROADS;
                    success = await AnalysisTools.ClipFeatureLayerAsync(Module1.Current.Aoi.FilePath, strOutputFc, Constants.DATA_TYPE_ROADS,
                                                                        RoadsBufferDistance, RoadsBufferUnits);

                    if (success == BA_ReturnCode.Success)
                    {
                        layersPane.ReclipRoads_Checked = false;
                        layersPane.Roads_Checked       = true;
                    }
                    else
                    {
                        MessageBox.Show("An error occurred while clipping the roads. Check the log file!!", "BAGIS-PRO");
                    }
                }

                if (clipPublicLands)
                {
                    string strOutputFc = GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Layers, true)
                                         + Constants.FILE_PUBLIC_LAND;
                    success = await AnalysisTools.ClipFeatureLayerAsync(Module1.Current.Aoi.FilePath, strOutputFc, Constants.DATA_TYPE_PUBLIC_LAND,
                                                                        PublicLandsBufferDistance, PublicLandsBufferUnits);

                    if (success == BA_ReturnCode.Success)
                    {
                        layersPane.ReclipPublicLands_Checked = false;
                        layersPane.PublicLands_Checked       = true;
                    }
                    else
                    {
                        MessageBox.Show("An error occurred while clipping the public lands. Check the log file!!", "BAGIS-PRO");
                    }
                }

                if (clipVegetation)
                {
                    string strOutputRaster = GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Layers, true)
                                             + Constants.FILE_VEGETATION_EVT;
                    success = await AnalysisTools.ClipRasterLayerAsync(Module1.Current.Aoi.FilePath, strOutputRaster, Constants.DATA_TYPE_VEGETATION,
                                                                       VegetationBufferDistance, VegetationBufferUnits);

                    if (success == BA_ReturnCode.Success)
                    {
                        layersPane.ReclipVegetation_Checked = false;
                        layersPane.Vegetation_Checked       = true;
                    }
                    else
                    {
                        MessageBox.Show("An error occurred while clipping the vegetation layer. Check the log file!!", "BAGIS-PRO");
                    }
                }

                if (clipLandcover)
                {
                    success = await AnalysisTools.ClipLandCoverAsync(Module1.Current.Aoi.FilePath, LandCoverBufferDistance, LandCoverBufferUnits);

                    if (success == BA_ReturnCode.Success)
                    {
                        layersPane.ReclipLandCover_Checked = false;
                        layersPane.LandCover_Checked       = true;
                    }
                    else
                    {
                        MessageBox.Show("An error occurred while clipping the land cover layer. Check the log file!!", "BAGIS-PRO");
                    }
                }

                if (success == BA_ReturnCode.Success)
                {
                    MessageBox.Show("Analysis layers clipped!!", "BAGIS-PRO");
                }
                else
                {
                    MessageBox.Show("An error occurred while trying to clip the layers !!", "BAGIS-PRO");
                }
            }
            catch (Exception ex)
            {
                Module1.Current.ModuleLogManager.LogError(nameof(ClipLayersAsync),
                                                          "Exception: " + ex.Message);
            }
        }