コード例 #1
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);
        }
コード例 #2
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;
     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.");
 }
コード例 #3
0
        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));
        }
コード例 #4
0
        private static Layer GetLineLayer(dynamic layer)
        {
            MapLineLayer lineLayer = new MapLineLayer(FeatureSet.OpenFile(layer["Path"]));
            LegacyDeserializer.DeserializeLayer(layer, lineLayer);

            return lineLayer;
        }
コード例 #5
0
 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;
 }
コード例 #6
0
ファイル: MapLineLayer.cs プロジェクト: vahidarr/DotSpatial
        /// <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 MapLineLayer result)
        {
            result = null;
            if (Selection == null || Selection.Count == 0)
            {
                return(false);
            }
            FeatureSet fs = Selection.ToFeatureSet();

            result = new MapLineLayer(fs);
            return(true);
        }
コード例 #7
0
        /// <summary>
        /// Allows for new behavior during deactivation.
        /// </summary>
        protected override void OnDeactivate()
        {
            if (_standBy) { return; }

            // Don't completely deactivate, but rather go into standby mode
            // where we draw only the content that we have actually locked in.
            _standBy = true;
            if (_coordinateDialog != null) { _coordinateDialog.Hide(); }
            if (_coordinates != null && _coordinates.Count > 1)
            {
                LineString ls = new LineString(_coordinates);
                FeatureSet fs = new FeatureSet(FeatureType.Line);
                fs.Features.Add(new Feature(ls));
                MapLineLayer gll = new MapLineLayer(fs)
                                       {
                                           Symbolizer =
                                               {
                                                   ScaleMode = ScaleMode.Symbolic,
                                                   Smoothing = true
                                               },
                                           MapFrame = Map.MapFrame
                                       };
                _tempLayer = gll;
                Map.MapFrame.DrawingLayers.Add(gll);
                Map.MapFrame.Invalidate();
                Map.Invalidate();
            }

            base.Deactivate();
        }
コード例 #8
0
        /// <summary>
        /// Deserializes the layer.
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="lineLayer">The line layer.</param>
        internal static void DeserializeLayer(dynamic layer, MapLineLayer lineLayer)
        {
            if (UseAlternateParser(layer))
            {
                // TODO: write alternate parser for this layer information.
                return;
            }
            var lineSymbolizer = new LineSymbolizer();
            lineSymbolizer.SetWidth(Convert.ToDouble(layer.ShapeFileProperties["LineOrPointSize"]));

            lineLayer.Symbolizer = lineSymbolizer;
        }
コード例 #9
0
ファイル: MapLineLayer.cs プロジェクト: ExRam/DotSpatial-PCL
 /// <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 MapLineLayer result)
 {
     result = null;
     if (Selection == null || Selection.Count == 0) return false;
     FeatureSet fs = Selection.ToFeatureSet();
     result = new MapLineLayer(fs);
     return true;
 }
コード例 #10
0
ファイル: OperationsMap.cs プロジェクト: shoaib-ijaz/geosoft
        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);
             }

            
           
            
            
        
        }
コード例 #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;
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
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;
        }
コード例 #14
0
        public void AddPolyline()
        {
            var layer = new MapLineLayer
            {
                Name = "Polyline",
                LegendText = "Polyline"
            };

            spatialMaplegend.MouseDown += (sender, args) =>
            {
                if (layer.IsSelected)
                {
                    layerBeingEdited = layer;

                    Points.Clear();

                    for (int i = 0; i < layer.DataSet.DataTable.Rows.Count; i++)
                    {
                        var point = layer.DataSet.GetFeature(i).BasicGeometry as Point;

                        Points.Add(point);
                    }
                }
            };

            var dataset =  new FeatureSet(FeatureType.Point);

            dataset.Projection = KnownCoordinateSystems.Geographic.World.WGS1984;

            dataset.DataTable.BeginInit();
            layer.DataSet = dataset;

            dataset.DataTable.EndLoadData();
            dataset.InvalidateVertices();

            spatialMap.Layers.Add(layer);
        }
コード例 #15
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;
     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.");
 }