public static IMapFeatureLayer Insert(this IMapLayerCollection collection, int index, IFeatureSet featureSet)
 {
     if (featureSet != null)
     {
         featureSet.ProgressHandler = collection.ProgressHandler;
         if ((featureSet.FeatureType == FeatureType.Point) || (featureSet.FeatureType == FeatureType.MultiPoint))
         {
             IMapPointLayer item = new MapPointLayer(featureSet);
             collection.Insert(index, item);
             item.ProgressHandler = collection.ProgressHandler;
             return item;
         }
         if (featureSet.FeatureType == FeatureType.Line)
         {
             IMapLineLayer layer2 = new MapLineLayer(featureSet);
             collection.Insert(index, layer2);
             layer2.ProgressHandler = collection.ProgressHandler;
             return layer2;
         }
         if (featureSet.FeatureType == FeatureType.Polygon)
         {
             IMapPolygonLayer layer3 = new MapPolygonLayer(featureSet);
             collection.Insert(index, layer3);
             layer3.ProgressHandler = collection.ProgressHandler;
             return layer3;
         }
     }
     return null;
 }
        private static Layer GetPointLayer(dynamic layer)
        {
            MapPointLayer pointLayer = new MapPointLayer(FeatureSet.OpenFile(layer["Path"]));
            LegacyDeserializer.DeserializeLayer(layer, pointLayer);

            return pointLayer;
        }
 /// <summary>
 /// This overload automatically constructs a new MapLayer from the specified
 /// feature layer with the default drawing characteristics and returns a valid
 /// IMapLayer which can be further cast into a PointLayer, MapLineLayer or
 /// a PolygonLayer, depending on the data that is passed in.
 /// </summary>
 /// <param name="featureSet">Any valid IFeatureSet that does not yet have drawing characteristics</param>
 /// <returns>A newly created valid implementation of FeatureLayer which at least gives a few more common
 /// drawing related methods and can also be cast into the appropriate Point, Line or Polygon layer.</returns>
 public virtual IMapFeatureLayer Add(IFeatureSet featureSet)
 {
     if (featureSet == null)
     {
         return(null);
     }
     featureSet.ProgressHandler = ProgressHandler;
     if (featureSet.FeatureType == FeatureType.Point || featureSet.FeatureType == FeatureType.MultiPoint)
     {
         IMapPointLayer pl = new MapPointLayer(featureSet);
         base.Add(pl);
         pl.ProgressHandler = ProgressHandler;
         return(pl);
     }
     if (featureSet.FeatureType == FeatureType.Line)
     {
         IMapLineLayer ll = new MapLineLayer(featureSet);
         base.Add(ll);
         ll.ProgressHandler = ProgressHandler;
         return(ll);
     }
     if (featureSet.FeatureType == FeatureType.Polygon)
     {
         IMapPolygonLayer pl = new MapPolygonLayer(featureSet);
         base.Add(pl);
         pl.ProgressHandler = ProgressHandler;
         return(pl);
     }
     return(null);
     //throw new NotImplementedException("Right now only point types are supported.");
 }
        public RuleSymbolizerPreview()
        {
            InitializeComponent();
            mapPreview.Projection = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            featureSetPoint.Projection = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            featureSetLine.Projection = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            featureSetPolygon.Projection = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            DotSpatial.Topology.LineString ls = new DotSpatial.Topology.LineString(new Coordinate[] { new Coordinate(-45D, 0D), new Coordinate(45D, 0D) });
            featureSetLine.AddFeature(ls);
            DotSpatial.Topology.Polygon polygon = new DotSpatial.Topology.Polygon(new LinearRing(new Coordinate[] {
                new Coordinate(90, -25), new Coordinate(135, -25), new Coordinate(135,25),new Coordinate(90, 25),new Coordinate(90, -25)
            }));
            featureSetPolygon.AddFeature(polygon);

            DotSpatial.Topology.Point point = new DotSpatial.Topology.Point(new Coordinate(-90D, 0D));
            featureSetPoint.AddFeature(point);

            layerPoint = new MapPointLayer(featureSetPoint);
            layerLine = new MapLineLayer(featureSetLine);
            layerPolygon = new MapPolygonLayer(featureSetPolygon);
               // layerPoint.Symbolizer = new DotSpatial.Symbology.PointSymbolizer(System.Drawing.Color.DarkBlue, DotSpatial.Symbology.PointShape.Triangle, 20);

            mapPreview.Layers.Add(layerLine);
            mapPreview.Layers.Add(layerPolygon);
            mapPreview.Layers.Add(layerPoint);
            this.SizeChanged += RuleSymbolizerPreview_SizeChanged;
            mapPreview.ViewExtents = new Extent(-180, -180, 180, 180);
            mapPreview.ViewExtents.SetCenter(new Coordinate(0, 0));
        }
        /// <summary>
        /// This overload automatically constructs a new MapLayer from the specified
        /// feature layer with the default drawing characteristics and returns a valid
        /// IMapLayer which can be further cast into a PointLayer, MapLineLayer or
        /// a PolygonLayer, depending on the data that is passed in.
        /// </summary>
        /// <param name="featureSet">Any valid IFeatureSet that does not yet have drawing characteristics</param>
        /// <returns>A newly created valid implementation of FeatureLayer which at least gives a few more common
        /// drawing related methods and can also be cast into the appropriate Point, Line or Polygon layer.</returns>
        public virtual IMapFeatureLayer Add(IFeatureSet featureSet)
        {
            if (featureSet == null)
            {
                return(null);
            }

            featureSet.ProgressHandler = ProgressHandler;
            IMapFeatureLayer res = null;

            if (featureSet.FeatureType == FeatureType.Point || featureSet.FeatureType == FeatureType.MultiPoint)
            {
                res = new MapPointLayer(featureSet);
            }
            else if (featureSet.FeatureType == FeatureType.Line)
            {
                res = new MapLineLayer(featureSet);
            }
            else if (featureSet.FeatureType == FeatureType.Polygon)
            {
                res = new MapPolygonLayer(featureSet);
            }

            if (res != null)
            {
                base.Add(res);
                res.ProgressHandler = ProgressHandler;
            }

            return(res);
        }
