示例#1
0
        protected async override void OnClick()
        {
            try
            {
                // Query for the drainage area
                Uri    gdbUri      = new Uri(GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Aoi, true));
                string strAreaSqKm = await GeodatabaseTools.QueryTableForSingleValueAsync(gdbUri, Constants.FILE_SNOTEL_POURPOINT,
                                                                                          Constants.FIELD_AOI_AREA, new QueryFilter());

                double areaSqKm = -1;
                bool   isDouble = Double.TryParse(strAreaSqKm, out areaSqKm);

                //Query min/max from dem
                IList <double> lstResult = await GeoprocessingTools.GetDemStatsAsync(Module1.Current.Aoi.FilePath, 0.005);

                double elevMinMeters = -1;
                double elevMaxMeters = -1;
                if (lstResult.Count == 2)   // We expect the min and max values in that order
                {
                    elevMinMeters = lstResult[0];
                    elevMaxMeters = lstResult[1];
                }

                //Test querying metadata; Layer metadata methods not currently available in Pro
                //string snowCourseSitesPath = GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Layers, true) +  Constants.FILE_SNOW_COURSE;
                //Item featureClassItem = ItemFactory.Instance.Create(snowCourseSitesPath);
                //IMetadata fcMetadataItem = featureClassItem as IMetadata;

                // Counting Snotel Sites in AOI boundary
                gdbUri = new Uri(GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Aoi, false));
                Uri sitesGdbUri   = new Uri(GeodatabaseTools.GetGeodatabasePath(Module1.Current.Aoi.FilePath, GeodatabaseNames.Layers, false));
                int snotelInBasin = await GeodatabaseTools.CountPointsWithinInFeatureAsync(sitesGdbUri, Constants.FILE_SNOTEL,
                                                                                           gdbUri, Constants.FILE_AOI_VECTOR);

                int snotelInBuffer = 0;
                int totalSites     = await GeodatabaseTools.CountFeaturesAsync(sitesGdbUri, Constants.FILE_SNOTEL);

                if (totalSites > 0)
                {
                    snotelInBuffer = totalSites - snotelInBasin;
                }

                // Counting Snow Course Sites in AOI boundary
                int scosInBasin = await GeodatabaseTools.CountPointsWithinInFeatureAsync(sitesGdbUri, Constants.FILE_SNOW_COURSE,
                                                                                         gdbUri, Constants.FILE_AOI_VECTOR);

                int scosInBuffer = 0;
                totalSites = await GeodatabaseTools.CountFeaturesAsync(sitesGdbUri, Constants.FILE_SNOW_COURSE);

                if (totalSites > 0)
                {
                    scosInBuffer = totalSites - scosInBasin;
                }


                // Serialize the title page object
                BA_Objects.ExportTitlePage tPage = new BA_Objects.ExportTitlePage
                {
                    aoi_name                 = Module1.Current.Aoi.Name,
                    comments                 = "This is a test",
                    publisher                = "Lesley Bross",
                    local_path               = Module1.Current.Aoi.FilePath,
                    streamgage_station       = "USGS XXXXXXX",
                    drainage_area_sqkm       = areaSqKm,
                    elevation_min_meters     = elevMinMeters,
                    elevation_max_meters     = elevMaxMeters,
                    snotel_sites_in_basin    = snotelInBasin,
                    snotel_sites_in_buffer   = snotelInBuffer,
                    snotel_sites_buffer_size = "???",
                    scos_sites_in_basin      = scosInBasin,
                    scos_sites_in_buffer     = scosInBuffer,
                    scos_sites_buffer_size   = "???",
                    date_created             = DateTime.Now
                };
                string publishFolder = Module1.Current.Aoi.FilePath + "\\" + Constants.FOLDER_MAP_PACKAGE;
                string myXmlFile     = publishFolder + "\\" + Constants.FILE_TITLE_PAGE_XML;
                System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(tPage.GetType());
                using (System.IO.FileStream fs = System.IO.File.Create(myXmlFile))
                {
                    writer.Serialize(fs, tPage);
                }

                // Process the title page through the xsl template
                string               myStyleSheet = GeneralTools.GetAddInDirectory() + "\\" + Constants.FILE_TITLE_PAGE_XSL;
                XPathDocument        myXPathDoc   = new XPathDocument(myXmlFile);
                XslCompiledTransform myXslTrans   = new XslCompiledTransform();
                myXslTrans.Load(myStyleSheet);
                XmlTextWriter myWriter = new XmlTextWriter(publishFolder + @"\result.html", null);
                myXslTrans.Transform(myXPathDoc, null, myWriter);
                MessageBox.Show("Title page created!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("An error occurred while trying to parse the XML!! " + e.Message, "BAGIS PRO");
            }
        }