Exemple #1
0
 /// <summary>
 /// Adds the specified raster image reference
 /// </summary>
 /// <param name="item"></param>
 public void AddItem(GdalRasterItem item)
 {
     if (!_items.ContainsKey(item.FileName))
     {
         _items.Add(item.FileName, item);
     }
     else
     {
         _items[item.FileName] = item;
     }
 }
Exemple #2
0
        /// <summary>
        /// Set the current element's content from the current XML node
        /// </summary>
        /// <param name="node"></param>
        /// <param name="mgr"></param>
        public void ReadXml(System.Xml.XmlNode node, System.Xml.XmlNamespaceManager mgr)
        {
            if (node.Name != "Location")                                                                 //NOXLATE
            {
                throw new Exception(string.Format(Strings.ErrorBadDocumentExpectedElement, "Location")); //NOXLATE
            }
            var loc = node.Attributes["name"];                                                           //NOXLATE

            this.Location = loc.Value;

            foreach (System.Xml.XmlNode item in node.ChildNodes)
            {
                var raster = new GdalRasterItem();
                raster.ReadXml(item, mgr);

                AddItem(raster);
            }
        }
Exemple #3
0
        object UpdateConfigurationDocument(BackgroundWorker worker, DoWorkEventArgs e, params object[] args)
        {
            GdalConfigurationDocument conf = (GdalConfigurationDocument)args[0];

            IServerConnection conn = (IServerConnection)args[1];
            string [] toAdd = args[2] as string[];
            string [] toRemove = args[3] as string[];
            bool isAlias = (bool)args[4];

            worker.ReportProgress(0, Strings.UpdatingConfiguration);

            int total = toAdd.Length + toRemove.Length;
            int unit = (total / 100);
            int progress = 0;

            var result = new UpdateConfigResult() { Added = new List<string>(), Removed = new List<string>() };

            //Remove first
            foreach (var remove in toRemove)
            {
                string dir = null;
                if (isAlias)
                {
                    dir = remove.Substring(0, remove.LastIndexOf("\\")); //NOXLATE
                }
                else
                {
                    dir = Path.GetDirectoryName(remove);
                }

                var loc = FindLocation(conf, dir);
                if (null != loc)
                {
                    string f = isAlias ? remove.Substring(remove.LastIndexOf("\\") + 1) : Path.GetFileName(remove); //NOXLATE
                    loc.RemoveItem(f);
                    result.Removed.Add(remove);
                    if (loc.Items.Length == 0)
                        conf.RemoveLocation(loc);
                }
                progress += unit;
                worker.ReportProgress(progress, string.Format(Strings.ProcessedItem, remove));
            }

            //Then add
            foreach (var add in toAdd)
            {
                string dir = null;
                if (isAlias)
                {
                    int idx = add.LastIndexOf("/"); //NOXLATE
                    if (idx >= 0)
                        dir = add.Substring(0, idx);
                    else
                        dir = add.Substring(0, add.LastIndexOf("%") + 1); //NOXLATE
                }
                else
                {
                    dir = Path.GetDirectoryName(add);
                }
                var loc = conf.AddLocation(dir);

                //Create a temp feature source to attempt interrogation of extents
                var values = new NameValueCollection();
                values["DefaultRasterFileLocation"] = add; //NOXLATE
                var fs = ObjectFactory.CreateFeatureSource(conn, "OSGeo.Gdal", values); //NOXLATE

                var resId = new ResourceIdentifier("Session:" + conn.SessionID + "//" + Guid.NewGuid() + ".FeatureSource"); //NOXLATE
                fs.ResourceID = resId.ToString();
                conn.ResourceService.SaveResource(fs);

                var scList = fs.GetSpatialInfo(false);

                var raster = new GdalRasterItem();

                if (isAlias)
                {
                    int idx = add.LastIndexOf("/"); //NOXLATE
                    if (idx >= 0)
                        raster.FileName = add.Substring(add.LastIndexOf("/") + 1); //NOXLATE
                    else
                        raster.FileName = add.Substring(add.LastIndexOf("%") + 1); //NOXLATE
                }
                else
                {
                    raster.FileName = Path.GetFileName(add);
                }

                if (scList.SpatialContext.Count > 0)
                {
                    raster.MinX = Convert.ToDouble(scList.SpatialContext[0].Extent.LowerLeftCoordinate.X, CultureInfo.InvariantCulture);
                    raster.MinY = Convert.ToDouble(scList.SpatialContext[0].Extent.LowerLeftCoordinate.Y, CultureInfo.InvariantCulture);
                    raster.MaxX = Convert.ToDouble(scList.SpatialContext[0].Extent.UpperRightCoordinate.X, CultureInfo.InvariantCulture);
                    raster.MaxY = Convert.ToDouble(scList.SpatialContext[0].Extent.UpperRightCoordinate.Y, CultureInfo.InvariantCulture);
                }
                else
                {
                    raster.MinX = -10000000;
                    raster.MinY = -10000000;
                    raster.MaxX = 10000000;
                    raster.MaxY = 10000000;
                }

                loc.AddItem(raster);

                result.Added.Add(Path.Combine(dir, raster.FileName));

                progress += unit;
                worker.ReportProgress(progress, string.Format(Strings.ProcessedItem, add));
            }

            //Re-calculate combined extent for spatial context
            var env = conf.CalculateExtent();
            if (env != null)
                conf.SpatialContexts[0].Extent = env;

            return result;
        }
