Beispiel #1
0
        internal void AddRedlineLayer(RedlineLayer layer, string fdoProvider)
        {
            var fsId = GetRegistryFeatureSource();
            MgFeatureCommandCollection commands   = new MgFeatureCommandCollection();
            MgPropertyCollection       insertVals = new MgPropertyCollection();

            MgStringProperty regId     = new MgStringProperty("ResourceId", layer.FeatureSource);
            MgStringProperty ldfId     = new MgStringProperty("LayerDefinition", layer.LayerDefinition);
            MgStringProperty name      = new MgStringProperty("Name", layer.Name);
            MgStringProperty provider  = new MgStringProperty("FdoProvider", fdoProvider);
            MgInt32Property  geomTypes = new MgInt32Property("GeometryTypes", layer.GeometryTypes);
            MgInt32Property  styleType = new MgInt32Property("StyleType", (int)layer.StyleType);

            insertVals.Add(regId);
            insertVals.Add(ldfId);
            insertVals.Add(name);
            insertVals.Add(provider);
            insertVals.Add(geomTypes);
            insertVals.Add(styleType);

            MgInsertFeatures insert = new MgInsertFeatures("Default:MarkupRegistry", insertVals);

            commands.Add(insert);

            MgPropertyCollection result       = _featSvc.UpdateFeatures(fsId, commands, false);
            MgFeatureProperty    insertResult = result.GetItem(0) as MgFeatureProperty;

            if (insertResult != null)
            {
                MgFeatureReader fr = insertResult.GetValue();
                fr.Close();
            }
        }
Beispiel #2
0
        internal void DeleteLayer(RedlineLayer layer)
        {
            var regId = GetRegistryFeatureSource();
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
            MgDeleteFeatures           delete   = new MgDeleteFeatures("Default:MarkupRegistry", "ResourceId = '" + layer.FeatureSource + "'");

            commands.Add(delete);

            MgPropertyCollection results      = _featSvc.UpdateFeatures(regId, commands, false);
            MgInt32Property      deleteResult = results.GetItem(0) as MgInt32Property;

            if (deleteResult != null && deleteResult.GetValue() > 0)
            {
                var ldfId = new MgResourceIdentifier(layer.LayerDefinition);
                var fsId  = new MgResourceIdentifier(layer.FeatureSource);

                if (_resSvc.ResourceExists(ldfId))
                {
                    _resSvc.DeleteResource(ldfId);
                }

                if (_resSvc.ResourceExists(fsId))
                {
                    _resSvc.DeleteResource(fsId);
                }
            }
        }
Beispiel #3
0
        public void RemoveLayerFromMap(RedlineLayer layer)
        {
            var layers = _map.GetLayers();
            var lidx   = layers.IndexOf("_" + layer.Name);

            if (lidx >= 0)
            {
                layers.RemoveAt(lidx);
            }
        }
Beispiel #4
0
        public RedlineEditor(IMapViewer viewer, RedlineLayer layer)
        {
            _viewer = viewer;
            _layer  = layer;
            var provider = viewer.GetProvider();

            _featSvc  = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService);
            _wktRW    = new MgWktReaderWriter();
            _agfRW    = new MgAgfReaderWriter();
            _geomFact = new MgGeometryFactory();
        }
Beispiel #5
0
 public RedlineEditingCtrl(IMapViewer viewer, RedlineLayer layer)
     : this()
 {
     _viewer = viewer;
     _layer  = layer;
     _viewer.PropertyChanged += OnViewerPropertyChanged;
     _ed                      = new RedlineEditor(_viewer, _layer);
     this.Disposed           += OnDisposed;
     lblRedlineLayerName.Text = _layer.Name;
     _origToolbarColor        = btnRefresh.BackColor;
 }
Beispiel #6
0
        internal void UpdateLayerStyle(RedlineLayer layer, RedlineStyle updatedStyle)
        {
            //HACK: SQLite leaky abstraction (hard-coded schema name), SHP probably has some leaks of its own, so we can't assume MarkupSchema:Markup
            //as the class name interrogate our schema to figure it out
            MgResourceIdentifier fsId = new MgResourceIdentifier(layer.FeatureSource);

            MgFeatureSchemaCollection   schemas = _featSvc.DescribeSchema(fsId, string.Empty, null);
            MgFeatureSchema             schema  = schemas.GetItem(0);
            MgClassDefinitionCollection classes = schema.GetClasses();
            MgClassDefinition           cls     = classes.GetItem(0);
            string className = schema.Name + ":" + cls.Name;

            MgResourceIdentifier ldfId = new MgResourceIdentifier(layer.LayerDefinition);

            string layerDefContent = CreateRedlineLayerDefinitionContent(fsId, className, updatedStyle, layer.StyleType);

            byte[]       bytes      = Encoding.UTF8.GetBytes(layerDefContent);
            MgByteSource byteSource = new MgByteSource(bytes, bytes.Length);
            MgByteReader byteReader = byteSource.GetReader();

            _resSvc.SetResource(ldfId, byteReader, null);
        }
