Example #1
0
        internal IMapFeatureLayer CreateLayer(string type, string layerName)
        {
            IMapFeatureLayer layer = null;

            switch (type)
            {
            case "Polygon":
                layer = new MapPolygonLayer();
                break;

            case "Line":
                layer = new MapLineLayer();
                break;

            case "Point":
                layer = new MapPointLayer();
                break;

            case "MultiPolygon":
                layer = new MapPolygonLayer();
                break;

            default:
                throw new Exception("Wrong Layer Class:" + type);
            }
            layer.DataSet.Name = layerName;
            layer.LegendText   = layerName;
            return(layer);
        }
Example #2
0
        //adds the line layer if it doesn't exist, clears it otherwise
        private void addLineLayer()
        {
            if (lineLayer == null)
            {
                var rectangleFs = new FeatureSet(FeatureType.Line);
                rectangleFs.DataTable.Columns.Add(new DataColumn("ID"));
                rectangleFs.Projection = mainMap.Projection;
                lineLayer = new MapLineLayer(rectangleFs)
                {
                    LegendText = "Cross Section Line"
                };
                mainMap.Layers.Add(lineLayer);

                //The symbolizer that controls the look of the final line
                lineLayer.Symbolizer          = new LineSymbolizer(Color.Red, 3);
                lineLayer.SelectionSymbolizer = lineLayer.Symbolizer;
            }
            else
            {
                lineLayer.DataSet.Features.Clear();

                //move linelayer to top if it isn't there
                if (mainMap.Layers.IndexOf(lineLayer) != mainMap.Layers.Count - 1)
                {
                    lineLayer.LockDispose();
                    mainMap.Layers.Remove(lineLayer);
                    mainMap.Layers.Add(lineLayer);
                    lineLayer.UnlockDispose();
                }
            }
        }
Example #3
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;
            _coordinateDialog?.Hide();

            if (_coordinates != null && _coordinates.Count > 1)
            {
                LineString ls = new LineString(_coordinates.ToArray());
                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();
            }

            Deactivate();
        }
