コード例 #1
0
        /// <summary>
        /// Deserializes the layer.
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="pointLayer">The point layer.</param>
        internal static void DeserializeLayer(dynamic layer, MapPointLayer pointLayer)
        {
            if (UseAlternateParser(layer))
            {
                // TODO: write alternate parser for this layer information.
                return;
            }

            LegacyPointType typeOfPoint = (LegacyPointType)Enum.ToObject(typeof(LegacyPointType), Convert.ToInt32(layer.ShapeFileProperties["PointType"]));

            PointSymbolizer pointSymbolizer;

            if (ConvertLegacyPointTypeToPointShape(typeOfPoint) == PointShape.Undefined)
            {
                pointSymbolizer = new PointSymbolizer();
            }
            else
            {
                var color = LegacyDeserializer.GetColor(layer.ShapeFileProperties["Color"]);
                var width = Convert.ToDouble(layer.ShapeFileProperties["LineOrPointSize"]);

                pointSymbolizer = new PointSymbolizer(color, ConvertLegacyPointTypeToPointShape(typeOfPoint), width);
            }

            pointLayer.Symbolizer = pointSymbolizer;
        }
コード例 #2
0
        private static void DeserializeLayer(dynamic layer, IMap map, Layer featureLayer)
        {
            LegacyLayerType typeOfLayer = (LegacyLayerType)Enum.ToObject(typeof(LegacyLayerType), Convert.ToInt32(layer["Type"]));

            switch (typeOfLayer)
            {
            case LegacyLayerType.Grid:
                break;

            case LegacyLayerType.Image:
                break;

            case LegacyLayerType.Invalid:
                throw new ArgumentException("The LayerType is an invalid layer type and cannot be loaded.");

            case LegacyLayerType.LineShapefile:
                LegacyDeserializer.DeserializeLayer(layer, featureLayer as MapLineLayer);
                break;

            case LegacyLayerType.PointShapefile:
                LegacyDeserializer.DeserializeLayer(layer, featureLayer as MapPointLayer);
                break;

            case LegacyLayerType.PolygonShapefile:
                LegacyDeserializer.DeserializeLayer(layer, featureLayer as MapPolygonLayer);

                break;

            default:
                throw new NotImplementedException("That LayerType is not supported.");
            }

            LegacyDeserializer.DeserializeLayerProperties(layer, featureLayer);
        }
コード例 #3
0
        private static Layer GetPolygonLayer(dynamic layer)
        {
            MapPolygonLayer polyLayer = new MapPolygonLayer(FeatureSet.OpenFile(layer["Path"]));

            LegacyDeserializer.DeserializeLayer(layer, polyLayer);

            return(polyLayer);
        }
コード例 #4
0
        private static Layer GetLineLayer(dynamic layer)
        {
            MapLineLayer lineLayer = new MapLineLayer(FeatureSet.OpenFile(layer["Path"]));

            LegacyDeserializer.DeserializeLayer(layer, lineLayer);

            return(lineLayer);
        }
コード例 #5
0
        private static void DeserializeLayers(MapGroup g, dynamic layers)
        {
            foreach (var layer in layers)
            {
                try
                {
                    LegacyLayerType typeOfLayer = (LegacyLayerType)Enum.ToObject(typeof(LegacyLayerType), Convert.ToInt32(layer["Type"]));
                    Layer           mapLayer;

                    switch (typeOfLayer)
                    {
                    case LegacyLayerType.Grid:
                        mapLayer = GetGridLayer(layer);
                        break;

                    case LegacyLayerType.Image:
                        mapLayer = GetImageLayer(layer);
                        break;

                    case LegacyLayerType.Invalid:
                        throw new ArgumentException("The LayerType is an invalid layer type and cannot be loaded.");

                    case LegacyLayerType.LineShapefile:
                        mapLayer = GetLineLayer(layer);
                        break;

                    case LegacyLayerType.PointShapefile:
                        mapLayer = GetPointLayer(layer);
                        break;

                    case LegacyLayerType.PolygonShapefile:
                        mapLayer = GetPolygonLayer(layer);

                        break;

                    default:
                        throw new NotImplementedException("That LayerType is not supported.");
                    }

                    if (mapLayer != null)
                    {
                        LegacyDeserializer.DeserializeLayerProperties(layer, mapLayer);

                        g.Add(mapLayer);
                    }
                }
                catch (Exception exOpen)
                {
                    // TODO: provide a warning of some sort, possibly ask abort/retry/continue
                    // HACK: we should be catching a more specific exception.
                    Trace.WriteLine(exOpen.Message);
                }
            }
        }
