public static Esri.ArcGISRuntime.Geometry.Geometry ChangeSpatailReference( Esri.ArcGISRuntime.Geometry.Geometry geom, SpatialReference sr) { if (geom.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Point) { MapPoint p = geom as MapPoint; return(ChangeSpatailReference(p, sr)); } else if (geom.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Multipoint) { Multipoint mp = geom as Multipoint; IEnumerable <MapPoint> newMP = ChangeSpatialReference(mp.Points, sr); return(new Multipoint(newMP, sr)); } else if (geom.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Polyline) { Esri.ArcGISRuntime.Geometry.Polyline pl = geom as Esri.ArcGISRuntime.Geometry.Polyline; PartCollection newPart = ChangeSpatialReference(pl.Parts, sr); return(new Esri.ArcGISRuntime.Geometry.Polyline(newPart, sr)); } else if (geom.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Polygon) { Esri.ArcGISRuntime.Geometry.Polygon pg = geom as Esri.ArcGISRuntime.Geometry.Polygon; PartCollection newPart = ChangeSpatialReference(pg.Parts, sr); return(new Esri.ArcGISRuntime.Geometry.Polygon(newPart, sr)); } else if (geom.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Envelope) { Envelope ev = geom as Envelope; return(new Envelope(ev.XMin, ev.YMin, ev.XMax, ev.YMax, sr)); } return(null); }
private Graphic coordinatesystem_polygon(Graphic graphic) { Graphic polylgonGraphic = null; var poly = graphic.Geometry as Esri.ArcGISRuntime.Geometry.Polygon; this.polygonbuild = new PolygonBuilder(poly); foreach (var re in polygonbuild.Parts) { IReadOnlyList <MapPoint> mapPoints = re.Points; var polypoints = Mapcoordinates_Aftertransform(mapPoints); var polygon = new Esri.ArcGISRuntime.Geometry.Polygon(polypoints); //Create symbol for polyline var polylineSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, System.Drawing.Color.Transparent, new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.FromArgb(0, 0, 255), 2)); //Create a polyline graphic with geometry and symbol polylgonGraphic = new Graphic(polygon, polylineSymbol); //Add polygone to graphics overlay _sketchOverlay.Graphics.Add(polylgonGraphic); Esri.ArcGISRuntime.Geometry.Geometry gr = polygon; } return(polylgonGraphic); }
public static MapPoint Center(Esri.ArcGISRuntime.Geometry.Polygon polygon) { IEnumerable <MapPoint> pc = polygon.Parts[0].GetPoints(); double x = 0; double y = 0; // The polygon's first point is coincide with the last point //for (int i = 0; i < pc.Count - 1; ++i) //{ // MapPoint p = pc[i]; // x += p.X; // y += p.Y; //} //x /= (pc.Count - 1); //y /= (pc.Count - 1); foreach (MapPoint p in pc) { x += p.X; y += p.Y; } x /= pc.Count(); y /= pc.Count(); MapPoint center = new MapPoint(x, y); return(center); }
/// <summary> /// Calculates the scale at the center of a polygon, at a given pixel size /// </summary> /// <remarks> /// A pixel is a device independent logical pixel - ie 1/96 inches. /// </remarks> /// <param name="visibleArea">The area which center the scale will be calculated for.</param> /// <param name="unitsPerPixel">The size of a device indepedent pixel in the units of the spatial reference</param> /// <returns>The MapScale for the center of the view</returns> public static double CalculateScale(Esri.ArcGISRuntime.Geometry.Polygon visibleArea, double unitsPerPixel) { if (visibleArea == null) { return(double.NaN); } if (visibleArea.SpatialReference == null) { return(double.NaN); } if (double.IsNaN(unitsPerPixel) || unitsPerPixel <= 0) { return(double.NaN); } #if __ANDROID__ // Need to convert the value to DIPs unitsPerPixel /= Android.Util.TypedValue.ApplyDimension(Android.Util.ComplexUnitType.Dip, 1, Internal.ViewExtensions.GetDisplayMetrics()); #endif var center = visibleArea.Extent.GetCenter(); var centerOnePixelOver = new Geometry.MapPoint(center.X + unitsPerPixel, center.Y, center.SpatialReference); // Calculate the geodedetic distance between two points one 'pixel' apart var result = Geometry.GeometryEngine.DistanceGeodetic(center, centerOnePixelOver, Geometry.LinearUnits.Inches, Geometry.AngularUnits.Degrees, Geometry.GeodeticCurveType.Geodesic); double distanceInInches = result.Distance; return(distanceInInches * 96); }
private void MyMapViewOnGeoViewTapped_Area(object sender, GeoViewInputEventArgs geoViewInputEventArgs) { // Get the tapped point, projected to WGS84. MapPoint destination = (MapPoint)GeometryEngine.Project(geoViewInputEventArgs.Location, SpatialReferences.Wgs84); // 点集(mapPoints) ——记得清空 mapPoints.Add(destination); int len = mapPoints.Count(); Esri.ArcGISRuntime.Geometry.PointCollection polygonPoints; Esri.ArcGISRuntime.Geometry.Geometry areaGeometry; Esri.ArcGISRuntime.Geometry.Polygon routeArea; if (len > 2) { polygonPoints = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84) { mapPoints[len - 3], mapPoints[len - 2], destination }; routeArea = new Esri.ArcGISRuntime.Geometry.Polygon(polygonPoints); //pathGeometry = GeometryEngine.DensifyGeodetic(routeArea, 1, LinearUnits.Kilometers, GeodeticCurveType.Geodesic); // 这是测地线的长度 //double distance = GeometryEngine.LengthGeodetic(pathGeometry, LinearUnits.Kilometers, GeodeticCurveType.Geodesic); double area = GeometryEngine.Area(routeArea); if (areaList.Count() != 0) { area += areaList[areaList.Count() - 1]; } areaList.Add(area); myMeasureResult.Text += "\n" + area + " (地图默认面积单位)"; } }
/// <summary> /// Calculates the scale at the center of a polygon, at a given pixel size /// </summary> /// <remarks> /// A pixel is a device independent logical pixel - ie 1/96 inches. /// </remarks> /// <param name="visibleArea">The area which center the scale will be calculated for.</param> /// <param name="unitsPerPixel">The size of a device indepedent pixel in the units of the spatial reference</param> /// <returns>The MapScale for the center of the view</returns> public static double CalculateScale(Esri.ArcGISRuntime.Geometry.Polygon visibleArea, double unitsPerPixel) { if (visibleArea == null) { return(double.NaN); } if (visibleArea.SpatialReference == null) { return(double.NaN); } if (double.IsNaN(unitsPerPixel) || unitsPerPixel <= 0) { return(double.NaN); } var center = visibleArea.Extent.GetCenter(); var centerOnePixelOver = new Geometry.MapPoint(center.X + unitsPerPixel, center.Y, center.SpatialReference); // Calculate the geodedetic distance between two points one 'pixel' apart var result = Geometry.GeometryEngine.DistanceGeodetic(center, centerOnePixelOver, Geometry.LinearUnits.Inches, Geometry.AngularUnits.Degrees, Geometry.GeodeticCurveType.Geodesic); double distanceInInches = result.Distance; return(distanceInInches * 96); }
// 鹰眼 private void myMapView_ViewpointChanged(object sender, EventArgs e) { // 声明鹰眼地图的覆盖层边框 Esri.ArcGISRuntime.Geometry.Geometry eagleViewEnv = null; // 每次主地图的焦点改变, 都会清空鹰眼地图的覆盖层 myMapView_Eagle.GraphicsOverlays.Clear(); // 获取主地图的四至 Esri.ArcGISRuntime.Geometry.Polygon vExtent = myMapView.VisibleArea; // 鹰眼地图的覆盖层边框等于主地图四至 eagleViewEnv = vExtent.Extent; // 鹰眼地图的覆盖层边框为"红色" System.Drawing.Color lineColor = System.Drawing.Color.FromName("Red"); // 鹰眼地图的覆盖层边框样式 Esri.ArcGISRuntime.Symbology.SimpleLineSymbol lineSymbol = new Esri.ArcGISRuntime.Symbology.SimpleLineSymbol(Esri.ArcGISRuntime.Symbology.SimpleLineSymbolStyle.Dash, lineColor, 2.0); System.Drawing.Color fillColor = System.Drawing.Color.FromArgb(0, 255, 255, 255); Esri.ArcGISRuntime.Symbology.SimpleFillSymbol polySymbol = new Esri.ArcGISRuntime.Symbology.SimpleFillSymbol(Esri.ArcGISRuntime.Symbology.SimpleFillSymbolStyle.Solid, fillColor, lineSymbol); var graphicOverlay = new Esri.ArcGISRuntime.UI.GraphicsOverlay(); // 几何图层 var envGraphic = new Esri.ArcGISRuntime.UI.Graphic(eagleViewEnv, polySymbol); // 覆盖层 graphicOverlay.Graphics.Add(envGraphic); // 覆盖层添加到鹰眼地图 myMapView_Eagle.GraphicsOverlays.Add(graphicOverlay); }
public static Graphic NewPolygon(Esri.ArcGISRuntime.Geometry.PointCollection pc) { Esri.ArcGISRuntime.Geometry.Polygon polygon = new Esri.ArcGISRuntime.Geometry.Polygon(pc); Graphic g = new Graphic(); g.Geometry = polygon; return(g); }
// 编辑绘制图层 private void EditVertexMenuItem_Click(object sender, RoutedEventArgs e) { if (curSelGraphic != null)//检查当前是否有选择图形 { operation = OperateType.EditVertex; if (curSelGraphic.Geometry.GeometryType == GeometryType.Point) //所选图形为点 { selVertexLayer.Graphics.Clear(); //清空顶点图层 MapPoint pt = (MapPoint)curSelGraphic.Geometry; Graphic pg = new Graphic(pt, vertexSymbol); //创建新的点图形 selVertexLayer.Graphics.Add(pg); } else if (curSelGraphic.Geometry.GeometryType == GeometryType.Polyline)//所选图形为线 { if (pointCollection != null) { pointCollection.Clear();//清空点集 } else { pointCollection = new Esri.ArcGISRuntime.Geometry.PointCollection(myMapView.Map.SpatialReference); } Esri.ArcGISRuntime.Geometry.Polyline ln = (Esri.ArcGISRuntime.Geometry.Polyline)curSelGraphic.Geometry; pointCollection.AddPoints(ln.Parts[0].Points); //将线的所有顶点加入点集 selVertexLayer.Graphics.Clear(); for (int i = 0; i < pointCollection.Count; i++) //将所有点以顶点图形样式显示 { MapPoint pt = pointCollection[i]; Graphic pg = new Graphic(pt, vertexSymbol); selVertexLayer.Graphics.Add(pg); } } else if (curSelGraphic.Geometry.GeometryType == GeometryType.Polygon)//所选图形为多边形 { if (pointCollection != null) { pointCollection.Clear(); } else { pointCollection = new Esri.ArcGISRuntime.Geometry.PointCollection(myMapView.Map.SpatialReference); } Esri.ArcGISRuntime.Geometry.Polygon pg = (Esri.ArcGISRuntime.Geometry.Polygon)curSelGraphic.Geometry; pointCollection.AddPoints(pg.Parts[0].Points); selVertexLayer.Graphics.Clear(); for (int i = 0; i < pointCollection.Count; i++) { MapPoint pt = pointCollection[i]; Graphic gg = new Graphic(pt, vertexSymbol); selVertexLayer.Graphics.Add(gg); } } EditVertexMenuItem.IsEnabled = false; UneditVertexMenuItem.IsEnabled = true; } }
private void addPolygon() { ObservableCollection <MapPoint> cc = new ObservableCollection <MapPoint>(); cc.Add(new MapPoint(-122.411033517241, 37.7928248779988, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.409439828211, 37.7929574531202, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407879728918, 37.7928979616957, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407366343129, 37.7929400050513, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.40620355885, 37.7928932150506, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.405970239004, 37.7919861537598, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.405851348679, 37.7915014272396, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.406282194305, 37.7914529231787, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.406947985248, 37.7913177148322, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407388139234, 37.7912593889064, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.408391496303, 37.7911085191116, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.409274453043, 37.791057174337, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.410233608604, 37.7910235416472, SpatialReferences.Wgs84)); SimpleFillSymbol sfs = new SimpleFillSymbol(); Esri.ArcGISRuntime.Geometry.Polygon polygon = new Esri.ArcGISRuntime.Geometry.Polygon(cc, SpatialReferences.Wgs84); sfs.Style = SimpleFillStyle.Solid; sfs.Color = Color.FromArgb(125, 255, 0, 0); sfs.Outline = new SimpleLineSymbol() { Color = Colors.Red, Width = 2 }; Graphic graphic = new Graphic(polygon, sfs); graphic.Attributes.Add("A", 76); graphic.Attributes.Add("B", 100); MyGraphicsLayer.Graphics.Add(graphic); }
public static Graphic NewPolygon(Esri.ArcGISRuntime.Geometry.PointCollection pc) { Esri.ArcGISRuntime.Geometry.Polygon polygon = new Esri.ArcGISRuntime.Geometry.Polygon(pc); Graphic g = new Graphic(); g.Geometry = polygon; return g; }
private void MyMapView_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { myMapView.Cursor = Cursors.Arrow;//恢复光标样式 if (curSelGraphic == null || orgPoint == null) { return; //计算位移 } IInputElement ie = (IInputElement)(sender); MapPoint loc = myMapView.ScreenToLocation(e.GetPosition(ie)); double deltaX = loc.X - orgPoint.X; double deltaY = loc.Y - orgPoint.Y; if (operation == OperateType.None) //非绘制状态或顶点编辑状态 { if (curSelGraphic.Geometry.GeometryType == GeometryType.Point) //当前选择的图形 为点,重新构造点 { MapPointBuilder pb = new MapPointBuilder(loc); curSelGraphic.Geometry = pb.ToGeometry(); } else if (curSelGraphic.Geometry.GeometryType == GeometryType.Polyline)//当前选 择的图形为线,重新计算所有点 { Esri.ArcGISRuntime.Geometry.Polyline ln = (Esri.ArcGISRuntime.Geometry.Polyline)curSelGraphic.Geometry; pointCollection.Clear(); for (int i = 0; i < ln.Parts[0].Points.Count; i++) { double X = ln.Parts[0].Points[i].X + deltaX; double Y = ln.Parts[0].Points[i].Y + deltaY; MapPoint Pt = new MapPoint(X, Y); pointCollection.Add(Pt); } PolylineBuilder lb = new PolylineBuilder(pointCollection); curSelGraphic.Geometry = lb.ToGeometry(); } else if (curSelGraphic.Geometry.GeometryType == GeometryType.Polygon)//当前选 择图形为多边形,重新计算所有点 { Esri.ArcGISRuntime.Geometry.Polygon poly = (Esri.ArcGISRuntime.Geometry.Polygon)curSelGraphic.Geometry; pointCollection.Clear(); for (int i = 0; i < poly.Parts[0].Points.Count; i++) { double X = poly.Parts[0].Points[i].X + deltaX; double Y = poly.Parts[0].Points[i].Y + deltaY; MapPoint Pt = new MapPoint(X, Y); pointCollection.Add(Pt); } PolygonBuilder pb = new PolygonBuilder(pointCollection); curSelGraphic.Geometry = pb.ToGeometry(); } } else if (operation == OperateType.EditVertex)//处于顶点编辑状态 { if (selGracphicIndex >= 0) { Graphic g = graphicsLayer.Graphics.ElementAt(selGracphicIndex); //找到所选 图形 if (g.Geometry.GeometryType == GeometryType.Point) //图形为点 { MapPointBuilder mpb = new MapPointBuilder(loc); g.Geometry = mpb.ToGeometry(); } else if (g.Geometry.GeometryType == GeometryType.Polyline && selPointIndex >= 0)//图形为线,顶点已捕捉 { Esri.ArcGISRuntime.Geometry.Polyline pln = (Esri.ArcGISRuntime.Geometry.Polyline)g.Geometry; pointCollection.Clear(); pointCollection.AddPoints(pln.Parts[0].Points); pointCollection.SetPoint(selPointIndex, loc.X, loc.Y); PolylineBuilder plb = new PolylineBuilder(pointCollection); g.Geometry = plb.ToGeometry(); } else if (g.Geometry.GeometryType == GeometryType.Polygon && selPointIndex >= 0)//图形为多边形,顶点已捕捉 { Esri.ArcGISRuntime.Geometry.Polygon plg = (Esri.ArcGISRuntime.Geometry.Polygon)g.Geometry; pointCollection.Clear(); pointCollection.AddPoints(plg.Parts[0].Points); pointCollection.SetPoint(selPointIndex, loc.X, loc.Y); PolygonBuilder pgb = new PolygonBuilder(pointCollection); g.Geometry = pgb.ToGeometry(); } if (selPointIndex >= 0) {//移动相应的顶点到当前位置 Graphic vtGraphic = selVertexLayer.Graphics.ElementAt(selPointIndex); MapPointBuilder tgPoint = new MapPointBuilder(loc); vtGraphic.Geometry = tgPoint.ToGeometry(); } } } }
private void addPolygon() { ObservableCollection<MapPoint> cc = new ObservableCollection<MapPoint>(); cc.Add(new MapPoint(-122.411033517241, 37.7928248779988, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.409439828211, 37.7929574531202, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407879728918, 37.7928979616957, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407366343129, 37.7929400050513, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.40620355885, 37.7928932150506, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.405970239004, 37.7919861537598, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.405851348679, 37.7915014272396, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.406282194305, 37.7914529231787, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.406947985248, 37.7913177148322, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407388139234, 37.7912593889064, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.408391496303, 37.7911085191116, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.409274453043, 37.791057174337, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.410233608604, 37.7910235416472, SpatialReferences.Wgs84)); SimpleFillSymbol sfs = new SimpleFillSymbol(); Esri.ArcGISRuntime.Geometry.Polygon polygon = new Esri.ArcGISRuntime.Geometry.Polygon(cc, SpatialReferences.Wgs84); sfs.Style = SimpleFillStyle.Solid; sfs.Color = Color.FromArgb(125, 255, 0, 0); sfs.Outline = new SimpleLineSymbol() { Color = Colors.Red, Width = 2 }; Graphic graphic = new Graphic(polygon, sfs); graphic.Attributes.Add("A", 76); graphic.Attributes.Add("B", 100); MyGraphicsLayer.Graphics.Add(graphic); }
//=======敏感区===== public void Createarea(double lon, double lat, double radius) { // Create the graphics overlay. GraphicsOverlay overlay1 = new GraphicsOverlay(); GraphicsOverlay overlay2 = new GraphicsOverlay(); // Create a green simple line symbol SimpleLineSymbol outlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, System.Drawing.Color.FromArgb(0xFF, 0x00, 0x50, 0x00), 1); // Create a green mesh simple fill symbol SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Cross, System.Drawing.Color.Yellow, outlineSymbol); Esri.ArcGISRuntime.Geometry.PointCollection boatPositions = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84); for (int i = 0; i < 36; i++) { double angle = (2 * Math.PI / 36) * i; // new MapPoint([lon + Math.sin(angle) * radius[0], lat[0] + Math.cos(angle) * radius[0]]); boatPositions.Add(new MapPoint(lon + Math.Sin(angle) * radius, lat + Math.Cos(angle) * radius)); } ; // Create the polyline from the point collection Esri.ArcGISRuntime.Geometry.Polygon polygon = new Esri.ArcGISRuntime.Geometry.Polygon(boatPositions); // Create the graphic with polyline and symbol Graphic graphic = new Graphic(polygon, fillSymbol); Graphic graphic1 = new Graphic(polygon, fillSymbol); // Add graphic to the graphics overlay overlay1.Graphics.Add(graphic); overlay2.Graphics.Add(graphic1); //MessageBox.Show(lon + " "+ lat + "添加成功"); // Show the graphics overlay in the scene. MyMapView.GraphicsOverlays.Add(overlay1); MySceneView.GraphicsOverlays.Add(overlay2); int de = -1; int mi = -1; if (Dector2D.Count > 0) { int count = Dector2D.Count; for (int i = 0; i < count; i++) { List <MapPoint> _artificialMapPoints = new List <MapPoint>(); _artificialMapPoints = MapPointslist[i]; int index = Global.DectorIndexIdlist[i]; for (int j = index; j < index + 120; j++) { MapPoint selectedMapPoint = _artificialMapPoints[j % _artificialMapPoints.Count]; double di = Distance(selectedMapPoint.X, selectedMapPoint.Y, selectedMapPoint.Z, lon, lat, 0); if (di < radius * 100000) { de = i; mi = j - index; break; } } // } if (mi != -1) { break; } } //double d = Distance(lon, lat, 0, lon1, lat1, radius1); StackPanel s = new StackPanel(); Label l1 = new Label(); Label l2 = new Label(); Label l3 = new Label(); s.Children.Add(l1); s.Children.Add(l2); s.Children.Add(l3); l1.Content = "longitude :" + lon; l2.Content = "latitude : " + lat; if (de != -1) { l3.Content = "探空仪 " + Global.DectorNamelist[de] + " 将在" + mi + "分钟后到达敏感区"; } else { /* * * string[] strArr = new string[3]; * string sArguments = @"station.py"; //调用的python的文件名字 * strArr[0] = lon.ToString(); * strArr[1] = lat.ToString(); * strArr[2] = (radius*111).ToString(); * RunPythonScript(sArguments, "-u", strArr); */ //int counter = 0; //string line; string result = "Please wait"; string[] lines = System.IO.File.ReadAllLines(@"E:\\VSProjects\\test\\data.txt", Encoding.GetEncoding("gb2312")); //System.Console.WriteLine("Contents of WriteLines2.txt = "); foreach (string line in lines) { result = line; } // System.IO.StreamReader file = new System.IO.StreamReader(@"E:\\VSProjects\\test\\data.txt"); // while ((line = file.ReadLine()) != null) //{ //System.Console.WriteLine(line); // counter++; // } /// MessageBox.Show( result); // file.Close(); l3.Content = result; } MyMapView.ShowCalloutAt(new MapPoint(lon, lat, SpatialReferences.Wgs84), s); } else { //double d = Distance(lon, lat, 0, lon1, lat1, radius1); StackPanel s = new StackPanel(); Label l1 = new Label(); Label l2 = new Label(); Label l3 = new Label(); s.Children.Add(l1); s.Children.Add(l2); s.Children.Add(l3); l1.Content = "longitude :" + lon; l2.Content = "latitude : " + lat; // l3.Content = ""; /* * string[] strArr = new string[3]; * string sArguments = @"station.py"; //调用的python的文件名字 * strArr[0] = lon.ToString(); * strArr[1] = lat.ToString(); * strArr[2] = (radius * 111).ToString(); * RunPythonScript(sArguments, "-u", strArr); */ string result = "Please wait"; string[] lines = System.IO.File.ReadAllLines(@"E:\\VSProjects\\test\\data.txt", Encoding.GetEncoding("gb2312")); //System.Console.WriteLine("Contents of WriteLines2.txt = "); foreach (string line in lines) { result = line; } // System.IO.StreamReader file = new System.IO.StreamReader(@"E:\\VSProjects\\test\\data.txt"); // while ((line = file.ReadLine()) != null) //{ //System.Console.WriteLine(line); // counter++; // } // MessageBox.Show("c" + result); // file.Close(); l3.Content = "可选放球站:" + result; // string text = System.IO.File.ReadAllText(@"E:\\VSProjects\\test\\data.txt"); MyMapView.ShowCalloutAt(new MapPoint(lon, lat, SpatialReferences.Wgs84), s); } // MyMapView.ShowCalloutAt(new MapPoint(lon, lat, SpatialReferences.Wgs84), s); }
private void CreateGraphic_Label(Esri.ArcGISRuntime.Geometry.PointCollection _pointc, string key, string encName) { var Polygon = new Esri.ArcGISRuntime.Geometry.Polygon(_pointc); // Define the symbology of the polygon var polygonSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, System.Drawing.Color.FromArgb(20, 60, 62, 66), new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.FromArgb(46, 50, 54), 0.5)); // a point to define where the text is drawn var labelbase1 = (Polygon.Extent); //text symbol which defines text size, the text and color TextSymbol textsym1 = new TextSymbol(key, System.Drawing.Color.FromArgb(255, 255, 255), 12, Esri.ArcGISRuntime.Symbology.HorizontalAlignment.Center, Esri.ArcGISRuntime.Symbology.VerticalAlignment.Middle); textsym1.FontWeight = 0; ////create a graphic from the point and symbol Graphic _labelGraphic = new Graphic(labelbase1, textsym1); //Graphic _labelGraphic = new Graphic(labelbase1, textsym1); //polygonlabeloverlay.Graphics.Add(_labelGraphic); graphattribute = new Dictionary <string, object>(); graphattribute.Add(key, encName); // graphattribute.Add(t1, two); _polygonGraphic = new Graphic(Polygon, graphattribute, polygonSymbol); if (encName == "1") { // MyMapView.Map.OperationalLayers.Add(generalfeature); overviewoverlay.Graphics.Add(_polygonGraphic); overviewoverlay.Graphics.Add(_labelGraphic); graphic_collection = overviewoverlay.Graphics; // overviewlabeloverlay.Graphics.Add(_labelGraphic); } else if (encName == "2") { generaloverlay.Graphics.Add(_polygonGraphic); generaloverlay.Graphics.Add(_labelGraphic); graphic_collection = generaloverlay.Graphics; //generallabeloverlay.Graphics.Add(_labelGraphic); } else if (encName == "3") { coastaloverlay.Graphics.Add(_polygonGraphic); coastaloverlay.Graphics.Add(_labelGraphic); graphic_collection = coastaloverlay.Graphics; //coastallabeloverlay.Graphics.Add(_labelGraphic); } else if (encName == "4") { approachoverlay.Graphics.Add(_polygonGraphic); approachoverlay.Graphics.Add(_labelGraphic); graphic_collection = approachoverlay.Graphics; //approachlabeloverlay.Graphics.Add(_labelGraphic); } else if (encName == "5") { harbouroverlay.Graphics.Add(_polygonGraphic); harbouroverlay.Graphics.Add(_labelGraphic); graphic_collection = harbouroverlay.Graphics; //harbourlabeloverlay.Graphics.Add(_labelGraphic); } else if (encName == "6") { berthingoverlay.Graphics.Add(_polygonGraphic); berthingoverlay.Graphics.Add(_labelGraphic); graphic_collection = berthingoverlay.Graphics; // berthinglabeloverlay.Graphics.Add(_labelGraphic); } }
// myMapView 事件 private async void MyMapView_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { IInputElement ie = (IInputElement)(sender); MapPoint loc = myMapView.ScreenToLocation(e.GetPosition(ie)); switch (operation) { case OperateType.DrawPoint: //画点 Graphic pt = new Graphic(loc, pointSymbol); graphicsLayer.Graphics.Add(pt); break; case OperateType.DrawPolyline: //画线 pointCollection.Add(loc); if (pointCollection.Count >= 2) { if (pointCollection.Count > 2) { Graphic g = graphicsLayer.Graphics[graphicsLayer.Graphics.Count - 1]; PolylineBuilder lb = new PolylineBuilder(pointCollection); g.Geometry = lb.ToGeometry(); } else { Esri.ArcGISRuntime.Geometry.Polyline l = new Esri.ArcGISRuntime.Geometry.Polyline(pointCollection); Graphic lg = new Graphic(l, lineSymbol); graphicsLayer.Graphics.Add(lg); } } break; case OperateType.DrawPolygon: //画多边形 pointCollection.Add(loc); if (pointCollection.Count >= 3) { if (pointCollection.Count > 3) { Graphic g = graphicsLayer.Graphics[graphicsLayer.Graphics.Count - 1]; PolygonBuilder pb = new PolygonBuilder(pointCollection); g.Geometry = pb.ToGeometry(); } else { Esri.ArcGISRuntime.Geometry.Polygon p = new Esri.ArcGISRuntime.Geometry.Polygon(pointCollection); Graphic pg = new Graphic(p, fillSymbol); graphicsLayer.Graphics.Add(pg); } } break; case OperateType.None: //缺省状态 graphicsLayer.ClearSelection(); IdentifyGraphicsOverlayResult result = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false); //选择图形元素 if (result.Graphics.Count < 1) { curSelGraphic = null; EditVertexMenuItem.IsEnabled = false; UneditVertexMenuItem.IsEnabled = false; return; } curSelGraphic = result.Graphics.First(); curSelGraphic.IsSelected = true; EditVertexMenuItem.IsEnabled = true; break; case OperateType.Cal_Clip: //选择图形 IdentifyGraphicsOverlayResult gResult = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false); if (gResult.Graphics.Count < 1) { return; } Graphic selGraphic = gResult.Graphics.First(); selGraphic.IsSelected = true; listOfClipGraphics.Add(selGraphic); //记录所选图形 if (listOfClipGraphics.Count == 2) //图形数目为2时,进行剪切计算 { Graphic g1 = listOfClipGraphics[0]; Graphic g2 = listOfClipGraphics[1]; if (g1.Geometry.GeometryType != GeometryType.Polygon || g2.Geometry.GeometryType != GeometryType.Polygon) //如果所选图形不是多边形,则退出 { MessageBox.Show("请选择两个多边形图形!"); listOfClipGraphics.Clear(); graphicsLayer.ClearSelection(); return; } Esri.ArcGISRuntime.Geometry.Geometry resultGeometry = GeometryEngine.Clip(g1.Geometry, g2.Geometry.Extent); //执行剪切操作 if (resultGeometry != null) //处理结果 { graphicsLayer.Graphics.Remove(g1); //从图形层中移除原图形 graphicsLayer.Graphics.Remove(g2); Graphic clipedGraphic = new Graphic(resultGeometry, fillSymbol); //利 用剪切结果构建新的图形 graphicsLayer.Graphics.Add(clipedGraphic); operation = OperateType.None; } listOfClipGraphics.Clear(); //清空图形选择集合 graphicsLayer.ClearSelection(); //清空图形层所选 } break; case OperateType.Cal_Union: // 联合 IdentifyGraphicsOverlayResult gResultUnion = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false); if (gResultUnion.Graphics.Count < 1) { return; } Graphic selGraphicUnion = gResultUnion.Graphics.First(); selGraphicUnion.IsSelected = true; listOfClipGraphics.Add(selGraphicUnion); //记录所选图形 if (listOfClipGraphics.Count == 2) //图形数目为2时,进行剪切计算 { Graphic g1 = listOfClipGraphics[0]; Graphic g2 = listOfClipGraphics[1]; if (g1.Geometry.GeometryType != GeometryType.Polygon || g2.Geometry.GeometryType != GeometryType.Polygon) //如果所选图形不是多边形,则退出 { MessageBox.Show("请选择两个多边形图形!"); listOfClipGraphics.Clear(); graphicsLayer.ClearSelection(); return; } Esri.ArcGISRuntime.Geometry.Geometry resultGeometry = GeometryEngine.Union(g1.Geometry, g2.Geometry.Extent); //执行剪切操作 if (resultGeometry != null) //处理结果 { graphicsLayer.Graphics.Remove(g1); //从图形层中移除原图形 graphicsLayer.Graphics.Remove(g2); Graphic clipedGraphic = new Graphic(resultGeometry, fillSymbol); //利 用剪切结果构建新的图形 graphicsLayer.Graphics.Add(clipedGraphic); operation = OperateType.None; } listOfClipGraphics.Clear(); //清空图形选择集合 graphicsLayer.ClearSelection(); //清空图形层所选 } break; case OperateType.Cal_Cut: // 剪切 IdentifyGraphicsOverlayResult gResult_Cut = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false); if (gResult_Cut.Graphics.Count < 1) { return; } Graphic selGraphic_Cut = gResult_Cut.Graphics.First(); selGraphic_Cut.IsSelected = true; listOfClipGraphics.Add(selGraphic_Cut); //记录所选图形 if (listOfClipGraphics.Count == 2) //图形数目为1时,进行剪切计算 { Graphic g1 = listOfClipGraphics[0]; Graphic g2 = listOfClipGraphics[1]; if (g1.Geometry.GeometryType != GeometryType.Polygon || g2.Geometry.GeometryType != GeometryType.Polyline) //如果所选图形不是多边形,则退出 { MessageBox.Show("请先选择一个面要素后再选择一个线要素."); listOfClipGraphics.Clear(); graphicsLayer.ClearSelection(); return; } Esri.ArcGISRuntime.Geometry.Polyline polyLine = (Esri.ArcGISRuntime.Geometry.Polyline)g2.Geometry; Esri.ArcGISRuntime.Geometry.Geometry[] resultGeometry = GeometryEngine.Cut(g1.Geometry, polyLine); //执行剪切操作 if (resultGeometry != null) //处理结果 { graphicsLayer.Graphics.Remove(g1); for (int z = 0; z < resultGeometry.Length; z++) { Graphic clipedGraphic = new Graphic(resultGeometry[z], fillSymbol); //利 用剪切结果构建新的图形 graphicsLayer.Graphics.Add(clipedGraphic); } operation = OperateType.None; } listOfClipGraphics.Clear(); //清空图形选择集合 graphicsLayer.ClearSelection(); //清空图形层所选 } break; case OperateType.Cal_Simplify: // 拓扑纠正 IdentifyGraphicsOverlayResult gResult_Simplify = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false); if (gResult_Simplify.Graphics.Count < 1) { return; } Graphic selGraphic_Simplify = gResult_Simplify.Graphics.First(); selGraphic_Simplify.IsSelected = true; listOfClipGraphics.Add(selGraphic_Simplify); //记录所选图形 if (listOfClipGraphics.Count == 1) //图形数目为1时,进行剪切计算 { Graphic g1 = listOfClipGraphics[0]; if (g1.Geometry.GeometryType == GeometryType.Point) //如果所选图形不是多边形,则退出 { MessageBox.Show("请先选择一个面要素或线要素."); listOfClipGraphics.Clear(); graphicsLayer.ClearSelection(); return; } Esri.ArcGISRuntime.Geometry.Geometry resultGeometry = GeometryEngine.Simplify(g1.Geometry); //执行剪切操作 if (resultGeometry != null) //处理结果 { graphicsLayer.Graphics.Remove(g1); //从图形层中移除原图形 Graphic clipedGraphic = new Graphic(resultGeometry, fillSymbol); //利 用剪切结果构建新的图形 graphicsLayer.Graphics.Add(clipedGraphic); operation = OperateType.None; } listOfClipGraphics.Clear(); //清空图形选择集合 graphicsLayer.ClearSelection(); //清空图形层所选 } break; case OperateType.Cal_Gene: // 简化 IdentifyGraphicsOverlayResult gResult_Gene = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false); if (gResult_Gene.Graphics.Count < 1) { return; } Graphic selGraphic_Gene = gResult_Gene.Graphics.First(); selGraphic_Gene.IsSelected = true; listOfClipGraphics.Add(selGraphic_Gene); //记录所选图形 if (listOfClipGraphics.Count == 1) //图形数目为1时 { Graphic g1 = listOfClipGraphics[0]; if (g1.Geometry.GeometryType == GeometryType.Point) //如果所选图形是点,则退出 { MessageBox.Show("请先选择一个面要素或线要素."); listOfClipGraphics.Clear(); graphicsLayer.ClearSelection(); return; } Esri.ArcGISRuntime.Geometry.Geometry resultGeometry = GeometryEngine.Generalize(g1.Geometry, 1000000.0, true); //执行剪切操作 if (resultGeometry != null) //处理结果 { MessageBox.Show(resultGeometry.ToJson() + "\n" + resultGeometry.GeometryType); graphicsLayer.Graphics.Remove(g1); //从图形层中移除原图形 Graphic clipedGraphic = new Graphic(resultGeometry, fillSymbol); //利 用剪切结果构建新的图形 graphicsLayer.Graphics.Add(clipedGraphic); operation = OperateType.None; } listOfClipGraphics.Clear(); //清空图形选择集合 graphicsLayer.ClearSelection(); //清空图形层所选 } break; case OperateType.Cal_Buff: // 缓冲 IdentifyGraphicsOverlayResult gResult_Buff = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false); if (gResult_Buff.Graphics.Count < 1) { return; } Graphic selGraphic_Buff = gResult_Buff.Graphics.First(); selGraphic_Buff.IsSelected = true; listOfClipGraphics.Add(selGraphic_Buff); //记录所选图形 if (listOfClipGraphics.Count == 1) //图形数目为1时,进行剪切计算 { Graphic g1 = listOfClipGraphics[0]; Esri.ArcGISRuntime.Geometry.Geometry resultGeometry = GeometryEngine.Buffer(g1.Geometry, 1000000.0); //执行剪切操作 if (resultGeometry != null) //处理结果 { graphicsLayer.Graphics.Remove(g1); //从图形层中移除原图形 Graphic clipedGraphic = new Graphic(resultGeometry, new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.FromArgb(125, 255, 250, 0), new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.FromArgb(0, 0, 0), 4.0))); //利 用剪切结果构建新的图形 graphicsLayer.Graphics.Add(clipedGraphic); operation = OperateType.None; } listOfClipGraphics.Clear(); //清空图形选择集合 graphicsLayer.ClearSelection(); //清空图形层所选 } break; case OperateType.Cal_Jiaodian: // 交点 IdentifyGraphicsOverlayResult gResult_Jiaodian = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false); if (gResult_Jiaodian.Graphics.Count < 1) { return; } Graphic selGraphic_Jiaodian = gResult_Jiaodian.Graphics.First(); selGraphic_Jiaodian.IsSelected = true; listOfClipGraphics.Add(selGraphic_Jiaodian); //记录所选图形 if (listOfClipGraphics.Count == 2) //图形数目为1时,进行剪切计算 { Graphic g1 = listOfClipGraphics[0]; Graphic g2 = listOfClipGraphics[1]; IReadOnlyList <Geometry> resultGeometry = GeometryEngine.Intersections(g1.Geometry, g2.Geometry); //执行剪切操作 if (resultGeometry != null) //处理结果 { Graphic clipedGraphic = new Graphic(resultGeometry[0], pointSymbol); //利 用剪切结果构建新的图形 graphicsLayer.Graphics.Add(clipedGraphic); operation = OperateType.None; } listOfClipGraphics.Clear(); //清空图形选择集合 graphicsLayer.ClearSelection(); //清空图形层所选 } break; } }
// myMapView 事件 private async void MyMapView_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { IInputElement ie = (IInputElement)(sender); MapPoint loc = myMapView.ScreenToLocation(e.GetPosition(ie)); switch (operation) { case OperateType.DrawPoint: //画点 Graphic pt = new Graphic(loc, pointSymbol); graphicsLayer.Graphics.Add(pt); break; case OperateType.DrawPolyline: //画线 pointCollection.Add(loc); if (pointCollection.Count >= 2) { if (pointCollection.Count > 2) { Graphic g = graphicsLayer.Graphics[graphicsLayer.Graphics.Count - 1]; PolylineBuilder lb = new PolylineBuilder(pointCollection); g.Geometry = lb.ToGeometry(); } else { Esri.ArcGISRuntime.Geometry.Polyline l = new Esri.ArcGISRuntime.Geometry.Polyline(pointCollection); Graphic lg = new Graphic(l, lineSymbol); graphicsLayer.Graphics.Add(lg); } } break; case OperateType.DrawPolygon: //画多边形 pointCollection.Add(loc); if (pointCollection.Count >= 3) { if (pointCollection.Count > 3) { Graphic g = graphicsLayer.Graphics[graphicsLayer.Graphics.Count - 1]; PolygonBuilder pb = new PolygonBuilder(pointCollection); g.Geometry = pb.ToGeometry(); } else { Esri.ArcGISRuntime.Geometry.Polygon p = new Esri.ArcGISRuntime.Geometry.Polygon(pointCollection); Graphic pg = new Graphic(p, fillSymbol); graphicsLayer.Graphics.Add(pg); } } break; case OperateType.None: //缺省状态 graphicsLayer.ClearSelection(); IdentifyGraphicsOverlayResult result = await myMapView.IdentifyGraphicsOverlayAsync(graphicsLayer, e.GetPosition(ie), 5, false); //选择图形元素 if (result.Graphics.Count < 1) { curSelGraphic = null; EditVertexMenuItem.IsEnabled = false; UneditVertexMenuItem.IsEnabled = false; return; } curSelGraphic = result.Graphics.First(); curSelGraphic.IsSelected = true; EditVertexMenuItem.IsEnabled = true; break; } }
public IS3Polygon(Esri.ArcGISRuntime.Geometry.Polygon other) : base(other.Parts, other.SpatialReference) { }