Example #4
0
        protected IMapLineLayer GetLineLayer()
        {
            IMapLineLayer lineLayer = null;

            foreach (ILayer item in _map.MapFrame.DrawingLayers)
            {
                if (item.LegendText == "Line")
                {
                    lineLayer = item as IMapLineLayer;
                    break;
                }
            }
            if (lineLayer == null)
            {
                lineLayer            = new MapLineLayer();
                lineLayer.LegendText = "Line";
                lineLayer.Symbolizer = GIS.FrameWork.ROIConfigure.lineSymbolizer;
                if (_map.MapFrame.DrawingLayers.Count > 0 && _map.MapFrame.DrawingLayers[_map.MapFrame.DrawingLayers.Count - 1].LegendText == "Point")
                {
                    _map.MapFrame.DrawingLayers.Insert(_map.MapFrame.DrawingLayers.Count - 1, lineLayer);
                }
                else
                {
                    _map.MapFrame.DrawingLayers.Add(lineLayer);
                }
            }
            return(lineLayer);
        }
        public void DrawLine(Coordinate p1, Coordinate p2, Double width, System.Drawing.Color col, IMap MapCanvas)
        {
            Coordinate[] L = new Coordinate[2]; //x-axis

            L[0] = p1;
            L[1] = p2;

            LineString ls = new LineString(L);
            //creates a feature from the linestring
            Feature f = new Feature(ls);
            //  Feature f = new Feature(axisLines);
            FeatureSet fs = new FeatureSet(f.FeatureType);

            fs.Features.Add(f);

            MapLineLayer rangeRingAxis;

            rangeRingAxis            = new MapLineLayer(fs);// MapPolygonLayer(fs);
            rangeRingAxis.Symbolizer = new LineSymbolizer(col, width);
            MapCanvas.MapFrame.DrawingLayers.Add(rangeRingAxis);


            //MapCanvas.MapFrame.DrawingLayers.Add(rangeRingAxis);

            // Request a redraw
            MapCanvas.MapFrame.Invalidate();
            // MapCanvas.MapFrame.Invalidate();
        }
        /// <summary>
        /// 비활성화하는 동안 새로운 동작을 허용합니다.
        /// </summary>
        protected override void OnDeactivate()
        {
            if (_standBy)
            {
                return;
            }

            // 완전히 비활성화하지 않고 대기 모드로 전환하십시오.
            // 여기서 실제로 잠근 내용 만 그립니다.
            _standBy = true;
            _coordinateDialog?.Hide();

            if (_coordinates != null && _coordinates.Count > 1)
            {
                LineString ls = new LineString(_coordinates.ToArray());
                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();
            }

            Deactivate();
        }
        public void kDrawArc(Double x0, Double y0, Double r, double AzStrat, double AzFinish, Int16 numVertex, IMap MapCanvas, Color color)
        {
            if (AzFinish < AzStrat)
            {
                AzFinish += 360;
            }
            Double dAng = (AzFinish - AzStrat) / numVertex;

            Coordinate[] cr = new Coordinate[numVertex + 1]; //x-axis

            for (int iAng = 0; iAng <= numVertex; iAng++)
            {
                Double ang1 = AzStrat + iAng * dAng;
                Double x1   = Math.Sin(ang1 * Math.PI / 180) * r + x0;
                Double y1   = Math.Cos(ang1 * Math.PI / 180) * r + y0;
                cr[iAng] = new Coordinate(x1, y1);
            }
            LineString ls = new LineString(cr);
            Feature    f  = new Feature(ls);
            FeatureSet fs = new FeatureSet(f.FeatureType);

            fs.Features.Add(f);

            MapLineLayer circleShp;

            circleShp            = new MapLineLayer(fs);
            circleShp.Symbolizer = new LineSymbolizer(color, 1);

            MapCanvas.MapFrame.DrawingLayers.Add(circleShp);

            // Request a redraw
            MapCanvas.MapFrame.Invalidate();
        }
        public void DrawLineCross(Double x, Double y, double size, Double width, System.Drawing.Color col, IMap MapCanvas)
        {
            Coordinate[] L1 = new Coordinate[2]; //x-axis
            L1[0] = new Coordinate(x - size, y);
            L1[1] = new Coordinate(x + size, y);
            Coordinate[] L2 = new Coordinate[2]; //x-axis
            L2[0] = new Coordinate(x, y - size);
            L2[1] = new Coordinate(x, y + size);

            LineString ls1 = new LineString(L1);
            LineString ls2 = new LineString(L2);
            Feature    f1  = new Feature(ls1);
            Feature    f2  = new Feature(ls2);
            FeatureSet fs  = new FeatureSet(FeatureType.Line);

            fs.Features.Add(f1);
            fs.Features.Add(f2);

            MapLineLayer rangeRingAxis;

            rangeRingAxis            = new MapLineLayer(fs);
            rangeRingAxis.Symbolizer = new LineSymbolizer(col, width);

            MapCanvas.MapFrame.DrawingLayers.Add(rangeRingAxis);

            // Request a redraw
            MapCanvas.MapFrame.Invalidate();
        }
        public void kDrawCircle(Coordinate pt, Double r, Int16 numVertex, IMap MapCanvas, Color color)
        {
            Double dAng = 360 / numVertex;

            Coordinate[] cr = new Coordinate[numVertex + 1]; //x-axis
            for (int iAng = 0; iAng <= numVertex; iAng++)
            {
                Double ang1 = iAng * dAng;
                Double x1   = Math.Sin(ang1 * Math.PI / 180) * r + pt.X;
                Double y1   = Math.Cos(ang1 * Math.PI / 180) * r + pt.Y;
                cr[iAng] = new Coordinate(x1, y1);
            }
            LineString ls = new LineString(cr);
            Feature    f  = new Feature(ls);
            FeatureSet fs = new FeatureSet(f.FeatureType);

            fs.Features.Add(f);

            MapLineLayer circleShp;

            circleShp            = new MapLineLayer(fs);
            circleShp.Symbolizer = new LineSymbolizer(color, 1);

            MapCanvas.MapFrame.DrawingLayers.Add(circleShp);

            // Request a redraw
            MapCanvas.MapFrame.Invalidate();
        }
Example #10
0
        private void NewFeatureLayer(DotSpatial.Controls.IMap map, string directory)
        {
            string filename = Path.Combine(directory, this.Name + ".shp");

            if (!File.Exists(filename))
            {
                CreateFeature(map.Projection, directory);
            }

            this.Feature = FeatureSet.Open(filename);
            if (this.Feature.FeatureType == FeatureType.Polygon)
            {
                var layer = new MapPolygonLayer(this.Feature);
                map.Layers.Add(layer);
                this.FeatureLayer = layer;
            }
            else if (this.Feature.FeatureType == FeatureType.Line)
            {
                var layer = new MapLineLayer(this.Feature);
                map.Layers.Add(layer);
                this.FeatureLayer = layer;
            }
            else if (this.Feature.FeatureType == FeatureType.Point)
            {
                var layer = new MapPointLayer(this.Feature);
                map.Layers.Add(layer);
                this.FeatureLayer = layer;
            }
        }