コード例 #6
0
        private static void DeserializeLayerAlternateVersion(dynamic shapefileProperties, MapPolygonLayer polyLayer)
        {
            var polySymbolizer = new PolygonSymbolizer();
            var outlineColor   = LegacyDeserializer.GetColor(shapefileProperties.DefaultDrawingOptions["LineColor"]);
            var outlineWidth   = Convert.ToDouble(shapefileProperties.DefaultDrawingOptions["LineWidth"]);

            polySymbolizer.SetOutline(outlineColor, outlineWidth);
            if (Convert.ToBoolean(shapefileProperties.DefaultDrawingOptions["FillVisible"]))
            {
                Color color        = LegacyDeserializer.GetColor(shapefileProperties.DefaultDrawingOptions["FillBgColor"]);
                float transparency = Convert.ToInt32(shapefileProperties.DefaultDrawingOptions["FillTransparency"]) / 255f;
                color = color.ToTransparent(transparency);
                polySymbolizer.SetFillColor(color);
            }
            else
            {
                polySymbolizer.SetFillColor(Color.Transparent);
            }

            polyLayer.Symbolizer = polySymbolizer;
        }
コード例 #7
0
        /// <summary>
        /// Deserializes beginning from the given root.
        /// </summary>
        /// <param name="xmlRoot">Root to use as string point.</param>
        public void Deserialize(dynamic xmlRoot)
        {
            _map.MapFrame.ProjectionString = xmlRoot["ProjectProjection"];

            if (!Convert.ToBoolean(xmlRoot["ViewBackColor_UseDefault"]))
            {
                var mapControl = _map as Control;
                if (mapControl != null)
                {
                    mapControl.BackColor = LegacyDeserializer.GetColor(xmlRoot["ViewBackColor"]);
                }

                _map.Invalidate();
            }

            _map.MapFrame.ViewExtents.MaxX = Convert.ToDouble(xmlRoot.Extents["xMax"]);
            _map.MapFrame.ViewExtents.MaxY = Convert.ToDouble(xmlRoot.Extents["yMax"]);
            _map.MapFrame.ViewExtents.MinX = Convert.ToDouble(xmlRoot.Extents["xMin"]);
            _map.MapFrame.ViewExtents.MinY = Convert.ToDouble(xmlRoot.Extents["yMin"]);

            DeserializeGroups(xmlRoot.Groups.Elements());
        }
コード例 #8
0
        /// <summary>
        /// Opens the MW4 style project file.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        public void OpenFile(string fileName)
        {
            dynamic parser = DynamicXMLNode.Load(fileName);

            _map.MapFrame.ProjectionString = parser["ProjectProjection"];

            if (!Convert.ToBoolean(parser["ViewBackColor_UseDefault"]))
            {
                var mapControl = _map as Control;
                if (mapControl != null)
                {
                    mapControl.BackColor = LegacyDeserializer.GetColor(parser["ViewBackColor"]);
                }

                _map.Invalidate();
            }

            _map.MapFrame.ViewExtents.MaxX = Convert.ToDouble(parser.Extents["xMax"]);
            _map.MapFrame.ViewExtents.MaxY = Convert.ToDouble(parser.Extents["yMax"]);
            _map.MapFrame.ViewExtents.MinX = Convert.ToDouble(parser.Extents["xMin"]);
            _map.MapFrame.ViewExtents.MinY = Convert.ToDouble(parser.Extents["yMin"]);

            DeserializeGroups(parser.Groups.Elements());
        }
