示例#1
0
 private static GdalRasterLocationItem FindLocation(GdalConfigurationDocument conf, string directory)
 {
     foreach (var loc in conf.RasterLocations)
     {
         if (loc.Location == directory)
         {
             return(loc);
         }
     }
     return(null);
 }
        public void GdalDocument_Remove()
        {
            var doc = new GdalConfigurationDocument();
            var loc = new GdalRasterLocationItem {
                Location = "C:\\temp\\location_1"
            };

            Assert.False(doc.RemoveLocation(loc));
            doc.AddLocation(loc);
            var loc2 = new GdalRasterLocationItem {
                Location = "C:\\temp\\location_1"
            };

            Assert.True(doc.RemoveLocation(loc2));
        }
        public void GdalDocument_CalculateExtents()
        {
            var doc = new GdalConfigurationDocument();

            Assert.Null(doc.CalculateExtent());
            var loc = new GdalRasterLocationItem {
                Location = "C:\\temp\\location_1"
            };

            loc.AddItem(new GdalRasterItem {
                FileName = "1_1.tif", MinX = 1, MinY = 1, MaxX = 2, MaxY = 2
            });
            doc.AddLocation(loc);
            var ext = doc.CalculateExtent();

            Assert.Equal(1, ext.MinX);
            Assert.Equal(1, ext.MinY);
            Assert.Equal(2, ext.MaxX);
            Assert.Equal(2, ext.MaxY);
            var loc2 = new GdalRasterLocationItem {
                Location = "C:\\temp\\location_2"
            };

            loc2.AddItem(new GdalRasterItem {
                FileName = "2_1.tif", MinX = -1, MinY = -1, MaxX = 2, MaxY = 2
            });
            doc.AddLocation(loc2);
            ext = doc.CalculateExtent();
            Assert.Equal(-1, ext.MinX);
            Assert.Equal(-1, ext.MinY);
            Assert.Equal(2, ext.MaxX);
            Assert.Equal(2, ext.MaxY);
            loc2.AddItem(new GdalRasterItem {
                FileName = "1_2.tif", MinX = 2, MinY = 1, MaxX = 3, MaxY = 3
            });
            ext = doc.CalculateExtent();
            Assert.Equal(-1, ext.MinX);
            Assert.Equal(-1, ext.MinY);
            Assert.Equal(3, ext.MaxX);
            Assert.Equal(3, ext.MaxY);
        }
        public void GdalDocument_AddLocationDeDupes()
        {
            var doc = new GdalConfigurationDocument();
            var loc = new GdalRasterLocationItem {
                Location = "C:\\temp\\location_1"
            };

            doc.AddLocation(loc);
            Assert.Single(doc.RasterLocations);
            var loc2 = new GdalRasterLocationItem {
                Location = "C:\\temp\\location_1"
            };

            doc.AddLocation(loc2);
            Assert.Single(doc.RasterLocations);
            var loc3 = new GdalRasterLocationItem {
                Location = "C:\\temp\\location_2"
            };

            doc.AddLocation(loc3);
            Assert.Equal(2, doc.RasterLocations.Length);
        }
示例#5
0
        internal void InitDefaults()
        {
            string xml = _fs.GetConfigurationContent(_service.CurrentConnection);

            if (!string.IsNullOrEmpty(xml))
            {
                try
                {
                    _conf = (GdalConfigurationDocument)ConfigurationDocument.LoadXml(xml);
                }
                catch
                {
                    BuildDefaultDocument();
                }

                lstView.Items.Clear();
                List <string> files = new List <string>();
                foreach (var loc in _conf.RasterLocations)
                {
                    AddRasterItems(loc.Location, loc.Items);
                }
            }
        }
示例#6
0
        private 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("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 = conn.FeatureService.GetSpatialContextInfo(fs.ResourceID, 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);
        }
示例#7
0
                                            "<xs:appinfo source=\"http://fdo.osgeo.org/schemas\"><fdo:DefaultDataModel dataModelType=\"Bitonal\" dataType=\"Unknown\" organization=\"Pixel\" bitsPerPixel=\"1\" tileSizeX=\"256\" tileSizeY=\"256\"/></xs:appinfo></xs:annotation></xs:element></xs:sequence></xs:extension></xs:complexContent></xs:complexType></xs:schema><SchemaMapping xmlns=\"http://fdogrfp.osgeo.org/schemas\" provider=\"OSGeo.Gdal.3.2\" name=\"default\"></SchemaMapping></fdo:DataStore>";                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        //NOXLATE

        private void BuildDefaultDocument()
        {
            _conf = (GdalConfigurationDocument)ConfigurationDocument.LoadXml(string.Format(TEMPLATE_CFG, -10000000, -10000000, 10000000, 10000000));
        }