Example #6
0
        /// <summary>
        /// This is the strong typed version of the same process that is specific to geo point layers.
        /// </summary>
        /// <param name="result">The new GeoPointLayer to be created</param>
        /// <returns>Boolean, true if there were any values in the selection</returns>
        public virtual bool CreateLayerFromSelectedFeatures(out MapPointLayer result)
        {
            result = null;
            if (Selection == null || Selection.Count == 0)
            {
                return(false);
            }
            FeatureSet fs = Selection.ToFeatureSet();

            result = new MapPointLayer(fs);
            return(true);
        }
        /// <summary>
        /// This overload automatically constructs a new MapLayer from the specified
        /// feature layer with the default drawing characteristics and returns a valid
        /// IMapLayer which can be further cast into a PointLayer, MapLineLayer or
        /// a PolygonLayer, depending on the data that is passed in.
        /// </summary>
        /// <param name="featureSet">Any valid IFeatureSet that does not yet have drawing characteristics</param>
        /// <returns>A newly created valid implementation of FeatureLayer which at least gives a few more common
        /// drawing related methods and can also be cast into the appropriate Point, Line or Polygon layer.</returns>
        public virtual IMapFeatureLayer Add(IFeatureSet featureSet)
        {
            if (featureSet == null) return null;

            featureSet.ProgressHandler = ProgressHandler;
            IMapFeatureLayer res = null;
            if (featureSet.FeatureType == FeatureType.Point || featureSet.FeatureType == FeatureType.MultiPoint)
            {
                res = new MapPointLayer(featureSet);
            }
            else if (featureSet.FeatureType == FeatureType.Line)
            {
                res = new MapLineLayer(featureSet);
            }
            else if (featureSet.FeatureType == FeatureType.Polygon)
            {
                res = new MapPolygonLayer(featureSet);
            }
            if (res != null)
            {
                base.Add(res);
                res.ProgressHandler = ProgressHandler;
            }

            return res;
        }
        public void TestMapFrameIsNotNull_Group()
        {
            string filename = Path.Combine("Data", "test-RandomPts.shp");
            string projectFileName = FileTools.GetTempFileName(".dspx");
            _filesToRemove.Add(projectFileName);
            
            AppManager manager = new AppManager();
            Map map = new Map();
            manager.Map = map;

            //new map group added to map
            MapGroup grp = new MapGroup(map, "group1");

            //new map layer added to group
            IFeatureSet fs = FeatureSet.Open(filename);
            MapPointLayer l = new MapPointLayer(fs);

            //add layer to group
            grp.Layers.Add(l);

            Assert.Greater(map.Layers.Count, 0);
            Assert.IsNotNull(l.MapFrame);

            manager.SerializationManager.SaveProject(projectFileName);
            Assert.True(System.IO.File.Exists(projectFileName));

            //reopen the project
            map.Layers.Clear();
            Assert.AreEqual(map.Layers.Count, 0);

            manager.SerializationManager.OpenProject(projectFileName);

            List<ILayer> layers = map.GetAllLayers();
            Assert.IsNotNull(layers[0].MapFrame);
        }
        public void TestMapPointLayer()
        {
            string filename = Path.Combine("Data", "test-RandomPts.shp");

            IFeatureSet fs = FeatureSet.Open(filename);
            MapPointLayer l = new MapPointLayer(fs);
            XmlSerializer s = new XmlSerializer();
            string result = s.Serialize(l);

            XmlDeserializer d = new XmlDeserializer();
            MapPointLayer newPointLayer = d.Deserialize<MapPointLayer>(result);

            Assert.IsNotNull(newPointLayer);
            Assert.True(filename.Contains(newPointLayer.DataSet.Filename));
        }
