public void Thermodynamic(double centerX, double centerY, double radius, string colour, int id, int typeid) { //画圆 GraphicsLayer Cityrode = map.Layers["GraphicsLayerRL"] as GraphicsLayer; //Cityrode.Graphics.Clear(); Graphic result = new Graphic(); radius = radius / 111321; List <MapPoint> points = new List <MapPoint>(); for (double i = 0; i <= 360; i++) { points.Add(new MapPoint((centerX - Math.Cos(Math.PI * i / 180.0) * radius), (centerY - Math.Sin(Math.PI * i / 180.0) * radius))); } //ESRI.ArcGIS.Client.Geometry. ESRI.ArcGIS.Client.Geometry.PointCollection pCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(points); ESRI.ArcGIS.Client.Geometry.Polygon g = new ESRI.ArcGIS.Client.Geometry.Polygon(); g.Rings.Add(pCollection); result.Geometry = g; SimpleFillSymbol sfs = new SimpleFillSymbol(); sfs.BorderBrush = new SolidColorBrush(Colors.Transparent); sfs.BorderThickness = 2; string[] str = colour.Split(','); sfs.Fill = new SolidColorBrush(Color.FromArgb(0x7f, Convert.ToByte(str[0]), Convert.ToByte(str[1]), Convert.ToByte(str[2]))); result.Symbol = sfs; result.MouseLeftButtonUp += delegate { HtmlPage.Window.Invoke("clickPonitsShowThermodynamic", id, typeid); }; Cityrode.Graphics.Add(result); ContainerManager.Map.PanTo(new ESRI.ArcGIS.Client.Geometry.Envelope((double)centerX, (double)centerY, (double)centerX, (double)centerY)); }
private void drawPolygon() { MapPoint center = MyMap.Extent.GetCenter(); double lat = center.Y; double lon = center.X + 300; double latOffset = 300; double lonOffset = 300; ESRI.ArcGIS.Client.Geometry.PointCollection points = new ESRI.ArcGIS.Client.Geometry.PointCollection() { new MapPoint(lon - lonOffset, lat), new MapPoint(lon, lat + latOffset), new MapPoint(lon + lonOffset, lat), new MapPoint(lon, lat - latOffset), new MapPoint(lon - lonOffset, lat), new MapPoint(lon - 2 * lonOffset, lat + latOffset), new MapPoint(lon - 3 * lonOffset, lat), new MapPoint(lon - 2 * lonOffset, lat - latOffset), new MapPoint(lon - 1.5 * lonOffset, lat + latOffset), new MapPoint(lon - lonOffset, lat) }; ESRI.ArcGIS.Client.Geometry.Polygon polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon.Rings.Add(points); polygon.SpatialReference = MyMap.SpatialReference; _unsimplifiedGraphic.Geometry = polygon; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; _unsimplifiedGraphic.Symbol = LayoutRoot.Resources["PolygonFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; graphicsLayer.Graphics.Add(_unsimplifiedGraphic); }
public void DrowGraphical(string url) { WebAPIHelper dt = new WebAPIHelper(); GraphicsLayer Cityrode = map.Layers["GraphicsLayerCq"] as GraphicsLayer; dt.GetDataCompleted += (s, args) => { List <MapGraphical> list = args.DataResult as List <MapGraphical>; foreach (var model in list) { SimpleFillSymbol style = new SimpleFillSymbol(); string[] str = model.colour.Split(','); List <MapPoint> MapPointList = new List <MapPoint>(); foreach (var po in model.MapPointList) { MapPointList.Add(new MapPoint { X = po.X, Y = po.Y }); } //Color ColorFill = ConvertToHtml(model.colour); Graphic graphic = new Graphic(); style.Fill = new SolidColorBrush(Color.FromArgb(0x7f, Convert.ToByte(str[0]), Convert.ToByte(str[1]), Convert.ToByte(str[2]))); ESRI.ArcGIS.Client.Geometry.PointCollection pCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(MapPointList); ESRI.ArcGIS.Client.Geometry.Polygon g = new ESRI.ArcGIS.Client.Geometry.Polygon(); g.Rings.Add(pCollection); graphic.Geometry = g; graphic.Symbol = style; //ESRI.ArcGIS.Client.Geometry.Polygon polygon = (ESRI.ArcGIS.Client.Geometry.Polygon)graphic.Geometry; //GraphicsLayerCq Cityrode.Graphics.Add(graphic); } }; dt.GetDataAsync <List <MapGraphical> >(url); }
private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args) { MyDrawObject.IsEnabled = false; ESRI.ArcGIS.Client.Geometry.Polygon polygon = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon; polygon.SpatialReference = MyMap.SpatialReference; Graphic graphic = new Graphic() { Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol, Geometry = polygon, }; GeometryService geometryService = new GeometryService("http://serverapps101.esri.com/arcgis/rest/services/Geometry/GeometryServer"); geometryService.AreasAndLengthsCompleted += GeometryService_AreasAndLengthsCompleted; geometryService.Failed += GeometryService_Failed; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.Graphics.Add(graphic); List <Graphic> graphicList = new List <Graphic>(); graphicList.Add(graphic); // Since there are multiple overloads for AreasAndLengthsAsync, make sure to use appropriate signature with correct parameter types. geometryService.AreasAndLengthsAsync(graphicList, null, null, (CalculationType)CalcTypeListBox.SelectedValue); // GeometryService.AreasAndLengths returns distances and areas in the units of the spatial reference. // The units in the map view's projection is decimal degrees. // Use the Project method to convert graphic points to a projection that uses a measured unit (e.g. meters). // If the map units are in measured units, the call to Project is unnecessary. // Important: Use a projection appropriate for your area of interest. }
private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args) { ESRI.ArcGIS.Client.Geometry.Polygon polygon = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon; polygon.SpatialReference = MyMap.SpatialReference; Graphic graphic = new Graphic() { Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.FillSymbol, Geometry = polygon, }; GeometryService geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.AreasAndLengthsCompleted += GeometryService_AreasAndLengthsCompleted; geometryService.Failed += GeometryService_Failed; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.Graphics.Add(graphic); List <Graphic> graphicList = new List <Graphic>(); graphicList.Add(graphic); geometryService.AreasAndLengthsAsync(graphicList); // GeometryService.AreasAndLengths returns distances and areas in the units of the spatial reference. // The units in the map view's projection is decimal degrees. // Use the Project method to convert graphic points to a projection that uses a measured unit (e.g. meters). // If the map units are in measured units, the call to Project is unnecessary. // Important: Use a projection appropriate for your area of interest. }
public void drawBufferCircle(double radius, int pointCount, MapPoint currentPoint, GraphicsLayer gl) { MapPoint point = currentPoint; var pl = new ESRI.ArcGIS.Client.Geometry.Polyline(); var polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); var routePoint = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (int i = 1; i <= pointCount; i++) { double x; double y; x = (point.X + radius * Math.Cos(2 * Math.PI / pointCount * i)); y = (point.Y + radius * Math.Sin(2 * Math.PI / pointCount * i)); routePoint.Add(new MapPoint(x, y)); } routePoint.Add(routePoint[0]); polygon.Rings.Add(routePoint); GraphicsLayer mygraphicslayer = gl; mygraphicslayer.ClearGraphics(); Graphic graphic = new Graphic() { Geometry = polygon, Symbol = LayoutRoot.Resources["DefaultBufferSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol, }; mygraphicslayer.Graphics.Add(graphic); }
/// <summary> /// Method converts ESRI ArcGIS Polygon object to ESRI ArcLogistics Polygon object. /// </summary> /// <param name="polygon">Polygon to convert.</param> /// <returns>ESRI ArcLogistics Polygon object.</returns> private ESRI.ArcLogistics.Geometry.Polygon _ConvertToArcLogisticsPolygon( ESRISDSGeometry.Polygon polygon) { Debug.Assert(polygon != null); var groups = new List <int>(); var points = new List <ESRI.ArcLogistics.Geometry.Point>(); for (int i = 0; i < polygon.Rings.Count; i++) { // Fill current group by count of Points in it. groups.Add(polygon.Rings[i].Count); var collection = polygon.Rings[i]; // Get all points. foreach (var point in collection) { points.Add(_ConvertToArcLogisticsPoint(point)); } } var newPolygon = new ESRI.ArcLogistics.Geometry.Polygon( groups.ToArray(), points.ToArray()); return(newPolygon); }
/// <summary> /// Convert Freehand Polyline to a Freehand Polygon /// </summary> /// <param name="freeline">Freehandly drawn polyline</param> /// <returns>A freehand polygon</returns> public static Polygon FreehandToPolygon(Polyline freeline) { if (freeline == null) { return(null); } Polygon polygonFromFreeline = null; // Reference the PointCollection of the drawn Freehand Polyline ObservableCollection <PointCollection> pointsCollection = freeline.Paths; if (pointsCollection.Count > 0) { if (pointsCollection[0].Count > 0) { // Get the first Point and "close" the shape and form a polygon. MapPoint startingPt = pointsCollection[0][0]; pointsCollection[0].Add(startingPt.Clone()); polygonFromFreeline = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygonFromFreeline.SpatialReference = freeline.SpatialReference; polygonFromFreeline.Rings.Add(pointsCollection[0]); } } return(polygonFromFreeline); }
private void drawPolygon() { MapPoint center = MyMap.Extent.GetCenter(); double lat = center.Y; double lon = center.X + 300; double latOffset = 300; double lonOffset = 300; ESRI.ArcGIS.Client.Geometry.PointCollection points = new ESRI.ArcGIS.Client.Geometry.PointCollection() { new MapPoint(lon - lonOffset, lat), new MapPoint(lon, lat + latOffset), new MapPoint(lon + lonOffset, lat), new MapPoint(lon, lat - latOffset), new MapPoint(lon - lonOffset, lat), new MapPoint(lon - 2 * lonOffset, lat + latOffset), new MapPoint(lon - 3 * lonOffset, lat), new MapPoint(lon - 2 * lonOffset, lat - latOffset), new MapPoint(lon - 1.5 * lonOffset, lat + latOffset), new MapPoint(lon - lonOffset, lat) }; ESRI.ArcGIS.Client.Geometry.Polygon polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon.Rings.Add(points); polygon.SpatialReference = MyMap.SpatialReference; _unsimplifiedGraphic.Geometry = polygon; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; _unsimplifiedGraphic.Symbol = LayoutRoot.Resources["PolygonFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; graphicsLayer.Graphics.Add(_unsimplifiedGraphic); }
public void Round(double centerX, double centerY, double radius, string jsondata) { //定位点 Location(jsondata); //画圆 GraphicsLayer Cityrode = map.Layers["GraphicsLayer"] as GraphicsLayer; Cityrode.Graphics.Clear(); Graphic result = new Graphic(); //radius = radius / 111321; List <MapPoint> points = new List <MapPoint>(); for (double i = 0; i <= 360; i++) { points.Add(new MapPoint((centerX - Math.Cos(Math.PI * i / 180.0) * radius), (centerY - Math.Sin(Math.PI * i / 180.0) * radius))); } //ESRI.ArcGIS.Client.Geometry. ESRI.ArcGIS.Client.Geometry.PointCollection pCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(points); ESRI.ArcGIS.Client.Geometry.Polygon g = new ESRI.ArcGIS.Client.Geometry.Polygon(); g.Rings.Add(pCollection); result.Geometry = g; SimpleFillSymbol sfs = new SimpleFillSymbol(); sfs.BorderBrush = new SolidColorBrush(Colors.Transparent); sfs.BorderThickness = 2; sfs.Fill = new SolidColorBrush(Colors.Red); result.Symbol = sfs; Cityrode.Graphics.Add(result); ContainerManager.Map.PanTo(new ESRI.ArcGIS.Client.Geometry.Envelope((double)centerX, (double)centerY, (double)centerX, (double)centerY)); }
private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args) { MyDrawObject.IsEnabled = true; ESRI.ArcGIS.Client.Geometry.Polygon polygon = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon; polygon.SpatialReference = MyMap.SpatialReference; Graphic graphic = new Graphic() { Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol, Geometry = polygon }; GraphicsLayer graphicsLayerPolygon = MyMap.Layers["PolygonGraphicsLayer"] as GraphicsLayer; graphicsLayerPolygon.Graphics.Add(graphic); GraphicsLayer graphicsLayerVertices = MyMap.Layers["VerticesGraphicsLayer"] as GraphicsLayer; foreach (MapPoint point in polygon.Rings[0]) { Graphic vertice = new Graphic() { Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol, Geometry = point }; graphicsLayerVertices.Graphics.Add(vertice); } DensifyButton.IsEnabled = true; }
/// <summary> /// union the polygon shapes in every graphic into one big multi part polygon. /// return esri polygon /// </summary> /// <param name="graphics"></param> /// <returns>esri polygon</returns> public static ESRI.ArcGIS.Client.Geometry.Polygon UnionEsriPolygon(GraphicCollection graphics) { ESRI.ArcGIS.Client.Geometry.Polygon p = new ESRI.ArcGIS.Client.Geometry.Polygon(); foreach (Graphic g in graphics) { foreach (ESRI.ArcGIS.Client.Geometry.PointCollection pc in (g.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon).Rings) { p.Rings.Add(pc); } } return(p); }
public static bool checkEsriIntersect(double lat, double lon, string beatID) { bool inPoly = false; bool isInside = false; ESRI.ArcGIS.Client.Geometry.MapPoint point = new ESRI.ArcGIS.Client.Geometry.MapPoint(lon, lat); var spList = from sp in beatPolygons where sp.BeatID == beatID select sp; foreach (esriBeat eb in spList) { ESRI.ArcGIS.Client.Geometry.Polygon p = (ESRI.ArcGIS.Client.Geometry.Polygon)eb.beatData.Geometry; if (lat <= eb.maxLat && lat >= eb.minLat && lon <= eb.maxLon && lon >= eb.minLon) { /* OLD CODE WORKED MOST OF THE TIME BUT RETURNED OFF BEAT SOMETIMES WHEN A TRUCK WAS ON BEAT */ foreach (ESRI.ArcGIS.Client.Geometry.PointCollection points in p.Rings) { int i; int j = points.Count - 1; for (i = 0; i < points.Count; i++) { if (points[i].X < point.X && points[j].X >= point.X || points[j].X < point.X && points[i].X >= point.X) { if (points[i].Y + (point.X - points[i].X) / (points[j].X - points[i].X) * (points[j].Y - points[i].Y) < point.Y) { inPoly = !inPoly; } } j = i; } } foreach (PointCollection points in p.Rings) { for (int i = 0, j = points.Count - 1; i < points.Count; j = i++) { if (((points[i].Y > point.Y) != (points[j].Y > point.Y)) && (point.X < (points[j].X - points[i].X) * (point.Y - points[i].Y) / (points[j].Y - points[i].Y) + points[i].X)) { isInside = true; } } } } } return(isInside); }
public static ESRI.ArcGIS.Client.Geometry.Polygon ConvertPBSPolygonToEsriPolygon(PBS.Util.Polygon pPolygon) { ESRI.ArcGIS.Client.Geometry.Polygon ePolygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); foreach (PBS.Util.PointCollection pPC in pPolygon.Rings) { ESRI.ArcGIS.Client.Geometry.PointCollection ePC = new ESRI.ArcGIS.Client.Geometry.PointCollection(); foreach (PBS.Util.Point pPoint in pPC) { ePC.Add(new MapPoint(pPoint.X, pPoint.Y)); } ePolygon.Rings.Add(ePC); } return(ePolygon); }
/// 此方法为ArcGIS for silverlight 中根据已知点生成圆状polygon(实为点集) /// /// 360度画圆 /// /// 半径Wgs-84坐标系下1度约等于 111194.872221777米 /// 中心点即为需要生成圆的基本点 /// 返回Graphic public static Geometry GetEllipseGraphic(double radius, MapPoint centerP) { ESRI.ArcGIS.Client.Geometry.PointCollection pCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (double i = 0; i <= 360; i += 1) { pCollection.Add(new MapPoint((centerP.X - Math.Cos(Math.PI * i / 180.0) * radius), (centerP.Y - Math.Sin(Math.PI * i / 180.0) * radius))); } ESRI.ArcGIS.Client.Geometry.Polygon g = new ESRI.ArcGIS.Client.Geometry.Polygon(); g.Rings.Add(pCollection); return(g); // result.Symbol = this.LayoutRoot.Resources["DefaulFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;//这里根据自己的需要定义样式 }
private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args) { MyDrawObject.IsEnabled = false; ESRI.ArcGIS.Client.Geometry.Polygon intersectPolygon = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon; intersectPolygon.SpatialReference = MyMap.SpatialReference; List <Graphic> graphicList = new List <Graphic>(); graphicList.Add(new Graphic() { Geometry = intersectPolygon }); geometryService.SimplifyAsync(graphicList); }
private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args) { MyDrawObject.IsEnabled = false; ESRI.ArcGIS.Client.Geometry.Polygon polygon = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon; polygon.SpatialReference = MyMap.SpatialReference; geometryService.SimplifyAsync(new List <Graphic>() { new Graphic() { Geometry = polygon } }); }
// *********************************************************************************** // * ... Select facilities that intersect the affeced area on the map // *********************************************************************************** private async void selectFeaturesOnTheMap(ESRI.ArcGIS.Client.Geometry.Polygon geometry) { // Find the Selectable data sources provided by feature layers in the map widget. var dataSourcesFromSameWidget = OperationsDashboard.Instance.DataSources.Select((dataSource) => { client.FeatureLayer fl = _mapWidget.FindFeatureLayer(dataSource); return(((fl != null) && (dataSource.IsSelectable)) ? fl : null); }); IEnumerable <ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources; foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources) { client.FeatureLayer featureL = _mapWidget.FindFeatureLayer(d); if (dataSourcesFromSameWidget.Contains(featureL)) { ESRI.ArcGIS.OperationsDashboard.Query query = new ESRI.ArcGIS.OperationsDashboard.Query(); query.SpatialFilter = geometry; query.ReturnGeometry = true; query.Fields = new string[] { d.ObjectIdFieldName }; ESRI.ArcGIS.OperationsDashboard.QueryResult result = await d.ExecuteQueryAsync(query); if (result.Features.Count > 0) { // Get the array of IDs from the query results. var resultOids = from feature in result.Features select System.Convert.ToInt32(feature.Attributes[d.ObjectIdFieldName]); // For each result feature, find the corresponding graphic in the map. foreach (client.Graphic feature in featureL.Graphics) { int featureOid; int.TryParse(feature.Attributes[d.ObjectIdFieldName].ToString(), out featureOid); if (resultOids.Contains(featureOid)) { feature.Select(); } } } else if (d.IsSelectable == true) { featureL.ClearSelection(); } } } }
public static PBS.Util.Polygon ConvertEsriPolygonToPBSPolygon(ESRI.ArcGIS.Client.Geometry.Polygon ePolygon) { if (ePolygon == null) { return(null); } PBS.Util.Polygon pPolygon = new Util.Polygon(); foreach (ESRI.ArcGIS.Client.Geometry.PointCollection ePC in ePolygon.Rings) { PBS.Util.PointCollection pPC = new Util.PointCollection(); foreach (ESRI.ArcGIS.Client.Geometry.MapPoint ePoint in ePC) { pPC.Add(new PBS.Util.Point(ePoint.X, ePoint.Y)); } pPolygon.Rings.Add(pPC); } return(pPolygon); }
private void AddPolygonGraphics() { string coordinateString1 = "130,5.59 118.42,3.92 117.3,23.3 143.2,22.9 130,5.59"; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; ESRI.ArcGIS.Client.Geometry.PointCollectionConverter pointConverter = new ESRI.ArcGIS.Client.Geometry.PointCollectionConverter(); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection1 = pointConverter.ConvertFromString(coordinateString1) as ESRI.ArcGIS.Client.Geometry.PointCollection; ESRI.ArcGIS.Client.Geometry.Polygon polygon1 = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon1.Rings.Add(pointCollection1); Graphic graphic = new Graphic() { Geometry = mercator.FromGeographic(polygon1), Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol }; graphicsLayer.Graphics.Add(graphic); }
private ESRI.ArcGIS.Client.Geometry.Geometry _CreateFrameGeometry() { ESRI.ArcGIS.Client.Geometry.Geometry geometry = null; _end = new ESRI.ArcLogistics.Geometry.Point(_start.Value.X, _start.Value.Y); if (_start.HasValue && _end.HasValue) { ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); pointCollection.Add(new MapPoint(_start.Value.X, _start.Value.Y)); pointCollection.Add(new MapPoint(_start.Value.X, _end.Value.Y)); pointCollection.Add(new MapPoint(_end.Value.X, _end.Value.Y)); pointCollection.Add(new MapPoint(_end.Value.X, _start.Value.Y)); pointCollection.Add(new MapPoint(_start.Value.X, _start.Value.Y)); ESRI.ArcGIS.Client.Geometry.Polygon polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon.Rings.Add(pointCollection); geometry = (ESRI.ArcGIS.Client.Geometry.Geometry)polygon; } return(geometry); }
private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args) { MyDrawObject.IsEnabled = false; ESRI.ArcGIS.Client.Geometry.Polygon polygon = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon; polygon.SpatialReference = new SpatialReference(4326); Graphic graphic = new Graphic() { Symbol = LayoutRoot.Resources["DefaultPolygonSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol, Geometry = polygon }; graphic.Attributes.Add("X", "Label Point Polygon"); graphicsLayer.Graphics.Add(graphic); List <Graphic> graphicsList = new List <Graphic>(); graphicsList.Add(graphic); geometryService.SimplifyAsync(graphicsList); }
private void AddPolygonGraphics() { string coordinateString1 = "14819406,1294088 13066124,751406 13191358,2880391 15570812,2713412 14819406,1294088"; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; PointCollectionConverter pointConverter = new PointCollectionConverter(); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection1 = pointConverter.ConvertFromString(coordinateString1) as ESRI.ArcGIS.Client.Geometry.PointCollection; ESRI.ArcGIS.Client.Geometry.Polygon polygon1 = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon1.Rings.Add(pointCollection1); Graphic graphic = new Graphic() { Geometry = polygon1, Symbol = DefaultFillSymbol }; graphicsLayer.Graphics.Add(graphic); }
void GeometryService_DensifyCompleted(object sender, GraphicsEventArgs e) { GraphicsLayer graphicsLayerVertices = MyMap.Layers["VerticesGraphicsLayer"] as GraphicsLayer; foreach (Graphic g in e.Results) { ESRI.ArcGIS.Client.Geometry.Polygon p = g.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon; foreach (ESRI.ArcGIS.Client.Geometry.PointCollection pc in p.Rings) { foreach (MapPoint point in pc) { Graphic vertice = new Graphic() { Symbol = LayoutRoot.Resources["NewMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol, Geometry = point }; graphicsLayerVertices.Graphics.Add(vertice); } } } DensifyButton.IsEnabled = true; }
private void drawDrops(string beatNumber) { GMapOverlay polyOverlay = new GMapOverlay("drops"); List <string> drops = new List <string>(); foreach (EsriDrops.esriDrop d in EsriDrops.dropPolygons) { if (!drops.Contains(d.BeatID) && d.BeatID != "NO BEAT ID") { drops.Add(d.BeatID); } } var dList = from d in EsriDrops.dropPolygons where d.BeatID == beatNumber select d; foreach (EsriDrops.esriDrop ed in dList) { ESRI.ArcGIS.Client.Geometry.Polygon p = (ESRI.ArcGIS.Client.Geometry.Polygon)ed.dropData.Geometry; List <PointLatLng> points = new List <PointLatLng>(); foreach (PointCollection pc in p.Rings) { for (int i = 0; i < pc.Count; i++) { points.Add(new PointLatLng(pc[i].Y, pc[i].X)); } points.Add(new PointLatLng(pc[0].Y, pc[0].X)); } GMapPolygon poly = new GMapPolygon(points, "Drop " + beatNumber); poly.Fill = new SolidBrush(Color.FromArgb(50, Color.Orange)); poly.Stroke = new Pen(Color.Orange, 1); polyOverlay.Polygons.Add(poly); gMapControl1.Overlays.Add(polyOverlay); } }
private void drawBeats(string beatNumber) { GMapOverlay polyOverlay = new GMapOverlay("beats"); List <string> beats = new List <string>(); foreach (esriBeat b in EsriBeats.beatPolygons) { if (!beats.Contains(b.BeatID) && b.BeatID != "NO BEAT ID") { beats.Add(b.BeatID); } } List <PointLatLng> points = new List <PointLatLng>(); var bList = from b in EsriBeats.beatPolygons where b.BeatID == beatNumber select b; foreach (esriBeat eb in bList) { ESRI.ArcGIS.Client.Geometry.Polygon p = (ESRI.ArcGIS.Client.Geometry.Polygon)eb.beatData.Geometry; foreach (PointCollection pc in p.Rings) { for (int i = 0; i < pc.Count; i++) { points.Add(new PointLatLng(pc[i].Y, pc[i].X)); } points.Add(new PointLatLng(pc[0].Y, pc[0].X)); } GMapPolygon poly = new GMapPolygon(points, "Beat " + beatNumber); poly.Fill = new SolidBrush(Color.FromArgb(50, Color.Blue)); poly.Stroke = new Pen(Color.Red, 1); polyOverlay.Polygons.Add(poly); gMapControl1.Overlays.Add(polyOverlay); } }
private ESRI.ArcGIS.Client.Geometry.Geometry getGeometry(string geometrytype) { switch (geometrytype) { case "Point": var point = new MapPoint(-16584535.1432908, 8580553.67499035); return(point); case "Polyline": { string coordinatestring = "-16584535.1432908,8580553.67499035 -16583535.1432908,8585553.67499035 -16580535.1432908,8575553.67499035"; var pointcollection = new PointCollectionConverter().ConvertFromString(coordinatestring) as ESRI.ArcGIS.Client.Geometry.PointCollection; var polygon = new ESRI.ArcGIS.Client.Geometry.Polyline(); polygon.Paths.Add(pointcollection); return(polygon); } case "Polygon": { string coordinatestring = "-16584535.1432908,8580553.67499035 -16583535.1432908,8585553.67499035 -16580535.1432908,8575553.67499035 -16584515.1432908,8580555.67499035 -16584535.1432908,8580553.67499035"; var pointcollection = new PointCollectionConverter().ConvertFromString(coordinatestring) as ESRI.ArcGIS.Client.Geometry.PointCollection; var polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon.Rings.Add(pointcollection); return(polygon); } case "Multipoint": return(null); case "Envelope": return(null); default: return(null); } }
private void AddPolygonGraphics() { string coordinateString1 = "14819406,1294088 13066124,751406 13191358,2880391 15570812,2713412 14819406,1294088"; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; PointCollectionConverter pointConverter = new PointCollectionConverter(); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection1 = pointConverter.ConvertFromString(coordinateString1) as ESRI.ArcGIS.Client.Geometry.PointCollection; ESRI.ArcGIS.Client.Geometry.Polygon polygon1 = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon1.Rings.Add(pointCollection1); Graphic graphic = new Graphic() { Geometry = polygon1, Symbol = DefaultFillSymbol }; graphicsLayer.Graphics.Add(graphic); }
private void AddZone(Zone z) { try { var tbd = (from g in ZoneLayer.Graphics where g.Attributes.ContainsKey("poi") && (Guid)g.Attributes["poi"] == Poi.Id where g.Attributes.ContainsKey("zone") && (string)g.Attributes["zone"] == z.Title select g).ToList(); if (tbd.Any()) return; Execute.OnUIThread(() => { z.Graphic = new Graphic(); z.Graphic.Attributes["poi"] = Poi.Id; z.Graphic.Attributes["zone"] = z.Title; if (IsAreaFilled) { if (z.Color != null) { z.Graphic.Symbol = new SimpleFillSymbol { BorderBrush = Brushes.Black, BorderThickness = 2, Fill = new SolidColorBrush(z.MediaColor(0x30)) }; } var poly = new Polygon { Rings = new ObservableCollection<PointCollection> { z.Points.ToPointCollection() } }; z.Graphic.Geometry = poly; } else { if (z.Color != null) { z.Graphic.Symbol = new LineSymbol { Width = 2, Color = new SolidColorBrush(z.MediaColor()) }; } var poly = new Polyline { Paths = new ObservableCollection<PointCollection> { z.Points.ToPointCollection() } }; z.Graphic.Geometry = poly; } ZoneLayer.Graphics.Add(z.Graphic); }); } catch (Exception e) { Logger.Log("Zone Model", "Error adding zone", e.Message, Logger.Level.Error, true); } }
/// <summary> /// Search arround a point within a specific radius /// </summary> /// <param name="center">The center point</param> /// <param name="radius">Search distance in meters</param> /// <param name="where">SQL where string</param> /// <param name="outSRWKID">Buffer circle output spatial reference</param> /// <param name="toMercator">Project the buffer circle's spatial reference into Mercator</param> /// <param name="circle">Output circle shape</param> public void SearchNearby(MapPoint center, double radius, string where, int outSRWKID, bool toMercator, out ESRI.ArcGIS.Client.Geometry.Polygon circle) { circle = CreateBufferCircle(center, radius, toMercator); Search(circle, where, outSRWKID); }
/// <summary> /// Create graphics when base is web mercator /// </summary> /// <param name="rssGraphics"></param> private void AddWebMercatorGraphics(List<RssGraphic> rssGraphics) { int counter = 0; foreach (RssGraphic rssGraphic in rssGraphics) { Graphic graphic = new Graphic(); //mouse events graphic.MouseEnter += graphic_MouseEnter; graphic.MouseLeave += graphic_MouseLeave; //title graphic.Attributes.Add("Title", rssGraphic.title); //abstract string result = (Regex.Replace(rssGraphic.Description, @"<(.|\n)*?>", string.Empty)).TrimStart(new char[] { '\n' }); int loc = result.IndexOf("\n"); string abstactString = result.Substring(0, loc); if (abstactString.ToLower() == "null") { abstactString = "No description available"; } graphic.Attributes.Add("Abstract", abstactString); //magic for links happens here List<GeoLinks> links = ParseDescription(rssGraphic.Description); //links List<string> currentLinks = new List<string>(); foreach (GeoLinks link in links) { graphic.Attributes.Add(link.Title, link.Url); graphic.Attributes.Add(link.Title + "Visible", true); currentLinks.Add(link.Title); if (link.AddToMapInfo != null) { graphic.Attributes.Add("Add", link.AddToMapInfo); graphic.Attributes.Add("AddVisible", true); currentLinks.Add("Add"); } } //geometry string[] sPoints = rssGraphic.StringPolygon.Split(' '); if (counter == 6) { string aaaaa = string.Empty; } ESRI.ArcGIS.Client.Geometry.PointCollection pColl = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (int i = 0; i < sPoints.Length; i++) { MapPoint mp = new MapPoint(); double x = WebMercator.ToWebMercatorX(Convert.ToDouble(sPoints[i + 1])); double y = WebMercator.ToWebMercatorY(Convert.ToDouble(sPoints[i])); if (Double.IsNegativeInfinity(y)) y = -20000000; if (Double.IsPositiveInfinity(y)) y = 20000000; if (!IsExtremeNumber(x) && !IsExtremeNumber(y)) { mp.X = x; mp.Y = y; pColl.Add(mp); } i++; } if (pColl.Count > 0) { ESRI.ArcGIS.Client.Geometry.Polygon poly = new ESRI.ArcGIS.Client.Geometry.Polygon(); poly.Rings.Add(pColl); graphic.Geometry = poly; System.Diagnostics.Debug.WriteLine("poly: xmax: " + poly.Extent.XMax + " xmin: " + poly.Extent.XMin + " ymax: " + poly.Extent.YMax + " ymin: " + poly.Extent.YMin); _graphicsLyr.Graphics.Add(graphic); //result grid string sCleanLink = FindServiceLink(rssGraphic.Description); string sID = rssGraphic.title; sCleanLink = sCleanLink + "," + sID; _queryResultData.Add(new QueryResultData() { Title = rssGraphic.title, Description = rssGraphic.Description, IsEnable = true, graphic = graphic, sLink = sCleanLink, ID = sID }); } counter++; } UpdateUIAfterSearch(counter); }
private void map_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { e.Handled = true; Point pt = e.GetPosition(null); if (Math.Abs(pt.X - lastClick.X) < 2 && Math.Abs(pt.Y - lastClick.Y) < 2) { int lastone = GraphicsLayer.Graphics.Count - 1; GraphicsLayer.Graphics.RemoveAt(lastone); if (Type == MeasureType.Area) { ESRI.ArcGIS.Client.Geometry.Polygon poly1 = GraphicsLayer.Graphics[0].Geometry as ESRI.ArcGIS.Client.Geometry.Polygon; MapPoint firstpoint = poly1.Rings[0][0]; poly1.Rings[0].Add(new MapPoint(firstpoint.X, firstpoint.Y)); GraphicsLayer.Graphics[0].Geometry = poly1; } ResetValues(); } else { if (_points.Count == 0) { GraphicsLayer.Graphics.Clear(); if (Type == MeasureType.Area) { Graphic areaGraphic = new Graphic() { Symbol = FillSymbol }; GraphicsLayer.Graphics.Add(areaGraphic); Graphic areaTotalGraphic = new Graphic() { Symbol = new RotatingTextSymbol() }; GraphicsLayer.Graphics.Add(areaTotalGraphic); } } originPoint = Map.ScreenToMap(e.GetPosition(Map)); endPoint = Map.ScreenToMap(e.GetPosition(Map)); ESRI.ArcGIS.Client.Geometry.Polyline line = new ESRI.ArcGIS.Client.Geometry.Polyline(); ESRI.ArcGIS.Client.Geometry.PointCollection points = new ESRI.ArcGIS.Client.Geometry.PointCollection(); points.Add(originPoint); points.Add(endPoint); line.Paths.Add(points); _points.Add(endPoint); if (_points.Count == 2) { _points.Add(endPoint); } lineCount++; if (Type == MeasureType.Area && _points.Count > 2) { ESRI.ArcGIS.Client.Geometry.Polygon poly = new ESRI.ArcGIS.Client.Geometry.Polygon(); poly.Rings.Add(_points); GraphicsLayer.Graphics[0].Geometry = poly; } if (Type == MeasureType.Distance) { Graphic totalTextGraphic = new Graphic() { Geometry = originPoint, Symbol = new RotatingTextSymbol() }; GraphicsLayer.Graphics.Add(totalTextGraphic); } Graphic marker = new Graphic() { Geometry = endPoint, Symbol = markerSymbol }; GraphicsLayer.Graphics.Add(marker); Graphic lineGraphic = new Graphic() { Geometry = line, Symbol = LineSymbol }; GraphicsLayer.Graphics.Add(lineGraphic); Graphic textGraphic = new Graphic() { Geometry = endPoint, Symbol = new RotatingTextSymbol() }; textGraphic.SetZIndex(1); GraphicsLayer.Graphics.Add(textGraphic); totalLength += _segmentLength; _lengths.Add(_segmentLength); _segmentLength = 0; _isMeasuring = true; } lastClick = pt; }
private void map_MouseMove(object sender, MouseEventArgs e) { Map.Cursor = Cursors.Hand; if (originPoint != null && _isMeasuring) { _graphicCount = GraphicsLayer.Graphics.Count; int g = _graphicCount - 1; MapPoint p = Map.ScreenToMap(e.GetPosition(Map)); MapPoint midpoint = new MapPoint((p.X + originPoint.X) / 2, (p.Y + originPoint.Y) / 2); ESRI.ArcGIS.Client.Geometry.PointCollection polypoints = new ESRI.ArcGIS.Client.Geometry.PointCollection(); ESRI.ArcGIS.Client.Geometry.Polygon poly = new ESRI.ArcGIS.Client.Geometry.Polygon(); if (Type == MeasureType.Area && _points.Count > 2) { Graphic graphic = GraphicsLayer.Graphics[0]; poly = graphic.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon; polypoints = poly.Rings[0]; int lastPt = polypoints.Count - 1; polypoints[lastPt] = p; } GraphicsLayer.Graphics[g - 2].Geometry = midpoint; (GraphicsLayer.Graphics[g - 1].Geometry as ESRI.ArcGIS.Client.Geometry.Polyline).Paths[0][1] = p; GraphicsLayer.Graphics[g].Geometry = midpoint; double angle = Math.Atan2((p.X - originPoint.X), (p.Y - originPoint.Y)) / Math.PI * 180 - 90; if (angle > 90 || angle < -90) { angle -= 180; } RotatingTextSymbol symb = GraphicsLayer.Graphics[g].Symbol as RotatingTextSymbol; symb.Angle = angle; double dist = Geodesic.GetSphericalDistance(originPoint, p); double distRound = RoundToSignificantDigit(dist); symb.Text = Convert.ToString(RoundToSignificantDigit(ConvertDistance(dist, DistanceUnits))); GraphicsLayer.Graphics[g].Symbol = symb; _segmentLength = distRound; _tempTotalLength = totalLength + distRound; RotatingTextSymbol totSym; if (Type == MeasureType.Distance) { totSym = GraphicsLayer.Graphics[0].Symbol as RotatingTextSymbol; totSym.Text = string.Format("Length Total:\n{0} {1}", RoundToSignificantDigit(ConvertDistance(_tempTotalLength, DistanceUnits)), DistanceUnits.ToString()); GraphicsLayer.Graphics[0].Symbol = totSym; } else { totSym = GraphicsLayer.Graphics[1].Symbol as RotatingTextSymbol; if (polypoints != null && polypoints.Count > 2) { double lastLen = Geodesic.GetSphericalDistance(polypoints[0], polypoints[polypoints.Count - 1]); poly = GraphicsLayer.Graphics[0].Geometry as ESRI.ArcGIS.Client.Geometry.Polygon; MapPoint anchor = poly.Extent.GetCenter(); ESRI.ArcGIS.Client.Geometry.PointCollection temppoints = new ESRI.ArcGIS.Client.Geometry.PointCollection(); foreach (MapPoint point in poly.Rings[0]) { temppoints.Add(point); } temppoints.Add(poly.Rings[0][0]); ESRI.ArcGIS.Client.Geometry.PointCollection pts = ToKmMapPoint(temppoints); double area = GetArea(pts); //double area = GetArea(ToKMMapPoint(polypoints)); totSym.Text = string.Format("Area:\n{0} {1}", RoundToSignificantDigit(area), AreaUnits.ToString()); GraphicsLayer.Graphics[1].Geometry = anchor; GraphicsLayer.Graphics[1].Symbol = totSym; } } } }
private ESRI.ArcGIS.Client.Geometry.Geometry _CreateFrameGeometry() { ESRI.ArcGIS.Client.Geometry.Geometry geometry = null; _end = new ESRI.ArcLogistics.Geometry.Point(_start.Value.X, _start.Value.Y); if (_start.HasValue && _end.HasValue) { ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); pointCollection.Add(new MapPoint(_start.Value.X, _start.Value.Y)); pointCollection.Add(new MapPoint(_start.Value.X, _end.Value.Y)); pointCollection.Add(new MapPoint(_end.Value.X, _end.Value.Y)); pointCollection.Add(new MapPoint(_end.Value.X, _start.Value.Y)); pointCollection.Add(new MapPoint(_start.Value.X, _start.Value.Y)); ESRI.ArcGIS.Client.Geometry.Polygon polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon.Rings.Add(pointCollection); geometry = (ESRI.ArcGIS.Client.Geometry.Geometry)polygon; } return geometry; }
private void ConvertPolygonToGraphic(csCommon.Types.Geometries.Polygon p, PoiGraphic g) { var polygon = new Polygon(); foreach (var ls in p.LineStrings) { var pc = new PointCollection(); foreach (var point in ls.Line) { pc.Add(mercator.FromGeographic(new MapPoint(point.X, point.Y)) as MapPoint); } if (pc.First().X != pc.Last().X || pc.First().Y != pc.Last().Y) pc.Add(pc.First()); polygon.Rings.Add(pc); } g.SetGeometry(polygon); }
/// <summary> /// Convert a polyline to a graphic. /// NOTE Although we could have used a Polyline to create the graphic, it would mean that we cannot specify the fill color, /// which is why I've chosen to convert it to a Polygon. /// </summary> /// <param name="ls"></param> /// <param name="g"></param> private void ConvertPolylineToGraphic(LineString ls, PoiGraphic g) { var polygon = new Polygon(); var pc = new PointCollection(); foreach (var point in ls.Line) { pc.Add(mercator.FromGeographic(new MapPoint(point.X, point.Y)) as MapPoint); } //if (pc.First().X != pc.Last().X || pc.First().Y != pc.Last().Y) // pc.Add(pc.First()); polygon.Rings.Add(pc); g.SetGeometry(polygon); }
private void ConvertPointsToPolygon(BaseContent p, PoiGraphic g) { var pc = ConvertPointsToPointCollection(p); if (pc == null) return; var polygon = new Polygon(); pc.Add(pc[0]); // Close the loop polygon.Rings.Add(pc); g.SetGeometry(polygon); }
public void GeometryService_BufferCompleted(object sender, GraphicsEventArgs args) { try { IList <Graphic> results = args.Results; //GraphicsLayer graphicsLayer = _mapControl.Layers["BombEvacLayer"] as GraphicsLayer; SimpleFillSymbol insideSymbol = new SimpleFillSymbol() { Fill = new SolidColorBrush(Color.FromArgb(100, (byte)255, (byte)0, (byte)0)), BorderBrush = new SolidColorBrush(Color.FromArgb(100, (byte)255, (byte)0, (byte)0)), BorderThickness = 1 }; SimpleFillSymbol outsideSymbol = new SimpleFillSymbol() { Fill = new SolidColorBrush(Color.FromArgb(100, (byte)232, (byte)158, (byte)28)), BorderBrush = new SolidColorBrush(Color.FromArgb(100, (byte)232, (byte)158, (byte)28)), BorderThickness = 1 }; int count = 0; Graphic extentGraphic = null; Graphic graphic1 = new Graphic(); Graphic graphic2 = new Graphic(); foreach (Graphic graphic in results) { if (count == 1) { graphic.Symbol = outsideSymbol; outdoorPoly = graphic.Geometry as client.Geometry.Polygon; graphic.Attributes.Add("Evac", "Shelter-in-Place Zone"); graphic1 = graphic; } else { graphic.Symbol = insideSymbol; indoorPoly = graphic.Geometry as client.Geometry.Polygon; graphic.Attributes.Add("Evac", "Mandatory Evacuation Distance"); graphic2 = graphic; } count++; extentGraphic = graphic; } _graphicsLayer.Graphics.Add(graphic1); _graphicsLayer.Graphics.Add(graphic2); _mapWidget.Map.ZoomTo(extentGraphic.Geometry); callQuery = true; ////Select features using polygon //IEnumerable<ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources; //foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources) //{ // //if (d.IsSelectable) // // { // System.Diagnostics.Debug.WriteLine(d.Name); // ESRI.ArcGIS.OperationsDashboard.Query query = new ESRI.ArcGIS.OperationsDashboard.Query(); // query.SpatialFilter = outdoorPoly; // query.ReturnGeometry = true; // query.Fields = new string[] { d.ObjectIdFieldName }; // QueryResult result = await d.ExecuteQueryAsync(query); // System.Diagnostics.Debug.WriteLine("Features : " + result.Features.Count); // if (result.Features.Count > 0) // { // // Get the array of IDs from the query results. // var resultOids = from feature in result.Features select System.Convert.ToInt32(feature.Attributes[d.ObjectIdFieldName]); // // Find the map layer in the map widget that contains the data source. // MapWidget mapW = MapWidget.FindMapWidget(d); // if (mapW != null) // { // // Get the feature layer in the map for the data source. // client.FeatureLayer featureL = mapW.FindFeatureLayer(d); // // NOTE: Can check here if the feature layer is selectable, using code shown above. // // For each result feature, find the corresponding graphic in the map by OID and select it. // foreach (client.Graphic feature in featureL.Graphics) // { // int featureOid; // int.TryParse(feature.Attributes[d.ObjectIdFieldName].ToString(), out featureOid); // if (resultOids.Contains(featureOid)) // { // feature.Select(); // } // } // } // //} // } //} } catch (Exception ex) { MessageBox.Show("Error in geometry service complete: " + ex.Message); } }
private ESRI.ArcGIS.Client.Geometry.Geometry getGeometry(string geometrytype) { switch (geometrytype) { case "Point": var point = new MapPoint(-16584535.1432908, 8580553.67499035); return point; case "Polyline": { string coordinatestring = "-16584535.1432908,8580553.67499035 -16583535.1432908,8585553.67499035 -16580535.1432908,8575553.67499035"; var pointcollection = new PointCollectionConverter().ConvertFromString(coordinatestring) as ESRI.ArcGIS.Client.Geometry.PointCollection; var polygon = new ESRI.ArcGIS.Client.Geometry.Polyline(); polygon.Paths.Add(pointcollection); return polygon; } case "Polygon": { string coordinatestring = "-16584535.1432908,8580553.67499035 -16583535.1432908,8585553.67499035 -16580535.1432908,8575553.67499035 -16584515.1432908,8580555.67499035 -16584535.1432908,8580553.67499035"; var pointcollection = new PointCollectionConverter().ConvertFromString(coordinatestring) as ESRI.ArcGIS.Client.Geometry.PointCollection; var polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon.Rings.Add(pointcollection); return polygon; } case "Multipoint": return null; case "Envelope": return null; default: return null; } }
private void ConvertGeometryToPolygon(PoI p, PoiGraphic g) { var polygon = new Polygon(); if (p.Geometry is csCommon.Types.Geometries.Polygon) { var geom = p.Geometry as csCommon.Types.Geometries.Polygon; foreach (var ls in geom.LineStrings) { var pc = new PointCollection(); foreach (var ps in ls.Line) { pc.Add(mercator.FromGeographic(new MapPoint(ps.X, ps.Y)) as MapPoint); } if (pc.First().X != pc.Last().X || pc.First().Y != pc.Last().Y) pc.Add(pc.First()); polygon.Rings.Add(pc); } g.SetGeometry(polygon); } else return; }
private client.Graphic CreateFan(client.Graphic g) { try { SimpleFillSymbol _sym = new SimpleFillSymbol() { Fill = new SolidColorBrush(Color.FromArgb(100, (byte)255, (byte)190, (byte)232)), BorderBrush = new SolidColorBrush(Color.FromArgb(100, (byte)197, (byte)0, (byte)255)), BorderThickness = 1 }; client.Graphic pPolyGraphic = new client.Graphic(); if (Traversal < 360) { double initBearing = Bearing; initBearing = Geo2Arithmetic(Bearing); //Need to convert from geographic angles (zero north clockwise) to arithmetic (zero east counterclockwise) if (Traversal == 0) Traversal = 1; double leftAngle = initBearing - (Traversal / 2.0); double rightAngle = initBearing + (Traversal / 2.0); double centerpointX = g.Geometry.Extent.GetCenter().X; double centerpointY = g.Geometry.Extent.GetCenter().Y; ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection> pcol = new ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection>(); ESRI.ArcGIS.Client.Geometry.PointCollection ptCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); ptCollection.Add(g.Geometry as MapPoint); for (int i = System.Convert.ToInt16(leftAngle); i < rightAngle; i++) { double x = centerpointX + (Range * Math.Cos(DegreeToRadian(i))); double y = centerpointY + (Range * Math.Sin(DegreeToRadian(i))); ESRI.ArcGIS.Client.Geometry.MapPoint mPt = new MapPoint(x, y); ptCollection.Add(mPt); } ptCollection.Add(g.Geometry as MapPoint); ESRI.ArcGIS.Client.Geometry.Polygon pPoly = new ESRI.ArcGIS.Client.Geometry.Polygon(); pcol.Add(ptCollection); pPoly.Rings = pcol; pPolyGraphic.Geometry = pPoly; pPolyGraphic.Symbol = _sym; pPolyGraphic.Attributes.Add("Name", g.Attributes[_datasource.ObjectIdFieldName].ToString()); System.Diagnostics.Debug.WriteLine(g.Attributes[_datasource.ObjectIdFieldName].ToString()); } else { Circle pCircle = new Circle(); ESRI.ArcGIS.Client.Geometry.MapPoint mPt = new MapPoint(g.Geometry.Extent.GetCenter().X, g.Geometry.Extent.GetCenter().Y); pCircle.Center = mPt; pCircle.Radius = Range; pPolyGraphic.Symbol = _sym; pPolyGraphic.Geometry = pCircle; pPolyGraphic.Attributes.Add("Name", g.Attributes[_datasource.ObjectIdFieldName].ToString()); } return pPolyGraphic; } catch { return null; } }
public void GeometryService_BufferCompleted(object sender, GraphicsEventArgs args) { try { IList<Graphic> results = args.Results; //GraphicsLayer graphicsLayer = _mapControl.Layers["BombEvacLayer"] as GraphicsLayer; SimpleFillSymbol insideSymbol = new SimpleFillSymbol() { Fill = new SolidColorBrush(Color.FromArgb(100, (byte)255, (byte)0, (byte)0)), BorderBrush = new SolidColorBrush(Color.FromArgb(100, (byte)255, (byte)0, (byte)0)), BorderThickness = 1 }; SimpleFillSymbol outsideSymbol = new SimpleFillSymbol() { Fill = new SolidColorBrush(Color.FromArgb(100, (byte)232, (byte)158, (byte)28)), BorderBrush = new SolidColorBrush(Color.FromArgb(100, (byte)232, (byte)158, (byte)28)), BorderThickness = 1 }; int count = 0; Graphic extentGraphic = null; Graphic graphic1 = new Graphic(); Graphic graphic2 = new Graphic(); foreach (Graphic graphic in results) { if (count == 1) { graphic.Symbol = outsideSymbol; outdoorPoly = graphic.Geometry as client.Geometry.Polygon; graphic.Attributes.Add("Evac", "Shelter-in-Place Zone"); graphic1 = graphic; } else { graphic.Symbol = insideSymbol; indoorPoly = graphic.Geometry as client.Geometry.Polygon; graphic.Attributes.Add("Evac", "Mandatory Evacuation Distance"); graphic2 = graphic; } count++; extentGraphic = graphic; } _graphicsLayer.Graphics.Add(graphic1); _graphicsLayer.Graphics.Add(graphic2); _mapWidget.Map.ZoomTo(extentGraphic.Geometry); callQuery = true; ////Select features using polygon //IEnumerable<ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources; //foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources) //{ // //if (d.IsSelectable) // // { // System.Diagnostics.Debug.WriteLine(d.Name); // ESRI.ArcGIS.OperationsDashboard.Query query = new ESRI.ArcGIS.OperationsDashboard.Query(); // query.SpatialFilter = outdoorPoly; // query.ReturnGeometry = true; // query.Fields = new string[] { d.ObjectIdFieldName }; // QueryResult result = await d.ExecuteQueryAsync(query); // System.Diagnostics.Debug.WriteLine("Features : " + result.Features.Count); // if (result.Features.Count > 0) // { // // Get the array of IDs from the query results. // var resultOids = from feature in result.Features select System.Convert.ToInt32(feature.Attributes[d.ObjectIdFieldName]); // // Find the map layer in the map widget that contains the data source. // MapWidget mapW = MapWidget.FindMapWidget(d); // if (mapW != null) // { // // Get the feature layer in the map for the data source. // client.FeatureLayer featureL = mapW.FindFeatureLayer(d); // // NOTE: Can check here if the feature layer is selectable, using code shown above. // // For each result feature, find the corresponding graphic in the map by OID and select it. // foreach (client.Graphic feature in featureL.Graphics) // { // int featureOid; // int.TryParse(feature.Attributes[d.ObjectIdFieldName].ToString(), out featureOid); // if (resultOids.Contains(featureOid)) // { // feature.Select(); // } // } // } // //} // } //} } catch (Exception ex) { MessageBox.Show("Error in geometry service complete: " + ex.Message); } }
/// <summary> /// Create graphics when base is 4326 /// </summary> /// <param name="rssGraphics"></param> private void Add4326Graphics(List<RssGraphic> rssGraphics) { int counter = 0; foreach (RssGraphic rssGraphic in rssGraphics) { Graphic graphic = new Graphic(); //mouse events graphic.MouseEnter += graphic_MouseEnter; graphic.MouseLeave += graphic_MouseLeave; //title graphic.Attributes.Add("Title", rssGraphic.title); //abstract string result = (Regex.Replace(rssGraphic.Description, @"<(.|\n)*?>", string.Empty)).TrimStart(new char[] { '\n' }); int loc = result.IndexOf("\n"); string abstactString = result.Substring(0, loc); if (abstactString.ToLower() == "null") { abstactString = "No description available"; } graphic.Attributes.Add("Abstract", abstactString); //magic for links happens here List<GeoLinks> links = ParseDescription(rssGraphic.Description); //links List<string> currentLinks = new List<string>(); foreach (GeoLinks link in links) { graphic.Attributes.Add(link.Title, link.Url); graphic.Attributes.Add(link.Title + "Visible", true); currentLinks.Add(link.Title); if (link.AddToMapInfo != null) { graphic.Attributes.Add("Add", link.AddToMapInfo); graphic.Attributes.Add("AddVisible", true); currentLinks.Add("Add"); } } //geometry string[] sPoints = rssGraphic.StringPolygon.Split(' '); ESRI.ArcGIS.Client.Geometry.PointCollection pColl = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (int i = 0; i < sPoints.Length; i++) { pColl.Add(new MapPoint(Convert.ToDouble(sPoints[i + 1]), Convert.ToDouble(sPoints[i]))); i++; } ESRI.ArcGIS.Client.Geometry.Polygon poly = new ESRI.ArcGIS.Client.Geometry.Polygon(); poly.Rings.Add(pColl); graphic.Geometry = poly; System.Diagnostics.Debug.WriteLine("Graphic extent: " + graphic.Geometry.Extent); _graphicsLyr.Graphics.Add(graphic); //result grid string sCleanLink = FindServiceLink(rssGraphic.Description); string sID = rssGraphic.title; sCleanLink = sCleanLink + "," + sID; _queryResultData.Add(new QueryResultData() { Title = rssGraphic.title, Description = rssGraphic.Description, IsEnable = true, graphic = graphic, sLink = sCleanLink, ID = sID }); counter++; } UpdateUIAfterSearch(counter); }
///刘宇 private Geometry ParsefromJson(string jsonResponse) { JsonObject jsonObject = JObject.Parse(jsonResponse.ToString()) as JObject; SpatialReference pSpatial = new SpatialReference(); Geometry pGeo = null; if (jsonObject.Contains("", "")) // .ContainsKey("geometries")) { JObject jsonObjectGeo = jsonObject["geometries"] as JObject; //空间参考信息 /* if (jsonObjectGeo.ContainsKey("spatialReference")) * { * pSpatial = this.myMap.SpatialReference; * * * //JsonObject pSpatialJson =jsonObjectGeo["spatialReference"] as JsonObject; * * // if(pSpatialJson.ContainsKey("wkid")) * // { * // pSpatial.WKID = Convert.ToInt16(pSpatialJson["wkid"].ToString()); * // } * // else if(pSpatialJson.ContainsKey("wkt")) * // { * // pSpatial.WKT = pSpatialJson["wkt"].ToString(); * // } * * * * * } * */ //点线面对象,不考虑hasz和hasM if (jsonObjectGeo.ContainsKey("points")) { JValue JsonPoints = jsonObjectGeo["points"]; if (JsonPoints is JsonArray) { if (JsonPoints.Count == 1) { MapPoint pPoint = new MapPoint(); //去掉中括号 string[] pStrPoints = JsonPoints[0].ToString().Substring(1, JsonPoints[0].ToString().Length - 2).Split(','); pPoint.X = Convert.ToDouble(pStrPoints[0]); pPoint.Y = Convert.ToDouble(pStrPoints[1]); pGeo = pPoint; } //else //{ // ESRI.ArcGIS.Client.Geometry.PointCollection pPointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); // for (int i = 0; i < JsonPoints.Count; i++) // { // string pStr = JsonPoints[i].ToString(); // MapPoint pPoint = new MapPoint(); // string[] pStrPoints = JsonPoints[0].ToString().Substring(1, JsonPoints[0].ToString().Length - 2).Split(','); // pPoint.X = Convert.ToDouble(pStrPoints[0]); // pPoint.Y = Convert.ToDouble(pStrPoints[1]); // pPointCollection.Add(pPoint); // } // pGeo = pPointCollection as ESRI.ArcGIS.Client.Geometry.Geometry; //} } } else if (jsonObjectGeo.ContainsKey("paths")) { JsonValue JsonPoints = jsonObjectGeo["paths"]; ESRI.ArcGIS.Client.Geometry.Polyline pPolyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection> pPointCollection = new ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection>(); // pPolyline.Paths if (JsonPoints is JsonArray) { for (int i = 0; i < JsonPoints.Count; i++) { if (JsonPoints[i] is JsonArray) { ESRI.ArcGIS.Client.Geometry.PointCollection pPointCollections = new ESRI.ArcGIS.Client.Geometry.PointCollection(); JsonArray pInnerPoints = JsonPoints[i] as JsonArray; for (int j = 0; j < pInnerPoints.Count; j++) { string pStr = pInnerPoints[j].ToString(); string[] pStrPoints = pInnerPoints[j].ToString().Substring(1, pInnerPoints[j].ToString().Length - 2).Split(','); MapPoint pPoint = new MapPoint(); pPoint.X = Convert.ToDouble(pStrPoints[0]); pPoint.Y = Convert.ToDouble(pStrPoints[1]); pPointCollections.Add(pPoint); } pPointCollection.Add(pPointCollections); } } pPolyline.Paths = pPointCollection; pGeo = pPolyline; } } else if (jsonObjectGeo.ContainsKey("rings")) { JsonValue JsonPoints = jsonObjectGeo["rings"]; ESRI.ArcGIS.Client.Geometry.Polygon pPolygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection> pPointCollection = new ObservableCollection <ESRI.ArcGIS.Client.Geometry.PointCollection>(); if (JsonPoints is JsonArray) { for (int i = 0; i < JsonPoints.Count; i++) { if (JsonPoints[i] is JsonArray) { ESRI.ArcGIS.Client.Geometry.PointCollection pPointCollections = new ESRI.ArcGIS.Client.Geometry.PointCollection(); JsonArray pInnerPoints = JsonPoints[i] as JsonArray; for (int j = 0; j < pInnerPoints.Count; j++) { string pStr = pInnerPoints[j].ToString(); string[] pStrPoints = pInnerPoints[j].ToString().Substring(1, pInnerPoints[j].ToString().Length - 2).Split(','); MapPoint pPoint = new MapPoint(); pPoint.X = Convert.ToDouble(pStrPoints[0]); pPoint.Y = Convert.ToDouble(pStrPoints[1]); pPointCollections.Add(pPoint); } pPointCollection.Add(pPointCollections); } } pPolygon.Rings = pPointCollection; pGeo = pPolygon; } } } pGeo.SpatialReference = pSpatial; return(pGeo); }