/// <summary> /// Convert from ArcLogistics polygon to ArcGIS polygon. /// </summary> /// <param name="sourcePolygon">ArcLogistics polygon</param> /// <param name="spatialReferenceID">Map spatial reference.</param> /// <returns>ArcGIS polygon.</returns> internal static ESRI.ArcGIS.Client.Geometry.Polygon ConvertToArcGISPolygon(Polygon sourcePolygon, int?spatialReferenceID) { ESRI.ArcGIS.Client.Geometry.Polygon resultPolygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); // Project polygon from WGS84 to Web Mercator if spatial reference of map is Web Mercator. if (spatialReferenceID != null) { sourcePolygon = WebMercatorUtil.ProjectPolygonToWebMercator(sourcePolygon, spatialReferenceID.Value); } int[] groups = sourcePolygon.Groups; for (int groupIndex = 0; groupIndex < groups.Length; ++groupIndex) { ESRI.ArcLogistics.Geometry.Point[] points = sourcePolygon.GetGroupPoints(groupIndex); ESRI.ArcGIS.Client.Geometry.PointCollection pointsCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (int index = 0; index < points.Length; index++) { ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(points[index].X, points[index].Y); pointsCollection.Add(mapPoint); } resultPolygon.Rings.Add(pointsCollection); } return(resultPolygon); }
private void QueryTask_ExecuteCompleted(object sender, QueryEventArgs args) { if (_originPoint == null) { return; } double searchDistance = (double)args.UserState; double x = _originPoint.X; double y = _originPoint.Y; Int32 id = 0; if (args.FeatureSet.Features.Count > 0) { foreach (Graphic feature in args.FeatureSet.Features) { // test type of feature, and test it's end points. if (feature.Geometry is ESRI.ArcGIS.Client.Geometry.Polygon) { ESRI.ArcGIS.Client.Geometry.Polygon featurePolygon = feature.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon; foreach (ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection in featurePolygon.Rings) { AddLineSegmentToCache(pointCollection, x, y, searchDistance, ref id); } } else if (feature.Geometry is ESRI.ArcGIS.Client.Geometry.Polyline) { ESRI.ArcGIS.Client.Geometry.Polyline featurePolyline = feature.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline; foreach (ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection in featurePolyline.Paths) { AddLineSegmentToCache(pointCollection, x, y, searchDistance, ref id); } } else if (feature.Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint) { ESRI.ArcGIS.Client.Geometry.MapPoint featurePoint = feature.Geometry as ESRI.ArcGIS.Client.Geometry.MapPoint; double distance = GeometryUtil.LineLength(x, y, featurePoint); if (distance < searchDistance) { _snapObjects[id++] = feature.Geometry; } } } } System.Diagnostics.Debug.WriteLine("Async: Number of objects cached: " + args.FeatureSet.Features.Count.ToString()); CalculateAndAddLineGraphics(); // We need to redraw, so we get the right snap marker }
public static ESRI.ArcGIS.Client.Geometry.Polygon FromIMSToPolygon(XElement item) { ESRI.ArcGIS.Client.Geometry.Polygon poly = new ESRI.ArcGIS.Client.Geometry.Polygon(); var Rings = from ring in item.Element("POLYGON").Descendants("RING") select ring; foreach (var ring in Rings) { List<ImsPoints> Points = (from point in ring.Descendants("POINT") select new ImsPoints { X = point.Attribute("x").Value, Y = point.Attribute("y").Value, }).ToList(); ESRI.ArcGIS.Client.Geometry.PointCollection pointcollection = GetPoints(Points); poly.Rings.Add(pointcollection); } return poly; }
public static ESRI.ArcGIS.Client.Geometry.Polygon FromIMSToPolygon(XElement item) { ESRI.ArcGIS.Client.Geometry.Polygon poly = new ESRI.ArcGIS.Client.Geometry.Polygon(); var Rings = from ring in item.Element("POLYGON").Descendants("RING") select ring; foreach (var ring in Rings) { List <ImsPoints> Points = (from point in ring.Descendants("POINT") select new ImsPoints { X = point.Attribute("x").Value, Y = point.Attribute("y").Value, }).ToList(); ESRI.ArcGIS.Client.Geometry.PointCollection pointcollection = GetPoints(Points); poly.Rings.Add(pointcollection); } return(poly); }
private void MarkerSymbols_QueryTask_ExecuteCompleted(object sender, QueryEventArgs e) { //Create centroid for all US States FeatureSet featureSet = e.FeatureSet; GraphicsLayer graphicsLayer = null; // layerDemo6.Layer as GraphicsLayer; if (featureSet != null && featureSet.Features.Count > 0) { foreach (Graphic feature in featureSet.Features) { ESRI.ArcGIS.Client.Geometry.Polygon polygon = feature.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon; if (polygon == null) { return; } polygon.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326); Graphic graphic; //Getting the center point of the polygon MBR: ESRI.ArcGIS.Client.Geometry.MapPoint featureCentroid = feature.Geometry.Extent.GetCenter(); bool pointInPolygon = featureCentroid.IsWithin(polygon); if (pointInPolygon) { graphic = new Graphic() { Geometry = featureCentroid, }; } else { graphic = new Graphic() { Geometry = polygon, Symbol = null }; } //Assigning attributes from the feature to the graphic: foreach (string key in feature.Attributes.Keys) { //for (int i = 0; i < pieChartMarkerSymbol.Fields.Count; i++) //{ // if (pieChartMarkerSymbol.Fields[i].FieldName == key) // graphic.Attributes.Add(key, feature.Attributes[key]); //} } graphicsLayer.Graphics.Add(graphic); //Using the geometry service to find a new centroid in the case the //calculated centroid is not inside of the polygon: if (!pointInPolygon) { GeometryService geometryService = new GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); List <Graphic> graphicsList = new List <Graphic>(); graphicsList.Add(graphic); geometryService.LabelPointsCompleted += MarkerSymbols_GeometryService_LabelPointsCompleted; geometryService.LabelPointsAsync(graphicsList); } } } }
/// <summary> /// Calling the rest end points for the GP /// </summary> /// <param name="myConfigToDownload"></param> private void DownloadDataGP(OsmConfig myConfigToDownload) { string sPort = ":6080"; string sGpUrl = string.Empty; if (Request != null) { sGpUrl = "http://" + Request.Url.Host + sPort + "/" + System.Configuration.ConfigurationManager.AppSettings["ArcGISInstance"].ToString() + "/rest/services/OSM_on_AGS/GPServer/Download%20OSM%20Data%20Serverside"; } else { string smyHost = myConfigToDownload.FeatureService.Substring(0, myConfigToDownload.FeatureService.ToLower().IndexOf("/arcgis/rest")); sGpUrl = smyHost + "/" + System.Configuration.ConfigurationManager.AppSettings["ArcGISInstance"].ToString() + "/rest/services/OSM_on_AGS/GPServer/Download%20OSM%20Data%20Serverside"; } ESRI.ArcGIS.Client.Tasks.Geoprocessor geoprocessorTask = new ESRI.ArcGIS.Client.Tasks.Geoprocessor(sGpUrl); List<ESRI.ArcGIS.Client.Tasks.GPParameter> parameters = new List<ESRI.ArcGIS.Client.Tasks.GPParameter>(); string[] myExtent = myConfigToDownload.Extent.Split(','); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollect = new ESRI.ArcGIS.Client.Geometry.PointCollection(); // X1 Y1 pointCollect.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[0])), WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[1])))); // X2 Y1 pointCollect.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[2])), WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[1])))); // X2 Y2 pointCollect.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[2])), WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[3])))); // X1 Y2 pointCollect.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[0])), WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[3])))); // X1 Y1 pointCollect.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[0])), WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[1])))); ESRI.ArcGIS.Client.Geometry.Polygon polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon.Rings.Add(pointCollect); polygon.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326); parameters.Add(new ESRI.ArcGIS.Client.Tasks.GPFeatureRecordSetLayer("Feature_Set", polygon)); parameters.Add(new ESRI.ArcGIS.Client.Tasks.GPString("Name_of_OSM_Dataset", myConfigToDownload.FeatureDataSet)); AppLogs logs = new AppLogs(); ESRI.ArcGIS.Client.Tasks.GPExecuteResults results = null; ESRI.ArcGIS.Client.Tasks.JobInfo info = null; try { //results = geoprocessorTask.Execute(parameters); info = geoprocessorTask.SubmitJob(parameters); } catch (Exception e) { logs.AddLog("DOWNLOADLOGS", "Exception " + e.Message); if ( info != null ) { for (int i = 0; i < info.Messages.Count; i++) logs.AddLog("DOWNLOADLOGS", "Exception: DownloadDataGP messages " + info.Messages[i].Description); } //logs.AddLog("DOWNLOADLOGS", "JobWaiting " + info.Messages[info.Messages.Count-1].Description); } while (info.JobStatus != ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobSucceeded && info.JobStatus != ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobFailed) { Thread.Sleep(2000); info = geoprocessorTask.CheckJobStatus(info.JobId); } if (info.JobStatus == ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobFailed) { for (int i = 0; i < info.Messages.Count; i++) { logs.AddLog("DOWNLOADLOGS", "JobFailed: DownloadDataGP messages " + info.Messages[i].Description); } throw new ApplicationException("JobFailed: Please view logs for details"); } }
public static bool Contains(this ESRI.ArcGIS.Client.Geometry.Polygon polygon, ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint) { return(mapPoint.IsWithin(polygon)); }
/// <summary> /// Utility function to determine whether a map point is inside of a given polygon /// </summary> /// <param name="polygon"></param> /// <param name="mapPoint"></param> /// <returns></returns> public static bool IsWithin(this ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint, ESRI.ArcGIS.Client.Geometry.Polygon polygon) { foreach (ESRI.ArcGIS.Client.Geometry.PointCollection points in polygon.Rings) { int j = points.Count - 1; bool inPoly = false; for (int i = 0; i < points.Count; i++) { if (points[i].X < mapPoint.X && points[j].X >= mapPoint.X || points[j].X < mapPoint.X && points[i].X >= mapPoint.X) { if (points[i].Y + (mapPoint.X - points[i].X) / (points[j].X - points[i].X) * (points[j].Y - points[i].Y) < mapPoint.Y) { inPoly = !inPoly; } } j = i; } if (inPoly) { return(true); } } return(false); }
/// <summary> /// Check rectangle intersects with geometry. /// </summary> /// <param name="frame">Rectangle.</param> /// <param name="geometry">Geometry to check.</param> /// <returns>True if intersects</returns> public static bool IsIntersects(ESRI.ArcGIS.Client.Geometry.Envelope frame, ESRI.ArcGIS.Client.Geometry.Geometry geometry) { bool isIntersects = false; if (geometry is ESRI.ArcGIS.Client.Geometry.MapPoint) { ESRI.ArcGIS.Client.Geometry.MapPoint point = (ESRI.ArcGIS.Client.Geometry.MapPoint)geometry; if (frame.Extent.Intersects(point.Extent)) { isIntersects = true; } } else if (geometry is ESRI.ArcGIS.Client.Geometry.Polyline) { ESRI.ArcGIS.Client.Geometry.Polyline polyline = (ESRI.ArcGIS.Client.Geometry.Polyline)geometry; if (frame.Extent.Intersects(polyline.Extent)) { foreach (ESRI.ArcGIS.Client.Geometry.PointCollection points in polyline.Paths) { ESRI.ArcGIS.Client.Geometry.MapPoint prevPoint = null; foreach (ESRI.ArcGIS.Client.Geometry.MapPoint point in points) { if (prevPoint != null) { if (_IsSegmentIntersectRectangle(frame.XMin, frame.YMin, frame.XMax, frame.YMax, point.X, point.Y, prevPoint.X, prevPoint.Y)) { isIntersects = true; break; } } prevPoint = point; } if (isIntersects) { break; } } } } else if (geometry is ESRI.ArcGIS.Client.Geometry.Polygon) { ESRI.ArcGIS.Client.Geometry.Polygon polygon = (ESRI.ArcGIS.Client.Geometry.Polygon)geometry; if (frame.Extent.Intersects(polygon.Extent)) { foreach (ESRI.ArcGIS.Client.Geometry.PointCollection points in polygon.Rings) { ESRI.ArcGIS.Client.Geometry.MapPoint prevPoint = null; foreach (ESRI.ArcGIS.Client.Geometry.MapPoint point in points) { if (prevPoint != null) { if (_IsSegmentIntersectRectangle(frame.XMin, frame.YMin, frame.XMax, frame.YMax, point.X, point.Y, prevPoint.X, prevPoint.Y)) { isIntersects = true; break; } } prevPoint = point; } if (isIntersects) { break; } } } } else { Debug.Assert(false); } return(isIntersects); }
/// <summary> /// Calling the rest end points for the GP /// </summary> /// <param name="myConfigToDownload"></param> private void DownloadDataGP(OsmConfig myConfigToDownload) { WebClient client = new WebClient(); // This assumes is port 80 string sGpUrl = "http://" + Request.Url.Host + "/" + System.Configuration.ConfigurationManager.AppSettings["ArcGISInstance"].ToString() + "/rest/services/OSM_on_AGS/GPServer/Download%20OSM%20Data%20Serverside"; ESRI.ArcGIS.Client.Tasks.Geoprocessor geoprocessorTask = new ESRI.ArcGIS.Client.Tasks.Geoprocessor(sGpUrl); List <ESRI.ArcGIS.Client.Tasks.GPParameter> parameters = new List <ESRI.ArcGIS.Client.Tasks.GPParameter>(); string[] myExtent = myConfigToDownload.Extent.Split(','); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollect = new ESRI.ArcGIS.Client.Geometry.PointCollection(); // X1 Y1 pointCollect.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[0])), WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[1])))); // X2 Y1 pointCollect.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[2])), WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[1])))); // X2 Y2 pointCollect.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[2])), WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[3])))); // X1 Y2 pointCollect.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[0])), WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[3])))); // X1 Y1 pointCollect.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(WebMercator.FromWebMercatorX(Convert.ToDouble(myExtent[0])), WebMercator.FromWebMercatorY(Convert.ToDouble(myExtent[1])))); ESRI.ArcGIS.Client.Geometry.Polygon polygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); polygon.Rings.Add(pointCollect); polygon.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326); parameters.Add(new ESRI.ArcGIS.Client.Tasks.GPFeatureRecordSetLayer("Feature_Set", polygon)); parameters.Add(new ESRI.ArcGIS.Client.Tasks.GPString("Name_of_OSM_Dataset", myConfigToDownload.FeatureDataSet)); AppLogs logs = new AppLogs(); ESRI.ArcGIS.Client.Tasks.JobInfo info = null; try { info = geoprocessorTask.SubmitJob(parameters); } catch (Exception e) { logs.AddLog("DOWNLOADLOGS", "Exception " + e.Message); if (info != null) { for (int i = 0; i < info.Messages.Count; i++) { logs.AddLog("DOWNLOADLOGS", "Exception: DownloadDataGP messages " + info.Messages[i].Description); } } } while (info.JobStatus != ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobSucceeded && info.JobStatus != ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobFailed) { Thread.Sleep(2000); info = geoprocessorTask.CheckJobStatus(info.JobId); } if (info.JobStatus == ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobFailed) { for (int i = 0; i < info.Messages.Count; i++) { logs.AddLog("DOWNLOADLOGS", "JobFailed: DownloadDataGP messages " + info.Messages[i].Description); } throw new ApplicationException("JobFailed: Please view logs for details"); } }
/// <summary> /// Convert from ArcLogistics polygon to ArcGIS polygon. /// </summary> /// <param name="sourcePolygon">ArcLogistics polygon</param> /// <param name="spatialReferenceID">Map spatial reference.</param> /// <returns>ArcGIS polygon.</returns> internal static ESRI.ArcGIS.Client.Geometry.Polygon ConvertToArcGISPolygon(Polygon sourcePolygon, int? spatialReferenceID) { ESRI.ArcGIS.Client.Geometry.Polygon resultPolygon = new ESRI.ArcGIS.Client.Geometry.Polygon(); // Project polygon from WGS84 to Web Mercator if spatial reference of map is Web Mercator. if (spatialReferenceID != null) { sourcePolygon = WebMercatorUtil.ProjectPolygonToWebMercator(sourcePolygon, spatialReferenceID.Value); } int[] groups = sourcePolygon.Groups; for (int groupIndex = 0; groupIndex < groups.Length; ++groupIndex) { ESRI.ArcLogistics.Geometry.Point[] points = sourcePolygon.GetGroupPoints(groupIndex); ESRI.ArcGIS.Client.Geometry.PointCollection pointsCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); for (int index = 0; index < points.Length; index++) { ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(points[index].X, points[index].Y); pointsCollection.Add(mapPoint); } resultPolygon.Rings.Add(pointsCollection); } return resultPolygon; }