Example #11
0
        public override async void MapViewTapped(MapView mapView, MapViewInputEventArgs e, bool drawing)
        {
            if (!drawing)
            {
                var graphic = await GraphicsLayer.HitTestAsync(mapView, e.Position);

                if (graphic != null)
                {
                    OnItemTapped(int.Parse($"{graphic.Attributes[CURR_GEO]}"));
                }
                return;
            }

            MapPoint newPoint = (MapPoint)GeometryEngine.Project(e.Location, SpatialReferences.Wgs84);

            if (_drawPointList.Count == 0)
            {
                AddGraphic(newPoint, DRAFT, MapLineLayer.GetSymbol(GeoMarkerType.Point, GeoStatus.Hilight));
            }
            else
            {
                Polyline line = new Polyline(new MapPoint[] { _drawPointList.Last(), newPoint });
                AddGraphic(line, DRAFT, MapLineLayer.GetSymbol(GeoMarkerType.Line, GeoStatus.Hilight));
            }

            _drawPointList.Add(newPoint);
        }
Example #12
0
        private void createPolylineShapefileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Change the mouse cursor
            map1.Cursor = Cursors.Cross;

            //set shape type
            shapeType = "line";

            //set projection
            lineF.Projection = map1.Projection;

            //initialize the featureSet attribute table
            DataColumn column = new DataColumn("LineID");

            if (!lineF.DataTable.Columns.Contains("LineID"))
            {
                lineF.DataTable.Columns.Add(column);
            }

            //add the featureSet as map layer
            lineLayer = (MapLineLayer)map1.Layers.Add(lineF);

            //Set the symbolizer to the line feature.
            LineSymbolizer symbol = new LineSymbolizer(Color.Blue, 2);

            lineLayer.Symbolizer = symbol;
            lineLayer.LegendText = "line";

            firstClick = true;

            linemouseClick = true;
        }
Example #13
0
        private static Layer GetLineLayer(dynamic layer)
        {
            MapLineLayer lineLayer = new MapLineLayer(FeatureSet.OpenFile(layer["Path"]));

            LegacyDeserializer.DeserializeLayer(layer, lineLayer);

            return(lineLayer);
        }
Example #14
0
 //removes the line layer when DeactivateLine is called
 private void removeLineLayer()
 {
     if (lineLayer == null)
     {
         return;
     }
     mainMap.Layers.Remove(lineLayer);
     lineLayer = null;
 }
Example #15
0
        public ucDrawLine(HMCon con, TUC_HMDevXManager.TUC_HMDevXManager hmDevMgr, WpfMapDrawBase map, MapLineLayer layer, int layerIndex)
            : base(con, hmDevMgr, map)
        {
            InitializeComponent();

            _layer            = layer;
            _layerIndex       = layerIndex;
            gcAttr.DataSource = _attrTable;

            InDrawingStatus(false);
        }
Example #16
0
        public override void Init(IGeoInfo geo, bool isCur, List <Envelope> shapeList, List <MapPoint> pointList)
        {
            GraphicsLayer.Graphics.Clear();

            _polyList = geo.ConvertTo <LineGeoInfo>().Polylines ?? new Dictionary <int, Polyline>();
            foreach (var poly in _polyList)
            {
                AddGraphic(poly.Value, CURR_GEO, $"{poly.Key}", MapLineLayer.GetSymbol(GeoMarkerType.Line, isCur ? GeoStatus.Normal : GeoStatus.Reference));
                shapeList.Add(poly.Value.Extent);
            }
        }
Example #17
0
        private void SetupResultsMapGroup(Core.Result.IResultSet set)
        {
            if (this.resultsGroup == null)
            {
                this.resultsGroup                  = new DotSpatial.Controls.MapGroup();
                this.resultsGroup.LegendText       = "Results";
                this.resultsGroup.SelectionEnabled = true;
                this.resultsGroup.IsVisible        = false;
                this.map.Layers.Add(this.resultsGroup);
            }

            if (set == null)
            {
                if (this.resultsLayer != null)
                {
                    this.resultsGroup.Layers.Remove(this.resultsLayer);
                    this.resultsLayer = null;
                }
                this.curResultsSet          = null;
                this.resultsGroup.IsVisible = false;
                return;
            }

            this.resultsGroup.IsVisible = true;
            if (this.resultsGroup.Layers.Count > 0)
            {
                this.resultsGroup.Layers.Clear();
            }

            this.curResultsSet = set;

            FeatureSet featureSet = new FeatureSet(FeatureType.Line);

            featureSet.Projection = this.map.Projection;
            featureSet.DataTable.Columns.Add(new DataColumn("LayerName", typeof(string)));

            foreach (var layer in this.curResultsSet.LayerNames)
            {
                var points = this.curResultsSet.GetDataset(layer);
                List <Coordinate> coords = new List <Coordinate>();
                for (int i = 0; i <= points.GetUpperBound(0); i++)
                {
                    coords.Add(new Coordinate(points[i, 0], points[i, 1]));
                }
                var feature = featureSet.AddFeature(new LineString(coords));
                feature.DataRow["LayerName"] = layer;
            }

            this.resultsLayer = new MapLineLayer(featureSet);
            this.resultsLayer.Symbology.EditorSettings.ExcludeExpression = "[LayerName] <> ''";

            this.resultsGroup.Layers.Add(this.resultsLayer);
        }