Example #10
0
 /// <summary>
 /// This is the strong typed version of the same process that is specific to geo point layers.
 /// </summary>
 /// <param name="result">The new GeoPointLayer to be created</param>
 /// <returns>Boolean, true if there were any values in the selection</returns>
 public virtual bool CreateLayerFromSelectedFeatures(out MapPointLayer result)
 {
     result = null;
     if (Selection == null || Selection.Count == 0) return false;
     var fs = Selection.ToFeatureSet();
     result = new MapPointLayer(fs);
     return true;
 }
Example #11
0
        /// <summary>
        /// Creates a new raster with the specified cell size.  If the cell size
        /// is zero, this will default to the shorter of the width or height
        /// divided by 256.  If the cell size produces a raster that is greater
        /// than 8, 000 pixels in either dimension, it will be re-sized to
        /// create an 8, 000 length or width raster.
        /// </summary>
        /// <param name="fs">The featureset to convert to a raster.</param>
        /// <param name="extent">Force the raster to this specified extent.</param>
        /// <param name="cellSize">The double extent of the cell.</param>
        /// <param name="fieldName">The integer field index of the file.</param>
        /// <param name="outputFileName">The fileName of the raster to create.</param>
        /// <param name="driverCode">The optional GDAL driver code to use if using GDAL
        /// for a format that is not discernable from the file extension.  An empty string
        ///  is usually perfectly acceptable here.</param>
        /// <param name="options">For GDAL rasters, they can be created with optional parameters
        ///  passed in as a string array.  In most cases an empty string is perfectly acceptable.</param>
        /// <param name="progressHandler">An interface for handling the progress messages.</param>
        /// <returns>Generates a raster from the vectors.</returns>
        public static IRaster ToRaster(IFeatureSet fs, Extent extent, double cellSize, string fieldName,
                                       string outputFileName,
                                       string driverCode, string[] options, IProgressHandler progressHandler)
        {
            Extent env = extent;
            if (cellSize == 0)
            {
                if (env.Width < env.Height)
                {
                    cellSize = env.Width / 256;
                }
                else
                {
                    cellSize = env.Height / 256;
                }
            }
            int w = (int)Math.Ceiling(env.Width / cellSize);
            if (w > 8000)
            {
                w = 8000;
                cellSize = env.Width / 8000;
            }
            int h = (int)Math.Ceiling(env.Height / cellSize);
            if (h > 8000)
            {
                h = 8000;
            }
            Bitmap bmp = new Bitmap(w, h);
            Graphics g = Graphics.FromImage(bmp);
            g.Clear(Color.Transparent);
            g.SmoothingMode = SmoothingMode.None;
            g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
            g.InterpolationMode = InterpolationMode.NearestNeighbor;
            Hashtable colorTable;
            MapArgs args = new MapArgs(new Rectangle(0, 0, w, h), env, g);

            switch (fs.FeatureType)
            {
                case FeatureType.Polygon:
                    {
                        MapPolygonLayer mpl = new MapPolygonLayer(fs);
                        PolygonScheme ps = new PolygonScheme();
                        colorTable = ps.GenerateUniqueColors(fs, fieldName);
                        mpl.Symbology = ps;
                        mpl.DrawRegions(args, new List<Extent> { env });
                    }
                    break;
                case FeatureType.Line:
                    {
                        MapLineLayer mpl = new MapLineLayer(fs);
                        LineScheme ps = new LineScheme();
                        colorTable = ps.GenerateUniqueColors(fs, fieldName);
                        mpl.Symbology = ps;
                        mpl.DrawRegions(args, new List<Extent> { env });
                    }
                    break;
                default:
                    {
                        MapPointLayer mpl = new MapPointLayer(fs);
                        PointScheme ps = new PointScheme();
                        colorTable = ps.GenerateUniqueColors(fs, fieldName);
                        mpl.Symbology = ps;
                        mpl.DrawRegions(args, new List<Extent> { env });
                    }
                    break;
            }
            Type tp = fieldName == "FID" ? typeof(int) : fs.DataTable.Columns[fieldName].DataType;
            // We will try to convert to double if it is a string
            if (tp == typeof(string))
            {
                tp = typeof(double);
            }
            InRamImageData image = new InRamImageData(bmp, env);
            ProgressMeter pm = new ProgressMeter(progressHandler, "Converting To Raster Cells", h);

            IRaster output;
            output = Raster.Create(outputFileName, driverCode, w, h, 1, tp, options);
            output.Bounds = new RasterBounds(h, w, env);

            double noDataValue = output.NoDataValue;

            if (fieldName != "FID")
            {
                // We can't use this method to calculate Max on a non-existent FID field.
                double dtMax = Convert.ToDouble(fs.DataTable.Compute("Max(" + fieldName + ")", ""));
                double dtMin = Convert.ToDouble(fs.DataTable.Compute("Min(" + fieldName + ")", ""));

                if (dtMin <= noDataValue && dtMax >= noDataValue)
                {
                    if (dtMax != GetFieldValue(tp, "MaxValue"))
                    {
                        output.NoDataValue = noDataValue;
                    }
                    else if (dtMin != GetFieldValue(tp, "MinValue"))
                    {
                        output.NoDataValue = noDataValue;
                    }
                }
            }

            List<RcIndex> locations = new List<RcIndex>();
            List<string> failureList = new List<string>();
            for (int row = 0; row < h; row++)
            {
                for (int col = 0; col < w; col++)
                {
                    Color c = image.GetColor(row, col);
                    if (c.A == 0)
                    {
                        output.Value[row, col] = output.NoDataValue;
                    }
                    else
                    {
                        if (colorTable.ContainsKey(c) == false)
                        {
                            if (c.A < 125)
                            {
                                output.Value[row, col] = output.NoDataValue;
                                continue;
                            }

                            // Use a color matching distance to pick the closest member
                            object val = GetCellValue(w, h, row, col, image, c, colorTable, locations);

                            output.Value[row, col] = GetDouble(val, failureList);
                        }
                        else
                        {
                            output.Value[row, col] = GetDouble(colorTable[c], failureList);
                        }
                    }
                }
                pm.CurrentValue = row;
            }
            const int maxIterations = 5;
            int iteration = 0;
            while (locations.Count > 0)
            {
                List<RcIndex> newLocations = new List<RcIndex>();
                foreach (RcIndex location in locations)
                {
                    object val = GetCellValue(w, h, location.Row, location.Column, image,
                                              image.GetColor(location.Row, location.Column), colorTable, newLocations);
                    output.Value[location.Row, location.Column] = GetDouble(val, failureList);
                }
                locations = newLocations;
                iteration++;
                if (iteration > maxIterations)
                {
                    break;
                }
            }

            pm.Reset();
            return output;
        }
