public WmsAdvancedConfigurationDialog(IEditorService service)
        {
            InitializeComponent();
            grdSpatialContexts.AutoGenerateColumns = false;
            _service = service;
            _fs = (IFeatureSource)_service.GetEditedResource();
            txtFeatureServer.Text = _fs.GetConnectionProperty("FeatureServer"); //NOXLATE
            string xml = _fs.GetConfigurationContent();
            if (!string.IsNullOrEmpty(xml))
            {
                try
                {
                    _config = (WmsConfigurationDocument)ConfigurationDocument.LoadXml(xml);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format(Strings.ErrorLoadingWmsConfig, ex.Message), Strings.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MakeDefaultDocument();
                }
            }
            else
            {
                MakeDefaultDocument();
            }

            lstFeatureClasses.DataSource = _config.RasterOverrides;
            grdSpatialContexts.DataSource = _config.SpatialContexts;
        }
Esempio n. 2
0
        public RasterDefinitionCtrl(WmsConfigurationDocument config, RasterWmsItem item, IEditorService edsvc)
        {
            InitializeComponent();
            cmbBackground.ResetColors();
            _config = config;

            _fs = (IFeatureSource)edsvc.GetEditedResource();
            _item = item;
            _edsvc = edsvc;

            txtImageFormat.Text = item.ImageFormat;
            chkTransparent.Checked = item.IsTransparent;
            cmbBackground.CurrentColor = item.BackgroundColor;
            txtElevation.Text = item.ElevationDimension;
            txtEpsg.Text = item.SpatialContextName;
            txtTime.Text = item.Time;

            txtImageFormat.TextChanged += (s, e) => { item.ImageFormat = txtImageFormat.Text; };
            chkTransparent.CheckedChanged += (s, e) => { item.IsTransparent = chkTransparent.Checked; };
            cmbBackground.SelectedIndexChanged += (s, e) => { item.BackgroundColor = cmbBackground.CurrentColor; };
            txtElevation.TextChanged += (s, e) => { item.ElevationDimension = txtElevation.Text; };
            txtEpsg.TextChanged += (s, e) => { item.SpatialContextName = txtEpsg.Text; };
            txtTime.TextChanged += (s, e) => { item.Time = txtTime.Text; };

            List<string> names = new List<string>();
            foreach (var layer in item.Layers)
            {
                names.Add(layer.Name);
            }
            txtLayers.Lines = names.ToArray();
            lnkUpdate.Enabled = false;
        }
Esempio n. 3
0
        private static ConfigurationDocument LoadInternal(XmlDocument doc)
        {
            var mgr = new XmlNamespaceManager(doc.NameTable);

            mgr.AddNamespace("xs", XmlNamespaces.XS);       //NOXLATE
            mgr.AddNamespace("xsi", XmlNamespaces.XSI);     //NOXLATE
            mgr.AddNamespace("fdo", XmlNamespaces.FDO);     //NOXLATE
            mgr.AddNamespace("gml", XmlNamespaces.GML);     //NOXLATE
            mgr.AddNamespace("xlink", XmlNamespaces.XLINK); //NOXLATE
            mgr.AddNamespace("fds", XmlNamespaces.FDS);     //NOXLATE

            ConfigurationDocument conf = null;
            var root = doc.DocumentElement;

            if (root == null || root.Name != "fdo:DataStore") //NOXLATE
            {
                return(null);
            }

            //Sample the first schema mapping node. Even if there are multiples
            //they will all be the same provider

            //NOTE: Why does the XPath query (commented out) fail?

            var map = root.LastChild;                       //root.SelectSingleNode("SchemaMapping");

            if (map != null && map.Name == "SchemaMapping") //NOXLATE
            {
                var prov = map.Attributes["provider"];      //NOXLATE
                if (prov != null)
                {
                    if (prov.Value.StartsWith("OSGeo.ODBC")) //NOXLATE
                    {
                        conf = new OdbcConfigurationDocument();
                    }
                    else if (prov.Value.StartsWith("OSGeo.Gdal")) //NOXLATE
                    {
                        conf = new GdalConfigurationDocument();
                    }
                    else if (prov.Value.StartsWith("OSGeo.WMS")) //NOXLATE
                    {
                        conf = new WmsConfigurationDocument();
                    }
                    else
                    {
                        conf = new GenericConfigurationDocument();
                    }
                }
            }

            if (conf != null)
            {
                conf.ReadXml(doc.SelectSingleNode("fdo:DataStore", mgr), mgr); //NOXLATE
                return(conf);
            }

            return(null);
        }
        private void MakeDefaultDocument()
        {
            try
            {
                _config = (WmsConfigurationDocument)_service.FeatureService.GetSchemaMapping("OSGeo.WMS", _fs.ConnectionString); //NOXLATE
                //BOGUS: This was not as sufficient as I originally thought, nevertheless this contains
                //information that would not exist if we constructed the document the old fashioned way.
                string defaultScName = string.Empty;
                if (_config.SpatialContexts.Length > 0)
                {
                    defaultScName = _config.SpatialContexts[0].Name;
                }
                else
                {
                    var list = _fs.GetSpatialInfo(false);
                    if (list.SpatialContext.Count > 0)
                    {
                        defaultScName = list.SpatialContext[0].Name;
                    }
                    else //Really? What kind of WMS service are you????
                    {
                        var sc = new FdoSpatialContextListSpatialContext()
                        {
                            Name = "EPSG:4326", //NOXLATE
                            Description = "Maestro-generated spatial context", //NOXLATE
                            CoordinateSystemName = "EPSG:4326", //NOXLATE
                            CoordinateSystemWkt = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]", //NOXLATE
                            Extent = new FdoSpatialContextListSpatialContextExtent()
                            {
                                LowerLeftCoordinate = new FdoSpatialContextListSpatialContextExtentLowerLeftCoordinate()
                                {
                                    X = "-180.0", //NOXLATE
                                    Y = "-90.0" //NOXLATE
                                },
                                UpperRightCoordinate = new FdoSpatialContextListSpatialContextExtentUpperRightCoordinate()
                                {
                                    X = "180.0", //NOXLATE
                                    Y = "90.0" //NOXLATE
                                }
                            },
                            ExtentType = FdoSpatialContextListSpatialContextExtentType.Static,
                            IsActive = true,
                            XYTolerance = 0.0001,
                            ZTolerance = 0.0001,
                        };
                        _config.AddSpatialContext(sc);
                        defaultScName = sc.Name;
                    }
                }

                EnsureRasterProperties(defaultScName);
                _config.EnsureConsistency();
            }
            catch
            {
                _config = BuildDefaultWmsDocument();
            }
        }
        private WmsConfigurationDocument BuildDefaultWmsDocument()
        {
            var doc = new WmsConfigurationDocument();
            var contexts = _fs.GetSpatialInfo(false);
            var schemaName = _fs.GetSchemaNames()[0];
            var clsNames = _fs.GetClassNames(schemaName);
            var schema = new FeatureSchema(schemaName, string.Empty);
            doc.AddSchema(schema);

            foreach (var sc in contexts.SpatialContext)
            {
                doc.AddSpatialContext(sc);
            }

            var defaultSc = contexts.SpatialContext[0];

            foreach (var clsName in clsNames)
            {
                var className = clsName.Split(':')[1]; //NOXLATE
                var cls = new ClassDefinition(className, string.Empty);
                cls.AddProperty(new DataPropertyDefinition("Id", string.Empty) //NOXLATE
                {
                    DataType = DataPropertyType.String,
                    Length = 256,
                    IsNullable = false
                }, true);
                cls.AddProperty(new RasterPropertyDefinition("Image", string.Empty) //NOXLATE
                {
                    DefaultImageXSize = 1024,
                    DefaultImageYSize = 1024,
                    SpatialContextAssociation = defaultSc.Name
                });

                schema.AddClass(cls);

                var item = CreateDefaultItem(schema.Name, cls.Name, "Image", defaultSc); //NOXLATE
                doc.AddRasterItem(item);
            }

            return doc;
        }