Example #18
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;
        }
Example #19
0
        private void cmdPath_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            if (fm.Ready)
            {
                String from = GetOD(cmbO.Text).ToString();
                String to   = GetOD(cmbD.Text).ToString();
                dijkstra = new Algorithm(fm.Graph);
                LinkedList <Edge> result = dijkstra.findPath(from, to);
                if (result.Count > 0)
                {
                    int         activeLyr = getLayerID(mMap, LinkLyr);
                    IFeatureSet FeLyr     = mMap.Layers[activeLyr].DataSet as IFeatureSet;
                    nLink = 0;
                    int nShp = FeLyr.DataTable.Rows.Count;

                    System.Drawing.Color col = Color.Red;
                    mMap.MapFrame.DrawingLayers.Clear();

                    //  Feature f = new Feature(axisLines);
                    FeatureSet fs = new FeatureSet(FeatureType.Line);
                    foreach (Edge edge in result)
                    {
                        string sID          = edge.Id.ToString();
                        int    spIndex      = Convert.ToInt32(edge.Id);
                        int    spatialIndex = Math.Abs(spIndex);
                        listBox1.Items.Add(spIndex);
                        IFeature f = FeLyr.GetFeature(spatialIndex);
                        fs.Features.Add(f);
                    }
                    MapLineLayer rangeRingAxis;
                    rangeRingAxis            = new MapLineLayer(fs);// MapPolygonLayer(fs);
                    rangeRingAxis.Symbolizer = new LineSymbolizer(col, 4);

                    mMap.MapFrame.DrawingLayers.Add(rangeRingAxis);

                    // Request a redraw
                    mMap.MapFrame.Invalidate();
                }
            }

            //---------------------------------------------------------------

            List <int> Links = new List <int>();

            for (int i = 0; i < Links.Count; i++)
            {
                //IFeature f = FeLyr.GetFeature(Links[i]);
                //fs.Features.Add(f);
            }
        }
Example #20
0
        public void ConvertLayerProperties_MapLineDataWithThemeAndMetaDataNameNotInFeatures_OnlyAddsDefaultCategory()
        {
            // Setup
            const string metadataAttribute = "Meta";
            var          random            = new Random(21);
            var          theme             = new MapTheme <LineCategoryTheme>("Other Meta", new[]
            {
                new LineCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion(),
                                      new LineStyle
                {
                    Color     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    Width     = random.Next(1, 48),
                    DashStyle = random.NextEnum <LineDashStyle>()
                })
            });

            var lineStyle = new LineStyle
            {
                Color     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                Width     = random.Next(1, 48),
                DashStyle = random.NextEnum <LineDashStyle>()
            };
            var mapLineData = new MapLineData("test", lineStyle, theme)
            {
                Features = new[]
                {
                    CreateMapFeatureWithMetaData(metadataAttribute)
                }
            };

            var mapLineLayer = new MapLineLayer();

            var converter = new MapLineDataConverter();

            // Call
            converter.ConvertLayerProperties(mapLineData, mapLineLayer);

            // Assert
            ILineSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(lineStyle);

            ILineScheme appliedScheme = mapLineLayer.Symbology;

            Assert.AreEqual(1, appliedScheme.Categories.Count);

            ILineCategory baseCategory = appliedScheme.Categories[0];

            AssertAreEqual(expectedSymbolizer, baseCategory.Symbolizer);
            Assert.IsNull(baseCategory.FilterExpression);
        }
Example #21
0
        public void ConvertLayerFeatures_MapLineDataWithMultipleGeometryFeature_ConvertsFeaturesToMapLineLayerAsMultiLineStringData()
        {
            // Setup
            var converter    = new MapLineDataConverter();
            var mapLineLayer = new MapLineLayer();
            var random       = new Random(21);
            var mapFeature   = new MapFeature(new[]
            {
                new MapGeometry(new[]
                {
                    new[]
                    {
                        new Point2D(random.NextDouble(), random.NextDouble()),
                        new Point2D(random.NextDouble(), random.NextDouble()),
                        new Point2D(random.NextDouble(), random.NextDouble())
                    }
                }),
                new MapGeometry(new[]
                {
                    new[]
                    {
                        new Point2D(random.NextDouble(), random.NextDouble()),
                        new Point2D(random.NextDouble(), random.NextDouble()),
                        new Point2D(random.NextDouble(), random.NextDouble())
                    }
                })
            });

            var mapLineData = new MapLineData("test data")
            {
                Features = new[]
                {
                    mapFeature
                }
            };

            // Call
            converter.ConvertLayerFeatures(mapLineData, mapLineLayer);

            // Assert
            IFeature feature = mapLineLayer.DataSet.Features[0];

            Assert.AreEqual(mapLineData.Features.Count(), mapLineLayer.DataSet.Features.Count);
            Assert.IsInstanceOf <MultiLineString>(feature.Geometry);

            IEnumerable <Coordinate> expectedCoordinates = mapFeature.MapGeometries.SelectMany(mg => mg.PointCollections.ElementAt(0).Select(p => new Coordinate(p.X, p.Y)));

            CollectionAssert.AreEqual(expectedCoordinates, feature.Geometry.Coordinates);
        }