Example #12
0
        [Ignore] // todo: fix reprojections
        public void TestMapFrameIsNotNull_Group()
        {
            var filename = FileTools.PathToTestFile(@"Shapefiles\Cities\cities.shp");
            var projectFileName = FileTools.GetTempFileName(".dspx");
            _filesToRemove.Add(projectFileName);
            
            var manager = new AppManager();
            var map = new Map();
            manager.Map = map;

            //new map group added to map
            var grp = new MapGroup(map, "group1");

            //new map layer added to group
            var fs = FeatureSet.Open(filename);
            var l = new MapPointLayer(fs);

            //add layer to group
            grp.Layers.Add(l);

            Assert.Greater(map.Layers.Count, 0);
            Assert.IsNotNull(l.MapFrame);

            manager.SerializationManager.SaveProject(projectFileName);
            Assert.True(File.Exists(projectFileName));

            //reopen the project
            map.Layers.Clear();
            Assert.AreEqual(map.Layers.Count, 0);

            manager.SerializationManager.OpenProject(projectFileName);

            var layers = map.GetAllLayers();
            Assert.IsNotNull(layers[0].MapFrame);
        }
        public void TestMapFrameIsNotNull_Group()
        {
            const string filename = @".\TestFiles\test-RandomPts.shp";
            const string projectFileName = @".\testmapframeisnotnull.dspx";
            
            AppManager manager = new AppManager();
            Map map = new Map();
            manager.Map = map;

            //new map group added to map
            MapGroup grp = new MapGroup(map, "group1");

            //new map layer added to group
            IFeatureSet fs = FeatureSet.Open(filename);
            MapPointLayer l = new MapPointLayer(fs);

            //add layer to group
            grp.Layers.Add(l);

            Assert.Greater(map.Layers.Count, 0);
            Assert.IsNotNull(l.MapFrame);

            manager.SerializationManager.SaveProject(projectFileName);
            Assert.True(System.IO.File.Exists(projectFileName));

            //reopen the project
            map.Layers.Clear();
            Assert.AreEqual(map.Layers.Count, 0);

            manager.SerializationManager.OpenProject(projectFileName);

            List<ILayer> layers = map.GetAllLayers();
            Assert.IsNotNull(layers[0].MapFrame);

            //delete file
            System.IO.File.Delete(projectFileName);
        }