コード例 #9
0
        private static void DeserializeLabels(dynamic labels, IMap map, IFeatureLayer featureLayer)
        {
            int fieldIndex = Convert.ToInt32(labels["Field"]) - 1;
            var fieldName  = featureLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName;

            var symbolizer = new LabelSymbolizer();

            symbolizer.FontFamily = labels["Font"];

            try
            {
                if (Convert.ToBoolean(labels["Bold"]))
                {
                    symbolizer.FontStyle = FontStyle.Bold;
                }
                else if (Convert.ToBoolean(labels["Italic"]))
                {
                    symbolizer.FontStyle = FontStyle.Italic;
                }
                else if (Convert.ToBoolean(labels["Underline"]))
                {
                    symbolizer.FontStyle = FontStyle.Underline;
                }
            }
            catch (RuntimeBinderException)
            {
                // ignore and continue.
                // some versions of the files don't have these properties.
            }

            symbolizer.FontColor = LegacyDeserializer.GetColor(labels["Color"]);

            LegacyHJustification typeOfJustification = (LegacyHJustification)Enum.ToObject(typeof(LegacyHJustification), Convert.ToInt32(labels["Justification"]));

            switch (typeOfJustification)
            {
            case LegacyHJustification.Center:
                symbolizer.Orientation = ContentAlignment.MiddleCenter;
                break;

            case LegacyHJustification.Left:
                symbolizer.Orientation = ContentAlignment.MiddleLeft;
                break;

            case LegacyHJustification.Right:
                symbolizer.Orientation = ContentAlignment.MiddleRight;
                break;

            case LegacyHJustification.None:
            case LegacyHJustification.Raw:
            default:
                break;
            }

            try
            {
                symbolizer.DropShadowEnabled = Convert.ToBoolean(labels["UseShadows"]);
                symbolizer.DropShadowColor   = LegacyDeserializer.GetColor(labels["Color"]);
            }
            catch (RuntimeBinderException) { }

            // not entirely sure if Offset from MW4 translates to OffsetX.
            try { symbolizer.OffsetX = Convert.ToInt32(labels["Offset"]); }
            catch (RuntimeBinderException) { }

            string expression = String.Format("[{0}]", fieldName);

            featureLayer.AddLabels(expression, null, symbolizer, expression);
            featureLayer.LabelLayer.UseDynamicVisibility = Convert.ToBoolean(labels["UseMinZoomLevel"]);

            try { featureLayer.LabelLayer.DynamicVisibilityWidth = Convert.ToDouble(labels["Scale"]); }
            catch (RuntimeBinderException) { }
        }
コード例 #10
0
        /// <summary>
        /// Deserializes the layer.
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="polyLayer">The poly layer.</param>
        internal static void DeserializeLayer(dynamic layer, MapPolygonLayer polyLayer)
        {
            if (UseAlternateParser(layer))
            {
                DeserializeLayerAlternateVersion(layer.ShapefileProperties, polyLayer);
                return;
            }
            var polySymbolizer = new PolygonSymbolizer();
            var outlineColor   = LegacyDeserializer.GetColor(layer.ShapeFileProperties["OutLineColor"]);
            var outlineWidth   = Convert.ToDouble(layer.ShapeFileProperties["LineOrPointSize"]);

            polySymbolizer.SetOutline(outlineColor, outlineWidth);
            if (Convert.ToBoolean(layer.ShapeFileProperties["DrawFill"]))
            {
                Color color        = LegacyDeserializer.GetColor(layer.ShapeFileProperties["Color"]);
                float transparency = Convert.ToSingle(layer.ShapeFileProperties["TransparencyPercent"]);
                color = color.ToTransparent(transparency);
                polySymbolizer.SetFillColor(color);
            }
            else
            {
                polySymbolizer.SetFillColor(Color.Transparent);
            }

            polyLayer.Symbolizer = polySymbolizer;
            try
            {
                int fieldIndex = Convert.ToInt32(layer.ShapeFileProperties.Legend["FieldIndex"]);

                // we have to clear the categories or the collection ends up with a default item
                polyLayer.Symbology.Categories.Clear();

                foreach (var colorBreak in layer.ShapeFileProperties.Legend.ColorBreaks.Elements())
                {
                    PolygonCategory category;

                    string startValue = colorBreak["StartValue"];
                    string endValue   = colorBreak["EndValue"];

                    if (startValue == endValue)
                    {
                        category = new PolygonCategory(LegacyDeserializer.GetColor(colorBreak["StartColor"]), LegacyDeserializer.GetColor(colorBreak["StartColor"]), 0);
                        category.FilterExpression = String.Format("[{0}] = '{1}'", polyLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName, startValue);
                        category.LegendText       = startValue;
                    }
                    else
                    {
                        category = new PolygonCategory(LegacyDeserializer.GetColor(colorBreak["StartColor"]), LegacyDeserializer.GetColor(colorBreak["EndColor"]), 0, GradientType.Linear, outlineColor, outlineWidth);
                        category.FilterExpression = String.Format("'{2}' >= [{0}] >= '{1}'", polyLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName, startValue, endValue);
                        category.LegendText       = String.Format("{0} - {1}", startValue, endValue);
                    }
                    category.LegendText        = startValue;
                    category.LegendItemVisible = Convert.ToBoolean(colorBreak["Visible"]);
                    polyLayer.Symbology.AddCategory(category);
                }

                // it took too a lot of work to figure out that we would need to do this...
                polyLayer.ApplyScheme(polyLayer.Symbology);
            }
            catch (RuntimeBinderException)
            {
                // ignore and continue.
                // this means the legend is not available.
            }
        }