Example #22
0
        public override bool FinishDraw(object input, ref Geometry output, ref string errMsg)
        {
            if (_drawPointList.Count <= 1)
            {
                errMsg = "A line need 2 or more points.";
                return(false);
            }

            DeleteGraphic(DRAFT);

            Polyline polyline = new Polyline(_drawPointList.ToArray(), SpatialReferences.Wgs84);
            int      polyId   = (_polyList.Count > 0) ? _polyList.Keys.Max() + 1 : 1;

            _polyList.Add(polyId, polyline);

            AddGraphic(polyline, CURR_GEO, $"{polyId}", MapLineLayer.GetSymbol(GeoMarkerType.Line, GeoStatus.Normal));

            output = new Multipoint(_drawPointList);
            return(true);
        }
Example #23
0
        public void MessageReceived(Core.Result.Events.ResultLayerSelected theEvent)
        {
            if (theEvent.ResultSet == null)
            {
                this.resultsGroup.Layers.Remove(this.resultsLayer);
                this.resultsLayer = null;
                return;
            }

            if (this.curResultsSet != theEvent.ResultSet)
            {
                SetupResultsMapGroup(theEvent.ResultSet);
            }

            if (this.resultsLayer == null)
            {
                return;
            }

            var layers = theEvent.SelectedLayers;

            IFeatureScheme scheme = this.resultsLayer.Symbology.Clone() as IFeatureScheme;

            this.resultsLayer.Symbology.SuspendEvents();
            scheme.ClearCategories();

            for (int i = 0; i < layers.Count; i++)
            {
                var    cat    = new LineCategory(this.colorList[i % this.colorList.Count], 1);
                string filter = "[LayerName] = '" + layers[i] + "'";
                cat.FilterExpression = filter;
                cat.LegendText       = layers[i];
                scheme.AddCategory(cat);
            }

            BeginInvoke(new MethodInvoker(delegate
            {
                this.resultsLayer.Symbology.CopyProperties(scheme);
                this.resultsLayer.Symbology.ResumeEvents();
            }));
        }
Example #24
0
        public void createPolyLineShape()
        {
            //initialize polyline feature set
            //map.Cursor = Cursors.Cross;
            lineF = new FeatureSet(FeatureType.Line);
            //set shape type
            shapeType = "Line";
            //set projection
            lineF.Projection = map.Projection;
            //initialize the featureSet attributr table
            DataColumn column = new DataColumn("ID");

            lineF.DataTable.Columns.Add(column);
            //add the featureSet as map layer
            lineLayer = (MapLineLayer)map.Layers.Add(lineF);
            LineSymbolizer symbol = new LineSymbolizer(Color.Black, 3);

            lineLayer.Symbolizer = symbol;
            lineLayer.LegendText = "My Line";
            firstClick           = true;
        }
Example #25
0
        public void ConvertLayerFeatures_MapLineDataWithMultipleFeatures_ConvertsAllFeaturesToMapLineLayer()
        {
            // Setup
            var converter    = new MapLineDataConverter();
            var mapLineLayer = new MapLineLayer();
            var mapLineData  = new MapLineData("test")
            {
                Features = new[]
                {
                    new MapFeature(Enumerable.Empty <MapGeometry>()),
                    new MapFeature(Enumerable.Empty <MapGeometry>()),
                    new MapFeature(Enumerable.Empty <MapGeometry>())
                }
            };

            // Call
            converter.ConvertLayerFeatures(mapLineData, mapLineLayer);

            // Assert
            Assert.AreEqual(mapLineData.Features.Count(), mapLineLayer.DataSet.Features.Count);
        }
Example #26
0
        public static IMapLayer GetMapLayer(string dataPath)
        {
            IMapLayer mapLayer = null;
            IDataSet  dataSet  = OpenFile(dataPath);

            if (dataSet != null)
            {
                if (dataSet is IFeatureSet featureSet)
                {
                    switch (featureSet.FeatureType)
                    {
                    case FeatureType.Point:
                    case FeatureType.MultiPoint:
                        mapLayer = new MapPointLayer(featureSet);
                        break;

                    case FeatureType.Line:
                        mapLayer = new MapLineLayer(featureSet);
                        break;

                    case FeatureType.Polygon:
                        mapLayer = new MapPolygonLayer(featureSet);
                        break;
                    }
                }
                else if (dataSet is IImageData imageSet)
                {
                    mapLayer = new MapImageLayer(imageSet);
                }
                else if (dataSet is IRaster raster)
                {
                    mapLayer = new MapRasterLayer(raster);
                }
                else if (dataSet is ISelfLoadSet selfLoadSet)
                {
                    mapLayer = selfLoadSet.GetLayer();
                }
            }
            return(mapLayer);
        }