Exemple #4
0
 private void AddRasterItems(string dir, GdalRasterItem[] items)
 {
     foreach (var item in items)
     {
         AddRasterItem(dir, item);
     }
 }
Exemple #5
0
        private void AddRasterItem(string dir, GdalRasterItem item)
        {
            foreach (ListViewItem li in lstView.Items)
            {
                //A list view item of the same file name exist. Abort.
                if (((GdalRasterItem)li.Tag).FileName == item.FileName)
                    return;
            }

            ListViewItem lvi = new ListViewItem();
            lvi.Name = Path.Combine(dir, item.FileName);
            lvi.Text = lvi.Name;
            lvi.Tag = item;
            lvi.ImageIndex = 0;

            lstView.Items.Add(lvi);
        }
Exemple #6
0
 /// <summary>
 /// Removes the specified raster image reference
 /// </summary>
 /// <param name="item"></param>
 public void RemoveItem(GdalRasterItem item) => _items.Remove(item.FileName);
Exemple #7
0
 /// <summary>
 /// Removes the specified raster image reference
 /// </summary>
 /// <param name="item"></param>
 public void RemoveItem(GdalRasterItem item)
 {
     _items.Remove(item.FileName);
 }
Exemple #8
0
        /// <summary>
        /// Set the current element's content from the current XML node
        /// </summary>
        /// <param name="node"></param>
        /// <param name="mgr"></param>
        public void ReadXml(System.Xml.XmlNode node, System.Xml.XmlNamespaceManager mgr)
        {
            if (node.Name != "Location") //NOXLATE
                throw new Exception(string.Format(Strings.ErrorBadDocumentExpectedElement, "Location")); //NOXLATE

            var loc = node.Attributes["name"]; //NOXLATE
            this.Location = loc.Value;

            foreach (System.Xml.XmlNode item in node.ChildNodes)
            {
                var raster = new GdalRasterItem();
                raster.ReadXml(item, mgr);

                AddItem(raster);
            }
        }
Exemple #9
0
 /// <summary>
 /// Adds the specified raster image reference
 /// </summary>
 /// <param name="item"></param>
 public void AddItem(GdalRasterItem item)
 {
     if (!_items.ContainsKey(item.FileName))
         _items.Add(item.FileName, item);
     else
         _items[item.FileName] = item;
 }