コード例 #11
0
        /// <summary>
        /// Deserializes beginning from the given root.
        /// </summary>
        /// <param name="xmlRoot">Root to use as string point.</param>
        public void Deserialize(dynamic xmlRoot)
        {
            var mapwin4Section   = xmlRoot.MapWindow4;
            var mapwingisSection = xmlRoot.MapWinGIS;

            _map.MapFrame.ProjectionString = mapwin4Section["ProjectProjection"];

            if (!Convert.ToBoolean(mapwin4Section["ViewBackColor_UseDefault"]))
            {
                var mapControl = _map as Control;
                if (mapControl != null)
                {
                    mapControl.BackColor = LegacyDeserializer.GetColor(mapwin4Section["ViewBackColor"]);
                }

                _map.Invalidate();
            }

            // Deserialize layers
            var layersDescs = mapwingisSection.Layers.Elements();
            var allLayers   = new Dictionary <int, List <ILayer> >(); // key: Group Name. Value: layers

            foreach (var layer in mapwin4Section.Layers.Elements())
            {
                var name     = (string)layer["Name"];
                var groupInd = Convert.ToInt32(layer["GroupIndex"]);
                if (!allLayers.ContainsKey(groupInd))
                {
                    allLayers[groupInd] = new List <ILayer>();
                }
                var listLayers = allLayers[groupInd];

                IMapLayer layerToAdd = null;
                foreach (var layersDesc in layersDescs)
                {
                    if (layersDesc["LayerName"] == name)
                    {
                        var lt = (string)layersDesc["LayerType"];
                        switch (lt)
                        {
                        case "Image":
                            layerToAdd = new MapImageLayer(ImageData.Open(layersDesc["Filename"]));
                            break;

                        case "Shapefile":
                            var fs = FeatureSet.OpenFile(layersDesc["Filename"]);
                            if (fs is PointShapefile)
                            {
                                layerToAdd = new MapPointLayer(fs);
                            }
                            else if (fs is PolygonShapefile)
                            {
                                layerToAdd = new MapPolygonLayer(fs);
                            }
                            else if (fs is LineShapefile)
                            {
                                layerToAdd = new MapLineLayer(fs);
                            }
                            else
                            {
                                var type = (object)fs.GetType().ToString();
                                Trace.WriteLine("Unsupported FeatureSet Type: " + type);
                            }

                            break;

                        default:
                            Trace.WriteLine("Unsupported LayerType: " + lt);
                            break;
                        }

                        break;
                    }
                }

                if (layerToAdd != null)
                {
                    layerToAdd.IsExpanded = Convert.ToBoolean(layer["Expanded"]);
                    listLayers.Add(layerToAdd);
                }
            }

            // Deserialize groups
            foreach (var group in mapwin4Section.Groups.Elements())
            {
                var gInd = Convert.ToInt32(group["Position"]);
                var g    = new MapGroup
                {
                    LegendText = group["Name"],
                    IsExpanded = Convert.ToBoolean(group["Expanded"])
                };
                List <ILayer> gl;
                if (allLayers.TryGetValue(gInd, out gl))
                {
                    foreach (var layer in gl)
                    {
                        g.Add(layer);
                    }
                }

                _map.MapFrame.Layers.Add(g);
            }
        }