Example #27
0
        private DotSpatial.Controls.IMapFeatureLayer GetMapLayerFromFeatureSet(IFeatureSet featureSet)
        {
            if (featureSet == null)
            {
                return(null);
            }

            IMapFeatureLayer layer = null;

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

            return(layer);
        }
Example #28
0
        public void ConvertLayerProperties_MapLineDataWithStyle_ConvertsStyleToMapLineLayer(
            [Values(KnownColor.AliceBlue, KnownColor.Azure)]
            KnownColor color,
            [Values(1, 5)] int width,
            [Values(LineDashStyle.Solid, LineDashStyle.Dash)]
            LineDashStyle lineStyle)
        {
            // Setup
            Color expectedColor = Color.FromKnownColor(color);
            var   converter     = new MapLineDataConverter();
            var   mapLineLayer  = new MapLineLayer();
            var   mapLineData   = new MapLineData("test", new LineStyle
            {
                Color     = expectedColor,
                Width     = width,
                DashStyle = lineStyle
            });

            // Call
            converter.ConvertLayerProperties(mapLineData, mapLineLayer);

            // Assert
            AssertAreEqual(new LineSymbolizer(expectedColor, expectedColor, width, MapDataHelper.Convert(lineStyle), LineCap.Round), mapLineLayer.Symbolizer);
        }
        public FeatureSet DrawLine()
        {
            FeatureSet lineF = new FeatureSet(FeatureType.Line);

            lineF.Projection = map.Projection;
            lineF.DataTable.Columns.Add("Value", typeof(double));//方便之后在等值线上标注
            MapLineLayer lineLayer = default(MapLineLayer);

            lineLayer = (MapLineLayer)map.Layers.Add(lineF);
            LineSymbolizer symnol = new LineSymbolizer(Color.Black, 2);

            lineLayer.Symbolizer = symnol;
            string[] thename = raster.Filename.Split('\\');
            lineLayer.LegendText = thename[thename.Length - 1] + "_line";
            //MapLabelLayer
            MapLabelLayer  labelLayer = new MapLabelLayer();
            ILabelCategory category   = labelLayer.Symbology.Categories[0];

            category.Expression = "[Value]";
            category.SelectionSymbolizer.BackColorEnabled = true;
            category.Symbolizer.BorderVisible             = false;
            category.Symbolizer.BackColor   = Color.FromArgb(128, Color.LightBlue);;
            category.Symbolizer.FontStyle   = FontStyle.Regular;
            category.Symbolizer.FontColor   = Color.Black;
            category.Symbolizer.FontSize    = 8.5f;
            category.Symbolizer.Orientation = ContentAlignment.MiddleCenter;
            category.Symbolizer.Alignment   = StringAlignment.Center;
            lineLayer.ShowLabels            = true;
            lineLayer.LabelLayer            = labelLayer;

            /*double min_X, min_Y, max_X, max_Y;
             * min_X = raster.Xllcenter - raster.CellWidth / 2;
             * min_Y = raster.Yllcenter - raster.CellHeight / 2;
             * max_X = raster.CellToProj(0, raster.NumColumns-1).X + raster.CellWidth / 2;
             * max_Y = raster.CellToProj(0, 0).Y + raster.CellHeight/2;
             * double interspace = (raster.CellToProj(1, 1).X - raster.CellToProj(0, 0).X) *
             *  (raster.CellToProj(1, 1).X - raster.CellToProj(0, 0).X) + (raster.CellToProj(1, 1).Y - raster.CellToProj(0, 0).Y) *
             *  (raster.CellToProj(1, 1).Y - raster.CellToProj(0, 0).Y);
             * Console.WriteLine("minX: " + min_X + " , minY: "+ min_Y + " , maxX: " + max_X + " , maxY: " + max_Y);*/
            List <Tin_Point> lpoints = new List <Tin_Point>();

            foreach (var lines in contourData)
            {
                //if(lines.Key == 18)
                //{
                //int i = 0;
                foreach (var line in lines.Value)
                {
                    Tin_Point p1 = new Tin_Point(line.startPoint.X, line.startPoint.Y, lines.Key);
                    Tin_Point p2 = new Tin_Point(line.endPoint.X, line.endPoint.Y, lines.Key);
                    //p1.Type = i;
                    //p2.Type = i;
                    lpoints.Add(p1);
                    lpoints.Add(p2);
                    List <Coordinate> lineArray    = new List <Coordinate>();
                    LineString        lineGeometry = new LineString(lineArray);
                    IFeature          lineFeature  = lineF.AddFeature(lineGeometry);
                    lineFeature.Coordinates.Add(line.startPoint);
                    lineFeature.Coordinates.Add(line.endPoint);
                    lineFeature.DataRow["Value"] = lines.Key;
                    lineF.InitializeVertices();
                    //i++;
                }
                //}
            }

            /*
             * Polish polish = new Polish();
             * List<List<Tin_Point>> new_tin_points = polish.ClassifyLine(lpoints);
             * Console.WriteLine("new_tin_point num: " + new_tin_points.Count);
             * foreach(var lines in new_tin_points)
             * {
             *  //int i = 0;
             *  foreach(var p in lines)
             *  {
             *      Console.Write(p.X + " , " + p.Y + "||");
             *  }
             *  Console.WriteLine("*********************************");
             * }
             * foreach (var lines in new_tin_points)
             * {
             *  //int i = 0;
             *
             *   Console.WriteLine(lines[0].X + " , " + lines[0].Y + "||" + lines[lines.Count-1].X + " , " + lines[lines.Count - 1].Y);
             * }
             *
             *
             * foreach (var freeline in new_tin_points)
             * {
             *  List<Coordinate> lineArray = new List<Coordinate>(); ;
             *  ILineString lineGeometry = new LineString(lineArray);
             *  IFeature lineFeature = lineF.AddFeature(lineGeometry);
             *  lineFeature.DataRow["Value"] = (int)freeline[0].Value;
             *  foreach (var p in freeline)
             *  {
             *      Coordinate coordinate = new Coordinate(p.X, p.Y);
             *      lineArray.Add(coordinate);
             *      lineFeature.Coordinates.Add(coordinate);
             *      lineF.InitializeVertices();
             *  }
             * }
             */
            map.ResetBuffer();
            return(lineF);
        }