Beispiel #7
0
 public void DeleteLayer(RedlineLayer layer)
 {
     _registry.DeleteLayer(layer);
 }
Beispiel #8
0
        public RedlineStyle GetLayerStyle(RedlineLayer layer)
        {
            var style = RedlineStyle.CreateDefault();

            var ldfId = new MgResourceIdentifier(layer.LayerDefinition);
            var br    = _resSvc.GetResourceContent(ldfId);
            var doc   = new XmlDocument();

            doc.LoadXml(br.ToString());

            if (layer.StyleType == RedlineStylizationType.Basic)
            {
                var vsr = doc.GetElementsByTagName("VectorScaleRange")[0];
                var pts = vsr["PointTypeStyle"];
                var ats = vsr["AreaTypeStyle"];
                var lts = vsr["LineTypeStyle"];

                if (pts != null)
                {
                    var label = (XmlElement)pts.GetElementsByTagName("Label")[0];
                    var psym  = pts.GetElementsByTagName("PointSymbolization2D");
                    if (psym.Count > 0)
                    {
                        var mark = psym[0]["Mark"];

                        style.MarkerSizeUnits = ParseEnumValue <SizeUnit>(GetNodeValue(mark, "Unit"));
                        style.MarkerSize      = Convert.ToDouble(GetNodeValue(mark, "SizeX"));
                        style.MarkerType      = ParseEnumValue <MarkerType>(GetNodeValue(mark, "Shape"));
                        style.MarkerColor     = Util.FromHtmlColor(GetNodeValue(mark, "ForegroundColor"), false);
                    }
                    style.LabelSizeUnits = ParseEnumValue <SizeUnit>(GetNodeValue(label, "Unit"));
                    style.LabelFontSize  = Convert.ToDouble(GetNodeValue(label, "SizeX"));
                    style.LabelForeColor = Util.FromHtmlColor(GetNodeValue(label, "ForegroundColor"), false);
                    style.LabelBackColor = Util.FromHtmlColor(GetNodeValue(label, "BackgroundColor"), false);
                    style.LabelBackStyle = ParseEnumValue <LabelStyle>(GetNodeValue(label, "BackgroundStyle"));
                    style.LabelBold      = Convert.ToBoolean(GetNodeValue(label, "Bold"));
                    style.LabelItalic    = Convert.ToBoolean(GetNodeValue(label, "Italic"));
                    style.LabelUnderline = Convert.ToBoolean(GetNodeValue(label, "Underlined"));
                }
                if (lts != null)
                {
                    var label = (XmlElement)lts.GetElementsByTagName("Label")[0];

                    style.LabelSizeUnits = ParseEnumValue <SizeUnit>(GetNodeValue(label, "Unit"));
                    style.LabelFontSize  = Convert.ToDouble(GetNodeValue(label, "SizeX"));
                    style.LabelForeColor = Util.FromHtmlColor(GetNodeValue(label, "ForegroundColor"), false);
                    style.LabelBackColor = Util.FromHtmlColor(GetNodeValue(label, "BackgroundColor"), false);
                    style.LabelBackStyle = ParseEnumValue <LabelStyle>(GetNodeValue(label, "BackgroundStyle"));

                    if (pts == null)
                    {
                        style.LabelBold      = Convert.ToBoolean(GetNodeValue(label, "Bold"));
                        style.LabelItalic    = Convert.ToBoolean(GetNodeValue(label, "Italic"));
                        style.LabelUnderline = Convert.ToBoolean(GetNodeValue(label, "Underlined"));
                    }

                    var lsym = lts.GetElementsByTagName("LineSymbolization2D");
                    if (lsym.Count > 0)
                    {
                        var line = (XmlElement)lsym[0];
                        style.LinePattern   = ParseEnumValue <LinePattern>(GetNodeValue(line, "LineStyle"));
                        style.LineThickness = Convert.ToDouble(GetNodeValue(line, "Thickness"));
                        style.LineColor     = Util.FromHtmlColor(GetNodeValue(line, "Color"), false);
                        style.LineSizeUnits = ParseEnumValue <SizeUnit>(GetNodeValue(line, "Unit"));
                    }
                }
                if (ats != null)
                {
                    var label = (XmlElement)ats.GetElementsByTagName("Label")[0];

                    style.LabelSizeUnits = ParseEnumValue <SizeUnit>(GetNodeValue(label, "Unit"));
                    style.LabelFontSize  = Convert.ToDouble(GetNodeValue(label, "SizeX"));
                    style.LabelForeColor = Util.FromHtmlColor(GetNodeValue(label, "ForegroundColor"), false);
                    style.LabelBackColor = Util.FromHtmlColor(GetNodeValue(label, "BackgroundColor"), false);
                    style.LabelBackStyle = ParseEnumValue <LabelStyle>(GetNodeValue(label, "BackgroundStyle"));

                    if (pts == null && lts == null)
                    {
                        style.LabelBold      = Convert.ToBoolean(GetNodeValue(label, "Bold"));
                        style.LabelItalic    = Convert.ToBoolean(GetNodeValue(label, "Italic"));
                        style.LabelUnderline = Convert.ToBoolean(GetNodeValue(label, "Underlined"));
                    }

                    var asym = ats.GetElementsByTagName("AreaSymbolization2D");
                    if (asym.Count > 0)
                    {
                        var fill   = asym[0]["Fill"];
                        var stroke = asym[0]["Stroke"];

                        style.FillPattern   = ParseEnumValue <FillPattern>(GetNodeValue(fill, "FillPattern"));
                        style.FillForeColor = Util.FromHtmlColor(GetNodeValue(fill, "ForegroundColor"), false);
                        style.FillBackColor = Util.FromHtmlColor(GetNodeValue(fill, "BackgroundColor"), false);

                        style.BorderPattern   = ParseEnumValue <LinePattern>(GetNodeValue(stroke, "LineStyle"));
                        style.BorderThickness = Convert.ToDouble(GetNodeValue(stroke, "Thickness"));
                        style.BorderColor     = Util.FromHtmlColor(GetNodeValue(stroke, "Color"));
                        style.BorderSizeUnits = ParseEnumValue <SizeUnit>(GetNodeValue(stroke, "Unit"));
                    }
                }
            }
            else
            {
                var extData = doc.GetElementsByTagName("ExtendedData1");
                if (extData.Count == 1)
                {
                    var ext = (XmlElement)extData[0];
                    style.MarkerColor          = Util.FromHtmlColor(GetNodeValue(ext, "MG_MARKER_COLOR"));
                    style.MarkerType           = ParseEnumValue <MarkerType>(GetNodeValue(ext, "MG_MARKER_TYPE"));
                    style.MarkerSizeUnits      = ParseEnumValue <SizeUnit>(GetNodeValue(ext, "MG_MARKER_UNITS"));
                    style.MarkerSize           = Convert.ToDouble(GetNodeValue(ext, "MG_MARKER_SIZE"));
                    style.LineColor            = Util.FromHtmlColor(GetNodeValue(ext, "MG_LINE_COLOR"));
                    style.LinePattern          = ParseEnumValue <LinePattern>(GetNodeValue(ext, "MG_LINE_PATTERN"));
                    style.LineSizeUnits        = ParseEnumValue <SizeUnit>(GetNodeValue(ext, "MG_LINE_UNITS"));
                    style.LineThickness        = Convert.ToDouble(GetNodeValue(ext, "MG_LINE_THICKNESS"));
                    style.FillPattern          = ParseEnumValue <FillPattern>(GetNodeValue(ext, "MG_FILL_PATTERN"));
                    style.FillTransparency     = 100 - ((Convert.ToInt32(GetNodeValue(ext, "MG_FILL_FORE_TRANSPARENCY"), 16) / 255.0) * 100.0);
                    style.FillForeColor        = Util.FromHtmlColor(GetNodeValue(ext, "MG_FILL_FORE_COLOR"));
                    style.FillBackColor        = Util.FromHtmlColor(GetNodeValue(ext, "MG_FILL_BACK_COLOR"));
                    style.FillBackTransparency = (GetNodeValue(ext, "MG_FILL_BACK_TRANSPARENCY") == "FF");
                    style.BorderPattern        = ParseEnumValue <LinePattern>(GetNodeValue(ext, "MG_BORDER_PATTERN"));
                    style.BorderSizeUnits      = ParseEnumValue <SizeUnit>(GetNodeValue(ext, "MG_BORDER_UNITS"));
                    style.BorderColor          = Util.FromHtmlColor(GetNodeValue(ext, "MG_BORDER_COLOR"));
                    style.BorderThickness      = Convert.ToDouble(GetNodeValue(ext, "MG_BORDER_THICKNESS"));
                    style.LabelSizeUnits       = ParseEnumValue <SizeUnit>(GetNodeValue(ext, "MG_LABEL_FONT_UNITS"));
                    style.LabelFontSize        = Convert.ToDouble(GetNodeValue(ext, "MG_LABEL_FONT_SIZE"));
                    style.LabelBold            = Convert.ToBoolean(GetNodeValue(ext, "MG_BOLD"));
                    style.LabelItalic          = Convert.ToBoolean(GetNodeValue(ext, "MG_ITALIC"));
                    style.LabelUnderline       = Convert.ToBoolean(GetNodeValue(ext, "MG_UNDERLINE"));
                    style.LabelForeColor       = Util.FromHtmlColor(GetNodeValue(ext, "MG_LABEL_FORECOLOR"));
                    style.LabelBackColor       = Util.FromHtmlColor(GetNodeValue(ext, "MG_LABEL_BACKCOLOR"));
                    style.LabelBackStyle       = ParseEnumValue <LabelStyle>(GetNodeValue(ext, "MG_LABEL_STYLE"));
                }
            }

            return(style);
        }
