/// <summary> /// Convert from ArcLogistics polyline to ArcGIS polyline. /// </summary> /// <param name="sourcePolyline">ArcLogistics polyline</param> /// <param name="spatialReferenceID">Map spatial reference.</param> /// <returns>ArcGIS polyline.</returns> internal static ESRI.ArcGIS.Client.Geometry.Geometry ConvertToArcGISPolyline(Polyline sourcePolyline, int?spatialReferenceID) { ESRI.ArcGIS.Client.Geometry.Polyline resultPolyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); // Project polyline from WGS84 to Web Mercator if spatial reference of map is Web Mercator. if (spatialReferenceID != null) // REV: comapre with specific Web Mercator WKID, instead of null. { sourcePolyline = WebMercatorUtil.ProjectPolylineToWebMercator(sourcePolyline, spatialReferenceID.Value); } int[] groups = sourcePolyline.Groups; for (int groupIndex = 0; groupIndex < groups.Length; ++groupIndex) { ESRI.ArcLogistics.Geometry.Point[] points = sourcePolyline.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); } resultPolyline.Paths.Add(pointsCollection); } return(resultPolyline); }
/// <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 bool SnapPointToCacheObjects(ESRI.ArcGIS.Client.Geometry.MapPoint point, bool skipZeroDistance, out ESRI.ArcGIS.Client.Geometry.Polyline snapLine) { snapLine = null; // default return arg. ESRI.ArcGIS.Client.Geometry.Polyline bestSnapLine = null; double shortestDistance = double.MaxValue; Int32 oid = -1; foreach (KeyValuePair <Int32, ESRI.ArcGIS.Client.Geometry.Geometry> kvp in _snapObjects) { if (-1 == kvp.Key) // this should not happen { continue; } ESRI.ArcGIS.Client.Geometry.Polyline line = kvp.Value as ESRI.ArcGIS.Client.Geometry.Polyline; if (line != null) { ESRI.ArcGIS.Client.Geometry.PointCollection pathPoints = line.Paths.First(); double distance; if (GeometryUtil.FindPerpendicularDistance(line, point, out distance) && (distance <= _xmlConfiguation.SnapTolerance)) { if ((distance < shortestDistance) && (!(skipZeroDistance && (distance == 0)))) { oid = kvp.Key; bestSnapLine = line; shortestDistance = distance; } } } /* For now we don't snap to points * This does not play well with scale or rotate on its own, as * it will want to pull the geometry in the other action (rotate or scale) also. * * ESRI.ArcGIS.Client.Geometry.MapPoint cachePoint = kvp.Value as ESRI.ArcGIS.Client.Geometry.MapPoint; * if (cachePoint != null) * { * double distance = GeometryUtil.LineLength(cachePoint, point); * if ((distance < shortestDistance) && (!(skipZeroDistance && (distance == 0)))) * { * oid = kvp.Key; * bestSnapLine = null; * shortestDistance = distance; * } * } */ } if (oid != -1) { snapLine = bestSnapLine; return(true); } return(false); }
/// <summary> /// React on polygon tool complete. /// </summary> /// <param name="sender">Ignored.</param> /// <param name="e">Ignored.</param> private void _PolygonToolOnComplete(object sender, EventArgs e) { if (_dataGridControl.SelectedItems.Count == 1 || _currentItem != null) { Debug.Assert(_polygonTool.Geometry.Rings.Count == 1); ESRI.ArcGIS.Client.Geometry.PointCollection pointsCollection = _polygonTool.Geometry.Rings[0]; ESRI.ArcLogistics.Geometry.Point[] points = new Point[pointsCollection.Count]; for (int index = 0; index < pointsCollection.Count; index++) { ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = pointsCollection[index]; Point point = new Point(mapPoint.X, mapPoint.Y); // Project point from Web Mercator to WGS84 if spatial reference of map is Web Mercator. if (_mapCtrl.Map.SpatialReferenceID.HasValue) { point = WebMercatorUtil.ProjectPointFromWebMercator(point, _mapCtrl.Map.SpatialReferenceID.Value); } points[index] = point; } if (_isInEditedMode) { _mapCtrl.ClearEditMarkers(); } ESRI.ArcLogistics.Geometry.Polygon polygon = new Polygon(points); if (_type == typeof(Zone)) { Zone zone = (Zone)_currentItem; zone.Geometry = polygon; } else { Barrier barrier = (Barrier)_currentItem; barrier.Geometry = polygon; _ShowBarrierEditor(barrier, polygon.GetPoint(polygon.TotalPointCount - 1)); } App.Current.Project.Save(); if (_isInEditedMode) { _mapCtrl.FillEditMarkers(_currentItem); } _mapCtrl.map.UpdateLayout(); } }
static public ESRI.ArcGIS.Client.Geometry.Polyline Line(ESRI.ArcGIS.Client.Geometry.MapPoint startPoint, ESRI.ArcGIS.Client.Geometry.MapPoint endPoint) { ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); pointCollection.Add(startPoint); pointCollection.Add(endPoint); ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); polyline.Paths.Add(pointCollection); return(polyline); }
private static ESRI.ArcGIS.Client.Geometry.PointCollection GetPoints(List <ImsPoints> points) { ESRI.ArcGIS.Client.Geometry.PointCollection pointcollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); foreach (var po in points) { ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(Convert.ToDouble(po.X, System.Globalization.CultureInfo.CurrentCulture), Convert.ToDouble(po.Y, System.Globalization.CultureInfo.CurrentCulture)); pointcollection.Add(mapPoint); } return(pointcollection); }
/// <summary> /// React on polyline tool complete. /// </summary> /// <param name="sender">Ignored.</param> /// <param name="e">Ignored.</param> private void _PolylineToolOnComplete(object sender, EventArgs e) { if (_dataGridControl.SelectedItems.Count == 1 || _currentItem != null) { Debug.Assert(_polylineTool.Geometry.Paths.Count == 1); ESRI.ArcGIS.Client.Geometry.PointCollection pointsCollection = _polylineTool.Geometry.Paths[0]; ESRI.ArcLogistics.Geometry.Point[] points = new Point[pointsCollection.Count]; for (int index = 0; index < pointsCollection.Count; index++) { ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = pointsCollection[index]; Point point = new Point(mapPoint.X, mapPoint.Y); // Project point from Web Mercator to WGS84 if spatial reference of map is Web Mercator. if (_mapCtrl.Map.SpatialReferenceID.HasValue) { point = WebMercatorUtil.ProjectPointFromWebMercator(point, _mapCtrl.Map.SpatialReferenceID.Value); } points[index] = point; } if (_isInEditedMode) { _mapCtrl.ClearEditMarkers(); } ESRI.ArcLogistics.Geometry.Polyline polyline = new Polyline(points); Barrier barrier = (Barrier)_currentItem; barrier.Geometry = polyline; barrier.BarrierEffect.BlockTravel = true; // Save this polyline as initial geometry. _initialGeometry = polyline; App.Current.Project.Save(); if (_isInEditedMode) { _mapCtrl.FillEditMarkers(_currentItem); } _mapCtrl.map.UpdateLayout(); } }
static public ESRI.ArcGIS.Client.Geometry.Polyline Line(ESRI.ArcGIS.Client.Geometry.MapPoint startPoint, double bearing, double distance, out ESRI.ArcGIS.Client.Geometry.MapPoint endPoint) { endPoint = null; if (distance == 0) { return(null); } endPoint = ConstructPoint(startPoint, bearing, distance); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); pointCollection.Add(startPoint); pointCollection.Add(endPoint); ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); polyline.Paths.Add(pointCollection); return(polyline); }
private void AddLineSegmentToCache(ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection, double x, double y, double searchDistance, ref Int32 id) { double distance; ESRI.ArcGIS.Client.Geometry.MapPoint lastPoint = null; ESRI.ArcGIS.Client.Geometry.MapPoint originPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(x, y); foreach (ESRI.ArcGIS.Client.Geometry.MapPoint featurePoint in pointCollection) { if (lastPoint != null) { ESRI.ArcGIS.Client.Geometry.Polyline snapLine = GeometryUtil.Line(lastPoint, featurePoint); if (GeometryUtil.FindPerpendicularDistance(snapLine, originPoint, out distance)) { if (distance < searchDistance) { _snapObjects[id++] = snapLine; } } } lastPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(featurePoint.X, featurePoint.Y); } }
public static ESRI.ArcGIS.Client.Geometry.Polyline CreateGeoForZoom(ESRI.ArcGIS.Client.Geometry.Geometry mp) { ESRI.ArcGIS.Client.Geometry.MapPoint mp1 = new ESRI.ArcGIS.Client.Geometry.MapPoint() { X = (mp as ESRI.ArcGIS.Client.Geometry.MapPoint).X + 10000, Y = (mp as ESRI.ArcGIS.Client.Geometry.MapPoint).Y + 10000 }; ESRI.ArcGIS.Client.Geometry.MapPoint mp2 = new ESRI.ArcGIS.Client.Geometry.MapPoint() { X = (mp as ESRI.ArcGIS.Client.Geometry.MapPoint).X - 10000, Y = (mp as ESRI.ArcGIS.Client.Geometry.MapPoint).Y - 10000 }; System.Collections.ObjectModel.ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection> path = new System.Collections.ObjectModel.ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection>(); ESRI.ArcGIS.Client.Geometry.PointCollection plist = new ESRI.ArcGIS.Client.Geometry.PointCollection(); plist.Add(mp2 as ESRI.ArcGIS.Client.Geometry.MapPoint); plist.Add(mp1); path.Add(plist); ESRI.ArcGIS.Client.Geometry.Polyline pl = new ESRI.ArcGIS.Client.Geometry.Polyline { Paths = path }; return pl; }
public static ESRI.ArcGIS.Client.Geometry.Polyline FromIMSToPolyline(XElement item) { ESRI.ArcGIS.Client.Geometry.Polyline poly = new ESRI.ArcGIS.Client.Geometry.Polyline(); var Paths = from path in item.Element("POLYLINE").Descendants("PATH") select path; foreach (var path in Paths) { List <ImsPoints> Points = (from point in path.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.Paths.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); }
// Create an ESRI polyline based on a densified representation of WPFs ArcSegment static public ESRI.ArcGIS.Client.Geometry.Polyline ConstructArcSegment(ESRI.ArcGIS.Client.Geometry.MapPoint startPoint, ESRI.ArcGIS.Client.Geometry.MapPoint endPoint, double radius, bool isMinor, SweepDirection direction) { if (endPoint == null) { return(null); } // WPF ArcSegment has issue with high coordinates values. // Bring coordinates down to 0,0 and translate back to real world later. double startX = startPoint.X; double startY = startPoint.Y; double absRadius = Math.Abs(radius); // We need to switch the curve direction, b/c we are starting with the end point if (radius > 0) { direction = direction == SweepDirection.Clockwise ? SweepDirection.Counterclockwise : SweepDirection.Clockwise; } Size radiusAspect = new Size(absRadius, absRadius); Point myEndPoint = new Point(endPoint.X - startX, endPoint.Y - startY); bool isLargeArc = !isMinor; ArcSegment wpfArcSegment = new ArcSegment(myEndPoint, radiusAspect, 0, isLargeArc, direction, false); // compose one or more segments into a collection var pathcoll = new PathSegmentCollection(); pathcoll.Add(wpfArcSegment); // create a figure based on the set of segments var pathFigure = new PathFigure(); pathFigure.Segments = pathcoll; pathFigure.IsClosed = false; // compose a collection of figures var figureCollection = new PathFigureCollection(); figureCollection.Add(pathFigure); // create a path-geometry using the figures collection var geometryPath = new PathGeometry(figureCollection); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); double numSegments = 1.0 / 50; // Default 50 Point point, tangent; Point pointA, pointB; geometryPath.GetPointAtFractionLength(0, out pointA, out tangent); geometryPath.GetPointAtFractionLength(numSegments, out pointB, out tangent); double partDistance = LineLength(pointA.X, pointA.Y, pointB.X, pointB.Y); if (partDistance > 1.0) { numSegments /= partDistance; } if (1 / numSegments > 160) // cap it at 160 vertexes { numSegments = 1.0 / 160; // Server is having issue with 185+ vertexes (180 seems ok) } for (double fraction = 0.0; fraction < 1.0; fraction += numSegments) { geometryPath.GetPointAtFractionLength(fraction, out point, out tangent); pointCollection.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(point.X + startX, point.Y + startY)); } pointCollection.Add(endPoint); // faction 1 can be skipped, so add it here. ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); polyline.Paths.Add(pointCollection); return(polyline); }
/// <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; }
public static ESRI.ArcGIS.Client.Geometry.Polyline Line(ESRI.ArcGIS.Client.Geometry.MapPoint startPoint, ESRI.ArcGIS.Client.Geometry.MapPoint endPoint) { ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); pointCollection.Add(startPoint); pointCollection.Add(endPoint); ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); polyline.Paths.Add(pointCollection); return polyline; }
/// <summary> /// Convert from ArcLogistics polyline to ArcGIS polyline. /// </summary> /// <param name="sourcePolyline">ArcLogistics polyline</param> /// <param name="spatialReferenceID">Map spatial reference.</param> /// <returns>ArcGIS polyline.</returns> internal static ESRI.ArcGIS.Client.Geometry.Geometry ConvertToArcGISPolyline(Polyline sourcePolyline, int? spatialReferenceID) { ESRI.ArcGIS.Client.Geometry.Polyline resultPolyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); // Project polyline from WGS84 to Web Mercator if spatial reference of map is Web Mercator. if (spatialReferenceID != null) // REV: comapre with specific Web Mercator WKID, instead of null. { sourcePolyline = WebMercatorUtil.ProjectPolylineToWebMercator(sourcePolyline, spatialReferenceID.Value); } int[] groups = sourcePolyline.Groups; for (int groupIndex = 0; groupIndex < groups.Length; ++groupIndex) { ESRI.ArcLogistics.Geometry.Point[] points = sourcePolyline.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); } resultPolyline.Paths.Add(pointsCollection); } return resultPolyline; }
// Create an ESRI polyline based on a densified representation of WPFs ArcSegment public static ESRI.ArcGIS.Client.Geometry.Polyline ConstructArcSegment(ESRI.ArcGIS.Client.Geometry.MapPoint startPoint, ESRI.ArcGIS.Client.Geometry.MapPoint endPoint, double radius, bool isMinor, SweepDirection direction) { if (endPoint == null) return null; // WPF ArcSegment has issue with high coordinates values. // Bring coordinates down to 0,0 and translate back to real world later. double startX = startPoint.X; double startY = startPoint.Y; double absRadius = Math.Abs(radius); // We need to switch the curve direction, b/c we are starting with the end point if (radius > 0) direction = direction == SweepDirection.Clockwise ? SweepDirection.Counterclockwise : SweepDirection.Clockwise; Size radiusAspect = new Size(absRadius, absRadius); Point myEndPoint = new Point(endPoint.X - startX, endPoint.Y - startY); bool isLargeArc = !isMinor; ArcSegment wpfArcSegment = new ArcSegment(myEndPoint, radiusAspect, 0, isLargeArc, direction, false); // compose one or more segments into a collection var pathcoll = new PathSegmentCollection(); pathcoll.Add(wpfArcSegment); // create a figure based on the set of segments var pathFigure = new PathFigure(); pathFigure.Segments = pathcoll; pathFigure.IsClosed = false; // compose a collection of figures var figureCollection = new PathFigureCollection(); figureCollection.Add(pathFigure); // create a path-geometry using the figures collection var geometryPath = new PathGeometry(figureCollection); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); double numSegments = 1.0 / 50; // Default 50 Point point, tangent; Point pointA, pointB; geometryPath.GetPointAtFractionLength(0, out pointA, out tangent); geometryPath.GetPointAtFractionLength(numSegments, out pointB, out tangent); double partDistance = LineLength(pointA.X, pointA.Y, pointB.X, pointB.Y); if (partDistance > 1.0) numSegments /= partDistance; if (1 / numSegments > 160) // cap it at 160 vertexes numSegments = 1.0 / 160; // Server is having issue with 185+ vertexes (180 seems ok) for (double fraction = 0.0; fraction < 1.0; fraction += numSegments) { geometryPath.GetPointAtFractionLength(fraction, out point, out tangent); pointCollection.Add(new ESRI.ArcGIS.Client.Geometry.MapPoint(point.X + startX, point.Y + startY)); } pointCollection.Add(endPoint); // faction 1 can be skipped, so add it here. ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); polyline.Paths.Add(pointCollection); return polyline; }
public static ESRI.ArcGIS.Client.Geometry.Polyline Line(ESRI.ArcGIS.Client.Geometry.MapPoint startPoint, double bearing, double distance, out ESRI.ArcGIS.Client.Geometry.MapPoint endPoint) { endPoint = null; if (distance == 0) return null; endPoint = ConstructPoint(startPoint, bearing, distance); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); pointCollection.Add(startPoint); pointCollection.Add(endPoint); ESRI.ArcGIS.Client.Geometry.Polyline polyline = new ESRI.ArcGIS.Client.Geometry.Polyline(); polyline.Paths.Add(pointCollection); return polyline; }
static public bool ConstructPointLineLineIntersection(ESRI.ArcGIS.Client.Geometry.Polyline line1, ESRI.ArcGIS.Client.Geometry.Polyline line2, out ESRI.ArcGIS.Client.Geometry.MapPoint intersectionPoint) { intersectionPoint = null; if ((line1 == null) || (line2 == null)) { return(false); } // Check if line is 2 point. if ((line1.Paths.Count == 0) || (line2.Paths.Count == 0)) { return(false); } // For now we are only going to look at the first segment. ESRI.ArcGIS.Client.Geometry.PointCollection pathPoints1 = line1.Paths.First(); ESRI.ArcGIS.Client.Geometry.PointCollection pathPoints2 = line2.Paths.First(); Int32 pathPoint1Count = pathPoints1.Count; Int32 pathPoint2Count = pathPoints2.Count; if ((pathPoint1Count < 1) || (pathPoint2Count < 1)) { return(false); } // Used the following http://en.wikipedia.org/wiki/Line-line_intersection ESRI.ArcGIS.Client.Geometry.MapPoint point1f = pathPoints1[0]; ESRI.ArcGIS.Client.Geometry.MapPoint point1t = pathPoints1[pathPoint1Count - 1]; ESRI.ArcGIS.Client.Geometry.MapPoint point2f = pathPoints2[0]; ESRI.ArcGIS.Client.Geometry.MapPoint point2t = pathPoints2[pathPoint2Count - 1]; double x1 = point1f.X; double y1 = point1f.Y; double x2 = point1t.X; double y2 = point1t.Y; double x3 = point2f.X; double y3 = point2f.Y; double x4 = point2t.X; double y4 = point2t.Y; double divider = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); double intersectX = ((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) / divider; double intersectY = ((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) / divider; // Now that we have intersection line, lay the source line horizontal (either would do) // and rotation intersection point on that. From this we can test if the line is within. // Shift coordinates to 0,0 double x2shift = x2 - x1; double y2shift = y2 - y1; double intersectXshift = intersectX - x1; double intersectYshift = intersectY - y1; double lineAngle = Math.Atan2(y2shift, x2shift); // Rotate the to point and the test point (clockwise) // x' = x.cos(angle) + y.sin(angle) // y' = y.cos(angle) - x.sin(angle) double cosAngle = Math.Cos(lineAngle); double sinAngle = Math.Sin(lineAngle); double rotX2 = x2shift * cosAngle + y2shift * sinAngle; // No need to compute the to point rotated y position. It will just be zero. // double rotY2 = y2shift * cosAngle - x2shift * sinAngle; double rotXIntersection = intersectXshift * cosAngle + intersectYshift * sinAngle; double rotYIntersection = intersectYshift * cosAngle - intersectXshift * sinAngle; double selfIntersectTolerance = 0.01; // don't allow an intersection result to select start/end points if ((rotXIntersection < selfIntersectTolerance) || (rotXIntersection > rotX2 - selfIntersectTolerance)) { return(false); } intersectionPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(intersectX, intersectY); return(true); }
static public bool ConstructPointLineCurveIntersection(ESRI.ArcGIS.Client.Geometry.Polyline srcLine, ESRI.ArcGIS.Client.Geometry.MapPoint centerPoint, double bearing, double radius, out ESRI.ArcGIS.Client.Geometry.MapPoint intersectPoint) { // Given a straight line geometry and a point, find the intersection point. // If the line was purely in the x direction, this would be a trivial task: // i) If the x ordinate of the point is with the x range of the line a perpendicular can be drawn // ii) If i) is true, the distance is just the difference in the y values of the line and the point. // iii) Using a triangle (perpendicular distance, radius and angle) we can calculate point along line // For any general line orientation and point location, we can make it look like the simple case // above by: // i) Translating the point and line such that the 'from' end of the line is at the origin // ii) Rotating the point and line about the origin so that the line is indeed purely in the // x direction. // iii) Check the x ordinate of the point against the line's xMin and xMax. // iv) The magnitude of the point's y value is the distance. intersectPoint = null; if ((srcLine == null) || (centerPoint == null)) { return(false); } // Check if line is 2 point. if (srcLine.Paths.Count == 0) { return(false); } // For now we are only going to look at the first segment. ESRI.ArcGIS.Client.Geometry.PointCollection pathPoints = srcLine.Paths.First(); Int32 pointCount = pathPoints.Count; if (pointCount < 1) { return(false); } double srcAngle = Math.PI / 2 - bearing; ESRI.ArcGIS.Client.Geometry.MapPoint endPoint = ConstructPoint(centerPoint, bearing, radius); double endPointX = endPoint.X; double endPointY = endPoint.Y; double centerPointX = centerPoint.X; double centerPointY = centerPoint.Y; ESRI.ArcGIS.Client.Geometry.MapPoint fromPoint = pathPoints[0]; ESRI.ArcGIS.Client.Geometry.MapPoint toPoint = pathPoints[pointCount - 1]; if ((fromPoint == null) || (toPoint == null)) { return(false); } double fromX = fromPoint.X; double fromY = fromPoint.Y; double toX = toPoint.X; double toY = toPoint.Y; // Translate the coordinates to place the from point at the origin. endPointX -= fromX; endPointY -= fromY; centerPointX -= fromX; centerPointY -= fromY; toX -= fromX; toY -= fromY; if ((toX == 0.0) && (toY == 0.0)) { return(false); } double lineAngle = Math.Atan2(toY, toX); // Rotate the to point and the test point (clockwise) // (not require, since we have rotated the line flat) // x' = x.cos(angle) + y.sin(angle) // y' = y.cos(angle) - x.sin(angle) double cosAngle = Math.Cos(lineAngle); double sinAngle = Math.Sin(lineAngle); double rotToX = toX * cosAngle + toY * sinAngle; // No need to compute the to point rotated y position. It will just be zero. // double rotToY = toY * cosAngle - toX * sinAngle; double rotEndPointX = endPointX * cosAngle + endPointY * sinAngle; // Check whether the point is with the bounds of the line if ((rotEndPointX <= 0.0) || (rotEndPointX >= rotToX)) { return(false); } double rotEndPointY = endPointY * cosAngle - endPointX * sinAngle; double endPointPerpendicularDistance = Math.Abs(rotEndPointY); double rotCenterPointX = centerPointX * cosAngle + centerPointY * sinAngle; // Check whether the point is with the bounds of the line double rotCenterPointY = centerPointY * cosAngle - centerPointX * sinAngle; double centerPointPerpendicularDistance = Math.Abs(rotCenterPointY); // _____ // Get distance b/t rotCenterPointY and arc intersection point: k = √r²-d² double k = Math.Sqrt(Math.Pow(radius, 2) - Math.Pow(centerPointPerpendicularDistance, 2)); // For the first quadrant we have a good solution. The others we need to decide which // way to go on the line, and which origin point to use. The simplest solution is to // calculate both solutions and choose the closest. // // Use the following matrix to rotate solution point back counterclockwise. // x' = x.cos(angle) + y.sin(angle) // y' = -y.cos(angle) + x.sin(angle) // // y=0 since the line is horizontal. // rotBackIntersectionPointX = intersectionDistance * cosAngle + 0 * sinAngle; // rotBackIntersectionPointY = -0 * cosAngle + intersectionDistance * sinAngle; // // To complete the solution, add the original offset (fromX, fromY) // Intersection point (solution 1) double intersectionDistance = rotCenterPointX + k; ESRI.ArcGIS.Client.Geometry.MapPoint intersectPoint1 = null; if ((intersectionDistance >= 0) || (intersectionDistance <= rotToX)) { double rotBackIntersectionPointX = intersectionDistance * cosAngle + fromX; double rotBackIntersectionPointY = intersectionDistance * sinAngle + fromY; intersectPoint1 = new ESRI.ArcGIS.Client.Geometry.MapPoint(rotBackIntersectionPointX, rotBackIntersectionPointY); } // Intersection point (solution 2) intersectionDistance = rotCenterPointX - k; ESRI.ArcGIS.Client.Geometry.MapPoint intersectPoint2 = null; if ((intersectionDistance >= 0) || (intersectionDistance <= rotToX)) { double rotBackIntersectionPointX = intersectionDistance * cosAngle + fromX; double rotBackIntersectionPointY = intersectionDistance * sinAngle + fromY; intersectPoint2 = new ESRI.ArcGIS.Client.Geometry.MapPoint(rotBackIntersectionPointX, rotBackIntersectionPointY); } // Choose the solution that's closest to our source point. if ((intersectPoint1 != null) && (intersectPoint2 == null)) { intersectPoint = intersectPoint1; } else if ((intersectPoint1 == null) && (intersectPoint2 != null)) { intersectPoint = intersectPoint2; } else if ((intersectPoint1 != null) && (intersectPoint2 != null)) { double distance1 = LineLength(intersectPoint1, endPoint); double distance2 = LineLength(intersectPoint2, endPoint); if (distance1 <= distance2) { intersectPoint = intersectPoint1; // if equal, this will also be the solution (quadrant 1) } else { intersectPoint = intersectPoint2; } } else { return(false); } return(true); }
static public bool FindPerpendicularDistance(ESRI.ArcGIS.Client.Geometry.Polyline srcLine, ESRI.ArcGIS.Client.Geometry.MapPoint srcPoint, out double perpendicularDistance) { // Given a straight line geometry and a point, check whether a perpendicular can be drawn // from the line to the point and if so, calculate the distance. // If the line was purely in the x direction, this would be a trivial task: // i) If the x ordinate of the point is with the x range of the line a perpendicular can be drawn // ii) If i) is true, the distance is just the difference in the y values of the line and the point. // For any general line orientation and point location, we can make it look like the simple case // above by: // i) Translating the point and line such that the 'from' end of the line is at the origin // ii) Rotating the point and line about the origin so that the line is indeed purely in the // x direction. // iii) Check the x ordinate of the point against the line's xMin and xMax. // iv) The magnitude of the point's y value is the distance. perpendicularDistance = -1.0; if ((srcLine == null) || (srcPoint == null)) { return(false); } // Check if line is 2 point. if (srcLine.Paths.Count == 0) { return(false); } // For now we are only going to look at the first segment. ESRI.ArcGIS.Client.Geometry.PointCollection pathPoints = srcLine.Paths.First(); Int32 pointCount = pathPoints.Count; if (pointCount < 1) { return(false); } double pointX = srcPoint.X; double pointY = srcPoint.Y; ESRI.ArcGIS.Client.Geometry.MapPoint fromPoint = pathPoints[0]; ESRI.ArcGIS.Client.Geometry.MapPoint toPoint = pathPoints[pointCount - 1]; if ((fromPoint == null) || (toPoint == null)) { return(false); } double fromX = fromPoint.X; double fromY = fromPoint.Y; double toX = toPoint.X; double toY = toPoint.Y; // Translate the coordinates to place the from point at the origin. pointX -= fromX; pointY -= fromY; toX -= fromX; toY -= fromY; if ((toX == 0.0) && (toY == 0.0)) { return(false); } double angle = Math.Atan2(toY, toX); // Rotate the to point and the test point // (not require, since we have rotated the line flat) // // x' = x cos(angle) + y sin(angle) // y' = y cos(angle) - x sin(angle) double cosAngle = Math.Cos(angle); double sinAngle = Math.Sin(angle); double rotToX = toX * cosAngle + toY * sinAngle; // No need to compute the to point rotated y position // It will just be zero. // double rotToY = toY * cosAngle - toX * sinAngle; double rotPointX = pointX * cosAngle + pointY * sinAngle; // Check whether the point is with the bounds of the line if ((rotPointX < 0.0) || (rotPointX > rotToX)) { return(false); } double rotPointY = pointY * cosAngle - pointX * sinAngle; if (rotPointY < 0) { perpendicularDistance = -1.0 * rotPointY; } else { perpendicularDistance = rotPointY; } return(true); }
/// <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"); } }
// *********************************************************************************** // * Add a from location point on the map... closest facility will be found for this location // *********************************************************************************** void SolveClosestFacility_Completed(object sender, RouteEventArgs e) { _routesGraphicsLayer.Graphics.Clear(); _routeLabelsGraphicsLayer.Graphics.Clear(); if (e.RouteResults != null) { int i = 0; Random randomGen = new Random(); foreach (RouteResult route in e.RouteResults) { Graphic routeGraphic = route.Route; Color color = createRandomColor(randomGen); randomGen.Next(255); routeGraphic.Symbol = new SimpleLineSymbol() { Width = 5, Color = new SolidColorBrush(color) }; _routesGraphicsLayer.Graphics.Add(routeGraphic); //Route rank identification symbols... client.Geometry.Polyline pl = (client.Geometry.Polyline)routeGraphic.Geometry; int index = pl.Paths[0].Count / 4; Graphic squareGraphic = new Graphic(); client.Geometry.PointCollection ptColl = pl.Paths[pl.Paths.Count / 2]; squareGraphic.Geometry = ptColl[ptColl.Count / 2]; //this is the white outline... SimpleMarkerSymbol sms = new SimpleMarkerSymbol() { Style = SimpleMarkerSymbol.SimpleMarkerStyle.Square, Size = 24, Color = new SolidColorBrush(Color.FromRgb(255, 255, 255)), }; squareGraphic.Symbol = sms; _routeLabelsGraphicsLayer.Graphics.Add(squareGraphic); //purple rectangle behind the rank number Graphic squareGraphic2 = new Graphic(); SimpleMarkerSymbol sms2 = new SimpleMarkerSymbol() { Style = SimpleMarkerSymbol.SimpleMarkerStyle.Square, Size = 20, Color = new SolidColorBrush(Color.FromRgb(0, 0, 139)) }; squareGraphic2.Symbol = sms2; squareGraphic2.Geometry = ptColl[ptColl.Count / 2]; _routeLabelsGraphicsLayer.Graphics.Add(squareGraphic2); //rank number text symbol Graphic routeRankGraphic = new Graphic(); routeRankGraphic.Geometry = ptColl[ptColl.Count / 2]; TextSymbol routeRankSymbol = new TextSymbol(); routeRankSymbol.FontFamily = new FontFamily("Arial Black"); //Modified offsetx from -4 to 5 routeRankSymbol.OffsetX = 5; routeRankSymbol.OffsetY = 10; routeRankSymbol.Text = e.RouteResults[i].Directions.RouteID.ToString(); routeRankSymbol.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); routeRankSymbol.FontSize = 16; routeRankGraphic.Symbol = routeRankSymbol; _routeLabelsGraphicsLayer.Graphics.Add(routeRankGraphic); i++; } //zoom to the map if (chkZoomToMap.IsChecked ?? false) { _mapWidget.Map.Extent = _routesGraphicsLayer.FullExtent; } //Create and Display Closest Facilities List window... _result = new FindCloseFacilityResultView(this, e.RouteResults, _mapWidget); _mapWidget.SetToolbar(_result); } }
/// <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"); } }
private static ESRI.ArcGIS.Client.Geometry.PointCollection GetPoints(List<ImsPoints> points) { ESRI.ArcGIS.Client.Geometry.PointCollection pointcollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); foreach (var po in points) { ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(Convert.ToDouble(po.X, System.Globalization.CultureInfo.CurrentCulture), Convert.ToDouble(po.Y, System.Globalization.CultureInfo.CurrentCulture)); pointcollection.Add(mapPoint); } return pointcollection; }