Example #14
0
        private void AddLayers(string type)
        {
            if (type == "cross" || type == "all")
            {
                idcross = new FeatureSet(FeatureType.Line);
                idcross.Projection = proj;
                idcross.Name = "cross";
                IMapLineLayer ml = new MapLineLayer(idcross);
                ml.Symbolizer = new LineSymbolizer();
                ml.Symbolizer.SetFillColor(Color.Red);

                map1.Layers.Add(ml);
            }


            if (type == "point" || type == "all")
            {
                pointSelect = new FeatureSet(FeatureType.Point);
                pointSelect.Projection = proj;
                pointSelect.Name = "point";
                IMapPointLayer mp = new MapPointLayer(pointSelect);
                mp.Symbolizer = new PointSymbolizer();
                mp.Symbolizer.SetSize(new Size2D(5, 5));
                mp.Symbolizer.SetOutline(Color.Blue, 1.0);
                mp.Symbolizer.SetFillColor(Color.Blue);
                map1.Layers.Add(mp);
            }
             if (type == "line" || type == "all")
            {
                cross = new FeatureSet(FeatureType.Line);
                cross.Projection = proj;
                cross.Name = "line";
             IMapLineLayer ml = new MapLineLayer(cross);
             ml.Symbolizer = new LineSymbolizer();
             ml.Symbolizer.SetOutline(Color.Magenta, 1.0);
             map1.Layers.Add(ml);
             }

             if (type == "polygon" || type == "all")
             {
                 poly = new FeatureSet(FeatureType.Polygon);
                 poly.Projection = proj;
                 poly.Name = "polygon";
                 IMapPolygonLayer my = new MapPolygonLayer(poly);
                 my.Symbolizer = new PolygonSymbolizer();
                 my.Symbolizer.SetOutline(Color.Maroon, 1.0);
                 my.Symbolizer.SetFillColor(Color.Transparent);
                 map1.Layers.Add(my);
             }

            
           
            
            
        
        }
        public void TestMapFrameIsNotNull()
        {
            const string filename = @".\TestFiles\test-RandomPts.shp";
            const string projectFileName = @".\testmapframeisnotnull.dspx";
            //string projPath = Path.Combine(Path.GetTempPath(), projectFileName);

            AppManager manager = new AppManager();
            Map map = new Map();
            manager.Map = map;

            IFeatureSet fs = FeatureSet.Open(filename);
            MapPointLayer l = new MapPointLayer(fs);
            map.Layers.Add(l);
            Assert.Greater(map.Layers.Count, 0);

            manager.SerializationManager.SaveProject(projectFileName);
            Assert.True(System.IO.File.Exists(projectFileName));

            //reopen the project
            map.Layers.Clear();
            Assert.AreEqual(map.Layers.Count, 0);

            manager.SerializationManager.OpenProject(projectFileName);
            Assert.Greater(map.Layers.Count, 0);
            Assert.IsNotNull(map.Layers[0].MapFrame);

            //delete file
            System.IO.File.Delete(projectFileName);
        }
        public void TestMapPointLayer()
        {
            const string filename = @".\TestFiles\test-RandomPts.shp";

            IFeatureSet fs = FeatureSet.Open(filename);
            MapPointLayer l = new MapPointLayer(fs);
            XmlSerializer s = new XmlSerializer();
            string result = s.Serialize(l);

            XmlDeserializer d = new XmlDeserializer();
            MapPointLayer newPointLayer = d.Deserialize<MapPointLayer>(result);

            Assert.IsNotNull(newPointLayer);
            Assert.AreEqual(filename, newPointLayer.DataSet.Filename);
        }
        public void TestMapFrameIsNotNull()
        {
            string filePath = AppDomain.CurrentDomain.BaseDirectory;
            string filename = Path.Combine(filePath, "Data", "test-RandomPts.shp");
            string projectFileName = Path.Combine(filePath, "testmapframeisnotnull.dspx");

            AppManager manager = new AppManager();
            Map map = new Map();
            manager.Map = map;

            IFeatureSet fs = FeatureSet.Open(filename);
            MapPointLayer l = new MapPointLayer(fs);
            map.Layers.Add(l);
            Assert.Greater(map.Layers.Count, 0);

            manager.SerializationManager.SaveProject(projectFileName);
            Assert.True(System.IO.File.Exists(projectFileName));

            //reopen the project
            map.Layers.Clear();
            Assert.AreEqual(map.Layers.Count, 0);

            manager.SerializationManager.OpenProject(projectFileName);
            Assert.Greater(map.Layers.Count, 0);
            Assert.IsNotNull(map.Layers[0].MapFrame);

            //delete file
            System.IO.File.Delete(projectFileName);
        }