Beispiel #9
0
        public void AddLayerToMap(RedlineLayer layer)
        {
            var ldfId = new MgResourceIdentifier(layer.LayerDefinition);

            AddRedlineLayerToMap(ldfId);
        }
Beispiel #10
0
        public RedlineLayer CreateRedlineLayer(CreateRedlineLayerParams param, out bool bAddedToMap)
        {
            bAddedToMap = false;
            MgResourceIdentifier fsId = GenerateRedlineFeatureSourceId(param);

            string className    = null;
            string providerName = null;

            if (_resSvc.ResourceExists(fsId))
            {
                MgFeatureSchemaCollection   schemas = _featSvc.DescribeSchema(fsId, string.Empty, null);
                MgFeatureSchema             schema  = schemas.GetItem(0);
                MgClassDefinitionCollection classes = schema.GetClasses();
                MgClassDefinition           cls     = classes.GetItem(0);
                className = schema.Name + ":" + cls.Name;
            }
            else
            {
                MgFeatureSchema schema = RedlineSchemaFactory.CreateSchema(param.GeometryTypes);

                providerName = "OSGeo.SDF";
                if (param.Format == RedlineDataStoreFormat.SHP)
                {
                    providerName = "OSGeo.SHP";
                }
                else if (param.Format == RedlineDataStoreFormat.SQLite)
                {
                    providerName = "OSGeo.SQLite";
                }

                MgFileFeatureSourceParams createParams = new MgFileFeatureSourceParams(providerName, RedlineSchemaFactory.SPATIAL_CONTEXT, _map.GetMapSRS(), schema);
                _featSvc.CreateFeatureSource(fsId, createParams);

                //HACK: SQLite leaky abstraction (hard-coded schema name), SHP probably has some leaks of its own, so we can't assume MarkupSchema:Markup
                //as the class name so re-interrogate our schema to figure it out
                MgFeatureSchemaCollection schemas = _featSvc.DescribeSchema(fsId, string.Empty, null);
                schema = schemas.GetItem(0);
                MgClassDefinitionCollection classes = schema.GetClasses();
                MgClassDefinition           cls     = classes.GetItem(0);
                className = schema.Name + ":" + cls.Name;
            }

            MgResourceIdentifier ldfId = GenerateRedlineLayerDefinitionId(param);

            if (!_resSvc.ResourceExists(ldfId))
            {
                string       layerDefContent = CreateRedlineLayerDefinitionContent(fsId, className, param.Style, param.StyleType);
                byte[]       bytes           = Encoding.UTF8.GetBytes(layerDefContent);
                MgByteSource byteSource      = new MgByteSource(bytes, bytes.Length);
                MgByteReader byteReader      = byteSource.GetReader();

                _resSvc.SetResource(ldfId, byteReader, null);
            }

            if (param.AddToMap)
            {
                AddRedlineLayerToMap(ldfId);
                bAddedToMap = true;
            }

            var layer = new RedlineLayer(ldfId.Name, fsId.ToString(), ldfId.ToString(), param.GeometryTypes, param.StyleType);

            //If provider name was set, then we register this layer in the registry. Otherwise it means
            //the layer already exists and by extension already registered
            if (providerName != null)
            {
                _registry.AddRedlineLayer(layer, providerName);
            }
            return(layer);
        }