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 void MyMapViewOnGeoViewTapped_Line(object sender, GeoViewInputEventArgs geoViewInputEventArgs) { // Get the tapped point, projected to WGS84. MapPoint destination = (MapPoint)GeometryEngine.Project(geoViewInputEventArgs.Location, SpatialReferences.Wgs84); mapPoints.Add(destination); int len = mapPoints.Count(); Esri.ArcGISRuntime.Geometry.PointCollection polylinePoints; Esri.ArcGISRuntime.Geometry.Geometry pathGeometry; Esri.ArcGISRuntime.Geometry.Polyline routeLine; if (len > 1) { polylinePoints = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84) { mapPoints[len - 2], destination }; routeLine = new Esri.ArcGISRuntime.Geometry.Polyline(polylinePoints); pathGeometry = GeometryEngine.DensifyGeodetic(routeLine, 1, LinearUnits.Kilometers, GeodeticCurveType.Geodesic); // 这是测地线的长度 //double distance = GeometryEngine.LengthGeodetic(pathGeometry, LinearUnits.Kilometers, GeodeticCurveType.Geodesic); double distance = GeometryEngine.Length(pathGeometry); //double distance = GeometryEngine.Length(routeLine); lengthList.Add(distance); myMeasureResult.Text += "\n" + distance + " (地图默认长度单位)"; } }
private void LoadEntireNmeaTrack(string filename) { var layer = mapView.GraphicsOverlays.First(); layer.Graphics.Clear(); if (currentNmeaFile == null) return; List<MapPoint> vertices = new List<MapPoint>(); using (var sr = System.IO.File.OpenText(filename)) { while (!sr.EndOfStream) { var line = sr.ReadLine(); if (line != null && line.StartsWith("$")) { try { var msg = NmeaParser.Messages.NmeaMessage.Parse(line); if (msg is NmeaParser.Messages.Rmc rmc) { if (!double.IsNaN(rmc.Longitude)) vertices.Add(new MapPoint(rmc.Longitude, rmc.Latitude)); } } catch { } } } } var pline = new Esri.ArcGISRuntime.Geometry.Polyline(vertices, SpatialReferences.Wgs84); var linesymbol = new SimpleLineSymbol() { Width = 4, Color = System.Drawing.Color.CornflowerBlue }; var symbol = new CompositeSymbol(); symbol.Symbols.Add(linesymbol); symbol.Symbols.Add(new SimpleMarkerSymbol() { Size = 5, Color = System.Drawing.Color.Black }); layer.Graphics.Add(new Graphic(pline, symbol)); }
public static Graphic NewPolyline(Esri.ArcGISRuntime.Geometry.PointCollection pc) { Esri.ArcGISRuntime.Geometry.Polyline polyline = new Esri.ArcGISRuntime.Geometry.Polyline(pc); Graphic g = new Graphic(); g.Geometry = polyline; 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 addPolylines() { ObservableCollection <MapPoint> cc = new ObservableCollection <MapPoint>(); cc.Add(new MapPoint(-122.410521484809, 37.7918774561425, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.410324448543, 37.7919488885661, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.410203882271, 37.791913618768, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.409893155125, 37.791929107188, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.409596281126, 37.7919658630922, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.409108421115, 37.7920624120246, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.408817075003, 37.7921308679055, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.408487157309, 37.7921404237124, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.408318594361, 37.7921634551306, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407960718313, 37.7922423743177, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407649210245, 37.7922609783687, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407319379371, 37.7923365607979, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407087140057, 37.7923507171833, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.406860565968, 37.7923645287614, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.406655156229, 37.7923727726631, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.406300167333, 37.7923798808881, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.406155210349, 37.7924008897704, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.405946326338, 37.7924247794125, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.405699271002, 37.7925230337143, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.405454358112, 37.7926090310406, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.405077277732, 37.7926305633495, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.404748570807, 37.792656153651, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.404624092484, 37.7927069877562, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.404443495634, 37.7927364457713, SpatialReferences.Wgs84)); SimpleLineSymbol sls = new SimpleLineSymbol(); sls.Style = SimpleLineStyle.Solid; sls.Color = Color.FromArgb(170, 255, 0, 0); sls.Width = 5; Esri.ArcGISRuntime.Geometry.Polyline polyline = new Esri.ArcGISRuntime.Geometry.Polyline(cc, SpatialReferences.Wgs84); Esri.ArcGISRuntime.Geometry.Geometry geometry = (Esri.ArcGISRuntime.Geometry.Geometry)polyline; Graphic graphic = new Graphic(geometry, sls); graphic.Attributes.Add("A", 74); graphic.Attributes.Add("B", 100); MyGraphicsLayer.Graphics.Add(graphic); }
private void Load3DLineLayer(object parameter) { var pointcollec = new Esri.ArcGISRuntime.Geometry.PointCollection(); pointcollec.Add(new MapPoint(116.587, 39.852, 3000)); pointcollec.Add(new MapPoint(116.587, 39.952, 3000)); pointcollec.Add(new MapPoint(116.687, 39.952, 3000)); pointcollec.Add(new MapPoint(116.687, 40.052, 3000)); var line = new Esri.ArcGISRuntime.Geometry.Polyline(pointcollec, SpatialReferences.Wgs84); var graphicLayer = new GraphicsLayer(); graphicLayer.DisplayName = "3D线图层"; graphicLayer.ShowLegend = false; graphicLayer.Graphics.Add(new Graphic(line)); graphicLayer.Renderer = App.Current.Resources["LineSimpleRenderer"] as SimpleRenderer; graphicLayer.SceneProperties.SurfacePlacement = SurfacePlacement.Relative; graphicLayer.ID = "3DLineLayer"; scene.Layers.Add(graphicLayer); }
private Graphic coordinatesystem_polyline(Esri.ArcGISRuntime.Geometry.Geometry geometry) { Graphic _polylineGraphic = null; var roadPolyline = geometry as Esri.ArcGISRuntime.Geometry.Polyline; // var roadPolyline = graphic.Geometry as Esri.ArcGISRuntime.Geometry.Polyline; this.polylineBuilder = new PolylineBuilder(roadPolyline); foreach (var r in polylineBuilder.Parts) { IReadOnlyList <MapPoint> mapPoints = r.Points; var polypoints = Mapcoordinates_Aftertransform(mapPoints); _polypointcollection = polypoints; //HandleMapTap1(polypoints); //var polypoints = Mapcoordinates_Aftertransform(mapPoints); //_polypointcollection = polypoints;//new var polyline = new Esri.ArcGISRuntime.Geometry.Polyline(polypoints); //Create symbol for polyline // var polylineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.FromArgb(0, 0, 255), 3); // var polys3 = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Green, 3); var polys3 = new SimpleLineSymbol(SimpleLineSymbolStyle.DashDot, System.Drawing.Color.FromArgb(0, 0, 255), 3); // polys3.MarkerPlacement = SimpleLineSymbolMarkerPlacement.End; // polys3.ma = getpic1(); //polys3.MarkerStyle = SimpleLineSymbolMarkerStyle.Arrow; //polys3.MarkerPlacement = SimpleLineSymbolMarkerPlacement.BeginAndEnd; //Create a polyline graphic with geometry and symbol _polylineGraphic = new Graphic(polyline, polys3); //Add polyline to graphics overlay // _sketchPolylineOverlay.Graphics.Add(_polylineGraphic); Esri.ArcGISRuntime.Geometry.Geometry gr = polyline; } return(_polylineGraphic); }
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(); } } } }
// 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; } }
private async void ExecuteGPService() { //加载DEM并且缩放到该区域 Map map = new Map(Basemap.CreateTopographic()); string pathToRaster = @"D:\work\github\ExecuteGPK\LasVegasNED13_geoid1.tif"; var myRaster = new Raster(pathToRaster); // create a RasterLayer using the Raster var newRasterLayer = new RasterLayer(myRaster); map.OperationalLayers.Add(newRasterLayer); Viewpoint viewPoint = new Viewpoint(36.131, -115.144, 800000); myMapView.Map = map; await myMapView.SetViewpointAsync(viewPoint, TimeSpan.FromSeconds(2)); StartLocalServer(); LocalGeoprocessingService localServiceGP = new LocalGeoprocessingService(@"D:\work\github\ExecuteGPK\InterpolateShape.gpk"); localServiceGP.ServiceType = GeoprocessingServiceType.SynchronousExecute; // Handle the status changed event to check when it's loaded localServiceGP.StatusChanged += async(svc, args) => { // If service started successfully, create a gp task if (args.Status == LocalServerStatus.Started) { // Get the URL for the specific geoprocessing tool var gpSvcUrl = (svc as LocalGeoprocessingService).Url.AbsoluteUri + "/InterpolateShape"; // Create the geoprocessing task GeoprocessingTask gpRouteTask = new GeoprocessingTask(new Uri(gpSvcUrl)); GeoprocessingParameters para = new GeoprocessingParameters(GeoprocessingExecutionType.SynchronousExecute); // Create the schema for a lines table (one text field to contain a name attribute) var inputFeatures = new FeatureCollectionTable(new List <Field>(), GeometryType.Polyline, myMapView.SpatialReference); Feature inputFeature = inputFeatures.CreateFeature(); var geometry = await myMapView.SketchEditor.StartAsync(SketchCreationMode.Polyline, false); inputFeature.Geometry = geometry; await inputFeatures.AddFeatureAsync(inputFeature); para.Inputs.Add("inputLine", new GeoprocessingFeatures(inputFeatures)); para.ReturnZ = true; para.OutputSpatialReference = myMapView.SpatialReference; GeoprocessingJob routeJob = gpRouteTask.CreateJob(para); try { // Execute analysis and wait for the results GeoprocessingResult geoprocessingResult = await routeJob.GetResultAsync(); GeoprocessingFeatures resultFeatures = geoprocessingResult.Outputs["outputLine"] as GeoprocessingFeatures; IFeatureSet interpolateShapeResult = resultFeatures.Features; Esri.ArcGISRuntime.Geometry.Polyline elevationLine = interpolateShapeResult.First().Geometry as Esri.ArcGISRuntime.Geometry.Polyline; MapPoint startPoint = elevationLine.Parts[0].Points[0]; int count = elevationLine.Parts[0].PointCount; MapPoint stopPoint = elevationLine.Parts[0].Points[count - 1]; double chazhi = stopPoint.Z - startPoint.Z; MessageBox.Show("终点的Z值为: " + stopPoint.Z.ToString() + ",起点的Z值为: " + startPoint.Z.ToString()); } catch (Exception ex) { if (routeJob.Status == JobStatus.Failed && routeJob.Error != null) { MessageBox.Show("Executing geoprocessing failed. " + routeJob.Error.Message, "Geoprocessing error"); } else { MessageBox.Show("An error occurred. " + ex.ToString(), "Sample error"); } } // Create parameters, run the task, process results, etc. // ... } }; // Start the local geoprocessing service await localServiceGP.StartAsync(); }
private void addPolylines() { ObservableCollection<MapPoint> cc = new ObservableCollection<MapPoint>(); cc.Add(new MapPoint(-122.410521484809, 37.7918774561425, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.410324448543, 37.7919488885661, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.410203882271, 37.791913618768, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.409893155125, 37.791929107188, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.409596281126, 37.7919658630922, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.409108421115, 37.7920624120246, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.408817075003, 37.7921308679055, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.408487157309, 37.7921404237124, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.408318594361, 37.7921634551306, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407960718313, 37.7922423743177, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407649210245, 37.7922609783687, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407319379371, 37.7923365607979, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.407087140057, 37.7923507171833, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.406860565968, 37.7923645287614, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.406655156229, 37.7923727726631, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.406300167333, 37.7923798808881, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.406155210349, 37.7924008897704, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.405946326338, 37.7924247794125, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.405699271002, 37.7925230337143, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.405454358112, 37.7926090310406, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.405077277732, 37.7926305633495, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.404748570807, 37.792656153651, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.404624092484, 37.7927069877562, SpatialReferences.Wgs84)); cc.Add(new MapPoint(-122.404443495634, 37.7927364457713, SpatialReferences.Wgs84)); SimpleLineSymbol sls = new SimpleLineSymbol(); sls.Style = SimpleLineStyle.Solid; sls.Color = Color.FromArgb(170, 255, 0, 0); sls.Width = 5; Esri.ArcGISRuntime.Geometry.Polyline polyline = new Esri.ArcGISRuntime.Geometry.Polyline(cc, SpatialReferences.Wgs84); Esri.ArcGISRuntime.Geometry.Geometry geometry = (Esri.ArcGISRuntime.Geometry.Geometry)polyline; Graphic graphic = new Graphic(geometry, sls); graphic.Attributes.Add("A", 74); graphic.Attributes.Add("B", 100); MyGraphicsLayer.Graphics.Add(graphic); }
//=================探空仪位置更新==================== private void AnimatePlane(object sender, ElapsedEventArgs elapsedEventArgs) { //LoadData(); Dispatcher.BeginInvoke(new Action(() => { if (Global.namelist.Count > 0) { var ait = Global.namelist.GetEnumerator(); var bit = Global.lonlist.GetEnumerator(); var cit = Global.latlist.GetEnumerator(); var dit = Global.radiuslist.GetEnumerator(); while (ait.MoveNext() && bit.MoveNext() && cit.MoveNext() && dit.MoveNext()) { double lo = double.Parse(bit.Current.ToString()); double la = double.Parse(cit.Current.ToString()); double ra = double.Parse(dit.Current.ToString()); Createarea(lo, la, ra); } } })); //if (_randomizer.Next(0, 10) > 8) //{ // Don't send an update about 20% of the time. // return; // } // _locationIndex++; int cnt = 0; MapPoint p = observerCamera.Location; double dis = 999999999; if (Dector2D.Count > 0 && MapPointslist.Count > 0) { int count = Dector2D.Count; for (int i = 0; i < count; i++) { int index = Global.DectorIndexIdlist[i]; List <MapPoint> _artificialMapPoints = new List <MapPoint>(); if (MapPointslist[i].Count > 0) { _artificialMapPoints = MapPointslist[i]; if (index > _artificialMapPoints.Count) { Global.DectorNamelist.Remove(Global.DectorNamelist[i]); Global.StationIdlist.Remove(Global.StationIdlist[i]); Global.DectorIndexIdlist.Remove(Global.DectorIndexIdlist[i]); } else { MapPoint selectedMapPoint = _artificialMapPoints[index % _artificialMapPoints.Count]; double dis1 = Distance(p.X, p.Y, p.Z, selectedMapPoint.X, selectedMapPoint.Y, selectedMapPoint.Z); if (dis1 < dis) { cnt = i; dis = dis1; } Graphic name2D = Dector2D[i]; name2D.Geometry = new MapPoint(selectedMapPoint.X, selectedMapPoint.Y, spatialReference: SpatialReference.Create(wkid: 4326)); Graphic name3D = Dector3D[i]; name3D.Geometry = new MapPoint(selectedMapPoint.X, selectedMapPoint.Y, selectedMapPoint.Z); //=====预测轨迹显示==== // Create a purple simple line symbol SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.FromArgb(0xFF, 0x80, 0x00, 0x80), 3); SimpleLineSymbol lineSymbol1 = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.Red, 3); Esri.ArcGISRuntime.Geometry.PointCollection points = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84); Esri.ArcGISRuntime.Geometry.PointCollection points1 = new Esri.ArcGISRuntime.Geometry.PointCollection(); if (index + 120 < _artificialMapPoints.Count) { for (int j = index; j < index + 120; j++) { // Get the next point . MapPoint selectedMapPoint1 = _artificialMapPoints[j % _artificialMapPoints.Count]; points.Add(new MapPoint(selectedMapPoint1.X, selectedMapPoint1.Y, spatialReference: SpatialReference.Create(wkid: 4326))); points1.Add(new MapPoint(selectedMapPoint1.X, selectedMapPoint1.Y, selectedMapPoint1.Z)); } ; } // Create the polyline from the point collection Esri.ArcGISRuntime.Geometry.Polyline polyline = new Esri.ArcGISRuntime.Geometry.Polyline(points); Esri.ArcGISRuntime.Geometry.Polyline polyline1 = new Esri.ArcGISRuntime.Geometry.Polyline(points1); GraphicsOverlay _overlay = Dector2Doverlay[i]; GraphicsOverlay _overlay1 = Dector3Doverlay[i]; _overlay.Graphics.Clear(); _overlay1.Graphics.Clear(); // Create the graphic with polyline and symbol Graphic graphic = new Graphic(polyline, lineSymbol); Graphic graphic1 = new Graphic(polyline1, lineSymbol1); // Add graphic to the graphics overlay _overlay.Graphics.Add(graphic); _overlay1.Graphics.Add(graphic1); } } } } if (MapPointslist.Count > 0) { List <MapPoint> _artificialMapPoints2 = new List <MapPoint>(); _artificialMapPoints2 = MapPointslist[cnt]; // Get the next point . MapPoint selectedMapPoint2 = _artificialMapPoints2[Global.DectorIndexIdlist[cnt] % _artificialMapPoints2.Count]; string n = Global.DectorNamelist[cnt]; Dispatcher.BeginInvoke(new Action(() => { NameLabel.Text = n; AboveSeaLevelLabel.Text = " " + selectedMapPoint2.Z + "m"; LonLabel.Text = " " + selectedMapPoint2.X; LatLabel.Text = " " + selectedMapPoint2.Y; })); } if (Global.DectorIndexIdlist.Count > 0) { for (int k = 0; k < Global.DectorIndexIdlist.Count; k++) { Global.DectorIndexIdlist[k] = Global.DectorIndexIdlist[k] + 120; } } }
// 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; } }
public static Graphic NewPolyline(Esri.ArcGISRuntime.Geometry.PointCollection pc) { Esri.ArcGISRuntime.Geometry.Polyline polyline = new Esri.ArcGISRuntime.Geometry.Polyline(pc); Graphic g = new Graphic(); g.Geometry = polyline; return g; }
private void LoadEntireNmeaTrack(string filename) { var layer = mapView.Map.Layers.OfType<GraphicsLayer>().First(); layer.Graphics.Clear(); if (currentNmeaFile == null) return; List<MapPoint> vertices = new List<MapPoint>(); using (var sr = System.IO.File.OpenText(filename)) { while (!sr.EndOfStream) { var line = sr.ReadLine(); if (line.StartsWith("$")) { try { var msg = NmeaParser.Nmea.NmeaMessage.Parse(line); if (msg is NmeaParser.Nmea.Gps.Gprmc) { var rmc = (NmeaParser.Nmea.Gps.Gprmc)msg; if (!double.IsNaN(rmc.Longitude)) vertices.Add(new MapPoint(rmc.Longitude, rmc.Latitude)); } } catch { } } } } var pline = new Esri.ArcGISRuntime.Geometry.Polyline(vertices, SpatialReferences.Wgs84); var linesymbol = new SimpleLineSymbol() { Width = 4, Color = Colors.CornflowerBlue }; var symbol = new CompositeSymbol(); symbol.Symbols.Add(linesymbol); symbol.Symbols.Add(new SimpleMarkerSymbol() { Size = 5, Color = Colors.Black }); Esri.ArcGISRuntime.Layers.Graphic g = new Esri.ArcGISRuntime.Layers.Graphic(pline, symbol); layer.Graphics.Add(g); }