Example #18
0
        private MapPointLayer CreateSearchResultLayer(SearchResultItem item, IMapGroup root)
        {
            Debug.WriteLine("Starting method CreateSearchResultLayer");
            var myLayer = new MapPointLayer(item.FeatureSet);

            // Get Title of web-server
            var webService = _searchSettings.WebServicesSettings.WebServices.FirstOrDefault(
                ws => ws.ServiceCode == item.ServiceCode);
            var defaulLegendText = webService != null? webService.Title : item.ServiceCode;

            // Build legend text
            var legendText = defaulLegendText;
            int nameIndex = 1;
            Debug.WriteLine("Starting while loop.");
            while(true)
            {
                // Check if legend text is already used
                var nameUsed = root.Layers.Any(layer => layer.LegendText == legendText);
                if (!nameUsed)
                {
                    Debug.WriteLine("Exiting while loop");
                    break;
                }

                // Create new legend text
                nameIndex++;
                legendText = string.Format("{0} ({1})", defaulLegendText, nameIndex);
            }

            myLayer.LegendText = legendText;
            Debug.WriteLine("Returning myLayer");
            return myLayer;
        }
 /// <summary>
 /// This overload automatically constructs a new MapLayer from the specified
 /// feature layer with the default drawing characteristics and returns a valid
 /// IMapLayer which can be further cast into a PointLayer, MapLineLayer or
 /// a PolygonLayer, depending on the data that is passed in.
 /// </summary>
 /// <param name="featureSet">Any valid IFeatureSet that does not yet have drawing characteristics</param>
 /// <returns>A newly created valid implementation of FeatureLayer which at least gives a few more common
 /// drawing related methods and can also be cast into the appropriate Point, Line or Polygon layer.</returns>
 public virtual IMapFeatureLayer Add(IFeatureSet featureSet)
 {
     if (featureSet == null) return null;
     featureSet.ProgressHandler = ProgressHandler;
     if (featureSet.FeatureType == FeatureType.Point || featureSet.FeatureType == FeatureType.MultiPoint)
     {
         IMapPointLayer pl = new MapPointLayer(featureSet);
         base.Add(pl);
         pl.ProgressHandler = ProgressHandler;
         return pl;
     }
     if (featureSet.FeatureType == FeatureType.Line)
     {
         IMapLineLayer ll = new MapLineLayer(featureSet);
         base.Add(ll);
         ll.ProgressHandler = ProgressHandler;
         return ll;
     }
     if (featureSet.FeatureType == FeatureType.Polygon)
     {
         IMapPolygonLayer pl = new MapPolygonLayer(featureSet);
         base.Add(pl);
         pl.ProgressHandler = ProgressHandler;
         return pl;
     }
     return null;
     //throw new NotImplementedException("Right now only point types are supported.");
 }