Example #30
0
        /*public bool Execute(double start ,double space) {
         *  LineF.DataTable.Columns.Add("Value", typeof(double));
         *  MapLineLayer ml = (MapLineLayer)map.Layers.Add(LineF);
         *  /*MapLabelLayer labelLayer = new MapLabelLayer();
         *  ILabelCategory category = labelLayer.Symbology.Categories[0];
         *  category.Expression = "[Value]";
         *  category.SelectionSymbolizer.BackColorEnabled = true;
         *  category.Symbolizer.BorderVisible = false;
         *  category.Symbolizer.BackColor = Color.FromArgb(128, Color.LightBlue); ;
         *  category.Symbolizer.FontStyle = FontStyle.Regular;
         *  category.Symbolizer.FontColor = Color.Black;
         *  category.Symbolizer.FontSize = 8.5f;
         *  category.Symbolizer.Orientation = ContentAlignment.MiddleCenter;
         *  category.Symbolizer.Alignment = StringAlignment.Center;
         *  ml.ShowLabels = true;
         *  ml.LabelLayer = labelLayer;
         *  LineSymbolizer symbol = new LineSymbolizer(Color.Black, 2);
         *  ml.Symbolizer = symbol;
         *  ml.LegendText = "test_isoLine";
         *
         *  List<Tin_Point> tin_Points = new List<Tin_Point>();
         *  tin_Points.Add(new Tin_Point(572561.497857, 3078751.00159, 11.8, 1));
         *  tin_Points.Add(new Tin_Point(970365.002389, 3031211.249, 12.3, 2));
         *  tin_Points.Add(new Tin_Point(626125.750737, 2974587.498, 22, 3));
         *  tin_Points.Add(new Tin_Point(1011572.07339, 2913623.49696, 21, 4));
         *  tin_Points.Add(new Tin_Point(922526.062753, 2894449.74788, 19, 5));
         *  tin_Points.Add(new Tin_Point(491210.876499, 2860727.9972, 17.7, 6));
         *  tin_Points.Add(new Tin_Point(986676.942363, 2828322.24684, 16, 7));
         *  tin_Points.Add(new Tin_Point(628325.875511, 2828106.99668, 23, 8));
         *  tin_Points.Add(new Tin_Point(518668.440134, 2778797.99885, 22, 9));
         *  tin_Points.Add(new Tin_Point(878961.377011, 2777357.74535, 25, 10));
         *  tin_Points.Add(new Tin_Point(759651.063273, 2771206.25014, 13.6, 11));
         *  tin_Points.Add(new Tin_Point(460062.560062, 2705433.24783, 18, 12));//18
         *  tin_Points.Add(new Tin_Point(862951.066087, 2697174.99834, 24, 13));
         *  tin_Points.Add(new Tin_Point(408326.283205, 2666913.24635, 16, 14));
         *  tin_Points.Add(new Tin_Point(384889.188632, 2658932.49923, 23, 15));
         *  tin_Points.Add(new Tin_Point(610997.4361, 2641258.00046, 21, 16));
         *  tin_Points.Add(new Tin_Point(1042075.00856, 2595949.24905, 18, 17));
         *  tin_Points.Add(new Tin_Point(929238.438265, 2590020.00052, 19, 18));
         *  tin_Points.Add(new Tin_Point(708181.56137, 2524888.74999, 22.3, 19));
         *  tin_Points.Add(new Tin_Point(685935.251121, 2437299.24516, 18, 20));
         *  Delaunay delaunay = new Delaunay();
         *  List<Triangle> triangles = new List<Triangle>();
         *  triangles = delaunay.ConstructionDelaunay(tin_Points);
         *  Trace trace = new Trace();
         *  List<List<Tin_Point>> line_list = new List<List<Tin_Point>>();//多条等值线
         *  line_list = trace.MyTrace(triangles, tin_Points, space, start);
         *  PolishLine pl = new PolishLine(map, LineF, trace);
         *  Console.WriteLine("等值线的条数为:" + line_list.Count);
         *  foreach (var lines in line_list)
         *  {
         *      if (lines == null)
         *          break;
         *      //if(lines[0].Value)
         *      List<List<Tin_Point>> tp = null;
         *      if (lines[0].Value - (int)lines[0].Value > 0)//value为特殊值,后面有小数
         *      {
         *          tp = pl.ClassifyLine(lines, true);
         *      }
         *      else
         *      {
         *          tp = pl.ClassifyLine(lines, false);
         *      }
         *      foreach (var p in tp)
         *      {
         *          pl.SelectLine(p);
         *      }
         *  }
         *  map.ResetBuffer();
         *  return true;
         *  return true;
         * }*/
        public bool Execute(IFeatureSet input, String zField, double start, double space)
        {
            LineF.DataTable.Columns.Add("Value", typeof(double));
            MapLineLayer ml = (MapLineLayer)map.Layers.Add(LineF);

            /*
             * MapLabelLayer labelLayer = new MapLabelLayer();
             * ILabelCategory category = labelLayer.Symbology.Categories[0];
             * category.Expression = "[Value]";
             * category.SelectionSymbolizer.BackColorEnabled = true;
             * category.Symbolizer.BorderVisible = false;
             * category.Symbolizer.BackColor = Color.FromArgb(128, Color.LightBlue); ;
             * category.Symbolizer.FontStyle = FontStyle.Regular;
             * category.Symbolizer.FontColor = Color.Black;
             * category.Symbolizer.FontSize = 8.5f;
             * category.Symbolizer.Orientation = ContentAlignment.MiddleCenter;
             * category.Symbolizer.Alignment = StringAlignment.Center;
             * ml.ShowLabels = true;
             * ml.LabelLayer = labelLayer;
             * LineSymbolizer symbol = new LineSymbolizer(Color.Black, 2);
             * ml.Symbolizer = symbol;
             */
            string[] inputname = input.Filename.Split('\\');
            inputname     = inputname[inputname.Length - 1].Split('.');
            ml.LegendText = inputname[0] + "_isoLine";

            List <Tin_Point> tin_Points = new List <Tin_Point>();

            for (int i = 0; i < input.Features.Count; i++)
            {
                tin_Points.Add(new Tin_Point(input.Features[i].BasicGeometry.Coordinates[0].X, input.Features[i].BasicGeometry.Coordinates[0].Y, Convert.ToDouble(input.Features[i].DataRow[zField]), i));
            }
            Delaunay        delaunay  = new Delaunay();
            List <Triangle> triangles = new List <Triangle>();

            triangles = delaunay.ConstructionDelaunay(tin_Points);
            Trace trace = new Trace();
            List <List <Tin_Point> > line_list = new List <List <Tin_Point> >();//多条等值线

            line_list = trace.MyTrace(triangles, tin_Points, space, start);
            PolishLine pl = new PolishLine(map, LineF, trace);

            Console.WriteLine("等值线的条数为:" + line_list.Count);
            foreach (var lines in line_list)
            {
                if (lines == null)
                {
                    break;
                }
                //if(lines[0].Value)
                List <List <Tin_Point> > tp = null;
                if (lines[0].Value - (int)lines[0].Value > 0)//value为特殊值,后面有小数
                {
                    tp = pl.ClassifyLine(lines, true);
                }
                else
                {
                    tp = pl.ClassifyLine(lines, false);
                }
                foreach (var p in tp)
                {
                    pl.SelectLine(p);
                }
            }
            map.ResetBuffer();
            return(true);
        }