Esempio n. 6
0
        public void TestWmsSaveLoad()
        {
            var conf = new WmsConfigurationDocument();

            var schema = new FeatureSchema("WMS", "WMS Test Schema");
            var cls = new ClassDefinition("NASAWMSGlobalPan", "WMS Test Class");
            cls.AddProperty(new DataPropertyDefinition("Id", "ID Property")
            {
                DataType = DataPropertyType.String,
                Length = 256,
                IsNullable = false
            }, true);
            cls.AddProperty(new RasterPropertyDefinition("Image", "Raster Property")
            {
                DefaultImageXSize = 800,
                DefaultImageYSize = 800
            });

            schema.AddClass(cls);
            conf.AddSchema(schema);

            var item = new RasterWmsItem(schema.Name, cls.Name, "Image");
            item.ImageFormat = RasterWmsItem.WmsImageFormat.PNG;
            item.IsTransparent = true;
            item.BackgroundColor = ColorTranslator.FromHtml("#FFFFFF");
            item.Time = "current";
            item.ElevationDimension = "0";
            item.SpatialContextName = "EPSG:4326";

            for (int i = 0; i < 5; i++)
            {
                item.AddLayer(new WmsLayerDefinition("Layer" + i));
            }

            conf.AddRasterItem(item);

            string path = "WmsConfigTest.xml";
            File.WriteAllText(path, conf.ToXml());

            conf = null;
            string xml = File.ReadAllText(path);
            conf = ConfigurationDocument.LoadXml(xml) as WmsConfigurationDocument;
            Assert.NotNull(conf);

            Assert.AreEqual(1, conf.RasterOverrides.Length);

            var ritem = conf.RasterOverrides[0];
            cls = conf.GetClass("WMS", "NASAWMSGlobalPan");

            Assert.NotNull(cls);
            Assert.NotNull(cls.Parent);
            Assert.AreEqual("WMS", cls.Parent.Name);
            Assert.AreEqual("WMS Test Schema", cls.Parent.Description);
            Assert.AreEqual("NASAWMSGlobalPan", cls.Name);
            Assert.AreEqual("WMS Test Class", cls.Description);
            var prop = cls.FindProperty("Id");
            Assert.NotNull(prop);
            Assert.AreEqual("Id", prop.Name);
            Assert.AreEqual("ID Property", prop.Description);
            prop = cls.FindProperty("Image");
            Assert.NotNull(prop);
            Assert.AreEqual("Image", prop.Name);
            Assert.AreEqual("Raster Property", prop.Description);

            Assert.AreEqual(item.ImageFormat, ritem.ImageFormat);
            Assert.AreEqual(item.IsTransparent, ritem.IsTransparent);
            Assert.AreEqual(item.BackgroundColor, ritem.BackgroundColor);
            Assert.AreEqual(item.Time, ritem.Time);
            Assert.AreEqual(item.ElevationDimension, ritem.ElevationDimension);
            Assert.AreEqual(item.SpatialContextName, ritem.SpatialContextName);

            Assert.AreEqual(5, item.Layers.Length);
        }