Example #20
0
        public void SetPointLayer(IFeatureSet value)
        {
            IMapLayer mapR = null;
            foreach (IMapLayer ra in map1.GetPointLayers())
            {
               if (ra.LegendText== "DataSetPoints")
                mapR = ra;
            }

            if (mapR != null)
                map1.Layers.Remove(mapR);

            IMapPointLayer mp = new MapPointLayer(value);
            value.Name = "DataSetPoints";
            mp.Symbolizer = new PointSymbolizer();
            mp.Symbolizer.SetSize(new Size2D(7, 7));
            //mp.Symbolizer.Symbols[0].SymbolType= Sym
            mp.Symbolizer.SetOutline(Color.Green, 1.0);
            mp.Symbolizer.SetFillColor(Color.Red);
            map1.Layers.Add(mp);
            map1.ViewExtents = value.Extent;
        }
        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
                                {
                                    Trace.WriteLine("Unsupported FeatureSet Type: " + fs.GetType());
                                }
                                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);
            }
        }
        /// <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;
        }
Example #23
0
        public void TestMapPointLayer()
        {
            var filename = FileTools.PathToTestFile(@"Shapefiles\Cities\cities.shp");

            var fs = FeatureSet.Open(filename);
            var l = new MapPointLayer(fs);
            var s = new XmlSerializer();
            var result = s.Serialize(l);

            var d = new XmlDeserializer();
            var newPointLayer = d.Deserialize<MapPointLayer>(result);

            Assert.IsNotNull(newPointLayer);
            Assert.IsTrue(string.Equals(filename, Path.GetFullPath(newPointLayer.DataSet.Filename), StringComparison.OrdinalIgnoreCase));
        }