//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Copy constructor. * @param pline map object copy from. */ public MapPline(MapPline pline) : base(pline) { SetMapObjectType(PLINE); PenStyle = new MapPen(pline.PenStyle); Pline = new GeoPolyline(pline.Pline); }
private Point[] DrawPline(MapPen mapPen, GeoPolyline pline) { ArrayList clippedPts = _sutherlandHodgman.ClipPline(pline.GetPoints()); GeoPoint[] screenPts = FromLatLngToMapPixel(clippedPts); if (screenPts.Length > 1) { { Pen pen = GetPen(mapPen); int[] xpoints = new int[screenPts.Length]; int[] ypoints = new int[screenPts.Length]; for (int i = 0; i < screenPts.Length; i++) { xpoints[i] = (int)screenPts[i].X; ypoints[i] = (int)screenPts[i].Y; } Point[] points = new Point[xpoints.Length]; for (int i = 0; i < points.Length; i++) { points[i] = new Point(xpoints[i], ypoints[i]); } SharedGraphics2D.Graphics.DrawLines(pen, points); return(points); } } return(null); }
public void LongPolylineRectWithinDistanceSanityTest2() { List <GeoCoordinates> points = new List <GeoCoordinates>(); for (int i = 0; i < 1000; ++i) { // Points stretch from (0,0) to (9.99, 9.99) points.Add(new GeoCoordinates(i / 100.0, i / 100.0)); } GeoPolyline pl = new GeoPolyline(points); // Rect is in upper left corner of the square (0,0),(10,0),(10,10),(0,10) // and has side length 4. It should be sqrt(2) units away from line. Rect r = new Rect { xMin = 0, xMax = 4, yMin = 6, yMax = 10 }; Assert.False(pl.RectWithinDistance(r, 1.3)); Assert.True(pl.RectWithinDistance(r, 1.5)); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * draw a pline. * @param mapPen the pen used to draw the polyline * @param pline the polyline object. */ private void DrawPline(MapPen mapPen, GeoPolyline pline) { ArrayList clippedPts = _sutherlandHodgman.ClipPline(pline.GetPoints()); GeoPoint[] screenPts = FromLatLngToMapPixel(clippedPts); if (screenPts.Length > 1) { { int penWidth = mapPen.Width; if (mapPen.Pattern > 62) { penWidth = mapPen.Width * 2; } Pen pen = new Pen(new Color(mapPen.Color, false), penWidth); SharedGraphics2D.SetDefaultPen(pen); int[] xpoints = new int[screenPts.Length]; int[] ypoints = new int[screenPts.Length]; for (int i = 0; i < screenPts.Length; i++) { xpoints[i] = (int)screenPts[i].X; ypoints[i] = (int)screenPts[i].Y; } Polyline polyline = new Polyline { Xpoints = xpoints, Ypoints = ypoints, NumOfPoints = xpoints.Length }; SharedGraphics2D.DrawPolyline(null, polyline); } } }
private void DrawPolygonClip(PaintEventArgs e) { var aPoint1 = new GeoCoordinate(20.0, 20.0, 0.0); var aPoint2 = new GeoCoordinate(30.0, 200.0, 0.0); var aPoint3 = new GeoCoordinate(100.0, 300.0, 0.0); var aPoint4 = new GeoCoordinate(400.0, 350.0, 0.0); var aPoint5 = new GeoCoordinate(350.0, 150.0, 0.0); var aPolyline = new GeoPolyline(); aPolyline.addVertex(aPoint1); aPolyline.addVertex(aPoint2); aPolyline.addVertex(aPoint3); aPolyline.addVertex(aPoint4); aPolyline.addVertex(aPoint5); aPolyline.close(); var aPolygon = new GeoPolygon(); aPolygon.setPolyline(aPolyline); DrawPolygon(e, aPolygon, Color.FromArgb(255, 0, 0, 255)); var aNormal = new GeoNormal(1, 1, 0); var aPlane = new GeoPlane(aNormal, 3.0 * trackBar1.Value + 100.0); var aClippedPolygon = aPolygon.clip(aPlane); DrawPolygon(e, aClippedPolygon, Color.FromArgb(255, 255, 0, 0)); }
protected override void HandleBind() { location = RenderState.Source as GeoLocation; if (location == null) { polyline = (GeoPolyline)RenderState.Source; location = polyline.Points?.FirstOrDefault(); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Copy constructor. * @param multiPline map object copy from. */ public MapMultiPline(MapMultiPline multiPline) : base(multiPline) { SetMapObjectType(MULTIPLINE); PenStyle = new MapPen(multiPline.PenStyle); Plines = new GeoPolyline[multiPline.Plines.Length]; for (int i = 0; i < Plines.Length; i++) { Plines[i] = new GeoPolyline(multiPline.Plines[i]); } }
/// <inheritdoc /> /// <summary> /// This function will build the <see cref="P:Dxflib.Entities.Hatch.Hatch.Boundary" /> /// of this hatch if it is <see cref="P:Dxflib.Entities.Hatch.Hatch.IsAssociative" />. /// </summary> public override void UpdateReferencedEntities() { if (ReferencedEntities.Count > 1) { Boundary = BuildBoundary(); } else if (ReferencedEntities.Count == 1) { if (ReferencedEntities[0].RefEntity is LwPolyLine polyline) { Boundary = polyline.GPolyline; } } }
private static Polyline projectPolyline(GeoPolyline polyline, GnomonicProjection projection) { Polyline p = polyline.ToPlanarPolyline(false); foreach (LinePath path in p.Paths) { for (int i = 0; i < path.Vertices.Count; i++) { double x, y; projection.Project(path.Vertices[i].Y, path.Vertices[i].X, out x, out y); path.Vertices[i] = PlanimetryEnvironment.NewCoordinate(x, y); } } return p; }
/// <inheritdoc /> /// <summary> /// The Default Constructor that sets all values to their defaults /// </summary> public HatchBuffer() { EntityType = typeof(Hatch); HatchPatternName = string.Empty; SolidFillFlag = false; AssociativityFlag = false; NumberOfLoops = 0; HatchStyle = HatchStyles.Normal; PatternType = HatchPatternType.Predefined; PatternAngle = 0.0; PatternScale = 0.0; NumberOfPatternDefLines = 0; EntityReferenceList = new List <string>(); Boundary = new GeoPolyline(); }
public void SinglePointPolylineRectWithinDistanceIsCircleTest() { GeoPolyline pl = new GeoPolyline(new GeoCoordinates(0, 0)); Rect r = new Rect { xMin = 1, xMax = 2, yMin = 1, yMax = 2 }; Assert.False(pl.RectWithinDistance(r, 1.1)); Assert.True(pl.RectWithinDistance(r, 1.5)); }
private static Polyline projectPolyline(GeoPolyline polyline, GnomonicProjection projection) { Polyline p = polyline.ToPlanarPolyline(false); foreach (LinePath path in p.Paths) { for (int i = 0; i < path.Vertices.Count; i++) { double x, y; projection.Project(path.Vertices[i].Y, path.Vertices[i].X, out x, out y); path.Vertices[i] = PlanimetryEnvironment.NewCoordinate(x, y); } } return(p); }
/// <summary> /// The extraction constructor for the lwpolyline class /// </summary> /// <param name="lwPolyLineBuffer">A <see cref="LwPolyLineBuffer" /></param> public LwPolyLine(LwPolyLineBuffer lwPolyLineBuffer) : base(lwPolyLineBuffer) { EntityType = lwPolyLineBuffer.EntityType; // LwPolyLine Specific NumberOfVertices = lwPolyLineBuffer.NumberOfVertices; PolyLineFlag = lwPolyLineBuffer.PolyLineFlag; ConstantWidth = lwPolyLineBuffer.ConstantWidth; Elevation = lwPolyLineBuffer.Elevation; Thickness = lwPolyLineBuffer.Thickness; // Create the GeoPolyline GPolyline = new GeoPolyline( lwPolyLineBuffer.XValues, lwPolyLineBuffer.YValues, lwPolyLineBuffer.BulgeList, PolyLineFlag); }
/// <summary> /// Parsing the Boundary Edge from edge Data /// </summary> /// <param name="list">The <see cref="TaggedDataList" /> list</param> /// <param name="index">The current index</param> /// <returns>A GeoPolyline</returns> private static GeoPolyline ParseBoundary(TaggedDataList list, ref int index) { var geoPolyline = new GeoPolyline(); // The Geo Polyline to be returned for ( ; index < list.Length; ++index) { var currentData = list.GetPair(index); switch (currentData.GroupCode) { // Edge Types case HatchCodes.EdgeType: switch ((EdgeTypes)int.Parse(currentData.Value)) { case EdgeTypes.Line: geoPolyline.Add(ParseLineEdge(list, ref index)); break; case EdgeTypes.CircularArc: geoPolyline.Add(ParseCircularArcEdge(list, ref index)); break; case EdgeTypes.EllipticalArc: break; case EdgeTypes.Spline: break; default: throw new ArgumentOutOfRangeException(); } continue; // When to exit the loop case HatchCodes.SourceObjectsCount: --index; return(geoPolyline); default: continue; } } // This area of code should not be reachable throw new ArgumentOutOfRangeException(); }
private static GeoPolyline unprojectPolyline(Polyline polyline, GnomonicProjection projection) { GeoPolyline geoPolyline = new GeoPolyline(); foreach (LinePath path in polyline.Paths) { GeoPath geoPath = new GeoPath(); foreach (ICoordinate p in path.Vertices) { geoPath.Vertices.Add(unprojectPoint(new PointD(p), projection)); } geoPolyline.Paths.Add(geoPath); } return(geoPolyline); }
public void GenericGeoPolylineTest_1Arc() { // Line 0 var v0 = new Vertex(3.5, 0); var v1 = new Vertex(6, 0); var l0 = new GeoLine(v0, v1); Assert.IsTrue(Math.Abs(l0.Length - 2.5) < GeoMath.Tolerance); // Line 1 var v2 = new Vertex(6, 2.5); var l1 = new GeoLine(v1, v2); Assert.IsTrue(Math.Abs(l1.Length - 2.5) < GeoMath.Tolerance); // Arc var centerPoint = new Vertex(4.75, 1.75); var startAngle = GeoMath.DegToRad(30.964); var endAngle = GeoMath.DegToRad(149.036); const double radius = 1.4577; var arc0 = new GeoArc(centerPoint, startAngle, endAngle, radius); Assert.IsTrue(Math.Abs(arc0.Length - 3.0040) < GeoMath.Tolerance); // Line 2 var v3 = new Vertex(3.5, 2.5); var l2 = new GeoLine(v3, v0); Assert.IsTrue(Math.Abs(l2.Length - 2.5) < GeoMath.Tolerance); // GeoPolyline var geoPolyline = new GeoPolyline(); // Initialized // Adding sections to the GeoPolyline geoPolyline.Add(l0); geoPolyline.Add(l1); geoPolyline.Add(arc0); geoPolyline.Add(l2); // Assert Assert.IsTrue(Math.Abs(geoPolyline.Length - 10.5040) < GeoMath.Tolerance); Assert.IsTrue(Math.Abs(geoPolyline.Area - 7.5021) < GeoMath.Tolerance); }
/// <summary> /// Computes a series of driving routes from the origin, through each waypoint (in order), /// and to the destination. The first polyline corresponds to the route from the origin to the /// first waypoint, and the last polyline corresponds to the route from the last waypoint /// to the destination. If <paramref name="wayPoints"/> is empty, this is equivalent /// to <see cref="ComputeRoute(GeoCoordinates, GeoCoordinates)"/>. Will return null /// if no route is found. /// </summary> /// <exception cref="ApiAccessException">Thrown if underlying API (e.g. Google Maps) returns an error.</exception> /// <returns>A list of routes making up the journey from the origin through the waypoints to the destination. Returns /// null if no route is found.</returns> /// <param name="origin">Origin.</param> /// <param name="destination">Destination.</param> /// <param name="wayPoints">Way points.</param> static IEnumerable <GeoPolyline> ComputeRouteWithWaypoints(GeoCoordinates origin, GeoCoordinates destination, IEnumerable <GeoCoordinates> wayPoints) { List <GeoCoordinates> allWaypoints = wayPoints.ToList(); if (allWaypoints.Count == 0) { var route = ComputeRoute(origin, destination); if (route == null) { return(null); } return(new List <GeoPolyline> { route }); } var request = new DirectionRequest { Origin = origin.ToGoogleLocation(), Destination = destination.ToGoogleLocation(), Waypoints = allWaypoints.Select((pt) => (Location)pt.ToGoogleLocation()).ToList() }; var response = new DirectionService().GetResponse(request); if (response.ErrorMessage != null) { throw new ApiAccessException("Google Directions API failed with: " + response.ErrorMessage); } if (response.Routes.Length == 0) { return(null); } return(response.Routes[0].Legs .Select((leg) => leg.Steps) .Select((stepArray) => GeoPolyline.Join(stepArray.Select((step) => step.Polyline.ToGeo())))); }
// Build the Boundary if the number // of boundary objects is greater than 1 // or in other words is not a polyline private GeoPolyline BuildBoundary() { var geoPolyline = new GeoPolyline(); foreach (var entityPointer in ReferencedEntities) { switch (entityPointer.RefEntity) { case Line line: geoPolyline.Add(line.GLine); continue; case CircularArc arc: geoPolyline.Add(arc.GeometricArc); continue; default: throw new EntityPointerException("Pointer Type Not Recognized"); } } return(geoPolyline); }
public void LongPolylineRectWithinDistanceSanityTest1() { List <GeoCoordinates> points = new List <GeoCoordinates>(); for (int i = 0; i < 1000; ++i) { // Points stretch from lng=0 to lng=9.99 points.Add(new GeoCoordinates(0, i / 100.0)); } GeoPolyline pl = new GeoPolyline(points); // Rect 1 unit above line. Rect r = new Rect { xMin = 0, xMax = 10, yMin = 1, yMax = 2 }; Assert.False(pl.RectWithinDistance(r, 0.9)); Assert.True(pl.RectWithinDistance(r, 1.1)); }
public void CounterClockWiseTest() { // This test creates a geoPolyline in a counter clockwise direction // some vertices // Note that Vertex1 is to the right of vertex0 Vertex[] vertices = { new Vertex(7, 0), // Vertex0 new Vertex(9.5, 0), // Vertex1 new Vertex(9.5, 2.5), // Vertex2 new Vertex(7, 2.5) // Vertex3 }; GeoBase[] sections = { new GeoLine(vertices[0], vertices[1]), new GeoLine(vertices[1], vertices[2]), new GeoArc( new Vertex(8.25, 1.75), GeoMath.DegToRad(30.9638), GeoMath.DegToRad(149.0362), 1.4577), new GeoLine(vertices[3], vertices[0]) }; var geoPolyline = new GeoPolyline(); foreach (var section in sections) { geoPolyline.Add(section); } Assert.IsTrue(Math.Abs(geoPolyline.Length - 10.5040) < GeoMath.Tolerance); Assert.IsTrue(Math.Abs(geoPolyline.Area - 7.5021) < GeoMath.Tolerance); }
GetRide(UserRideOffer offer, ConcurrentGeoQuadtree <MatchableRideRequest> origins, ConcurrentGeoQuadtree <MatchableRideRequest> destinations) { RouteInfo driverRoute = await GetRoute(offer); var originsTask = GetElementsInsideAsync(origins, NearRoute); var destinationsTask = GetElementsInsideAsync(destinations, NearRoute); // Only consider passengers whose origins and destinations are near // the driver's route. var potentialPassengers = new HashSet <MatchableRideRequest>( from element in await originsTask select element.Data); potentialPassengers.IntersectWith( from element in await destinationsTask select element.Data); // Find a passenger going in the same direction as the driver such that // picking up the passenger does not put the driver too far out of their way. foreach (var passenger in potentialPassengers.Where(GoingInDriversDirection)) { RouteInfo routeWithPassenger = await GetRouteWithPassenger(offer, passenger); // Reject route if it's too far out of the way according to // the driver's settings. if (driverRoute.drivingTime.HasValue && routeWithPassenger.drivingTime.HasValue) { TimeSpan originalTime = driverRoute.drivingTime.Value; TimeSpan newTime = routeWithPassenger.drivingTime.Value; TimeSpan maxTime = originalTime + TimeSpan.FromMinutes(offer.RideOffer.MaxTimeOutOfWay); if (newTime > maxTime) { // Output debug info for demos. Program.LogError($"Matched {offer.User.UserInfo.UserId} with {passenger.Request.User.UserInfo.UserId}" + " but resulting route was too long." + $" Original trip duration: {originalTime.Minutes} mins." + $" Matched trip duration: {newTime.Minutes} mins." + $" Driver's max time out of way: {offer.RideOffer.MaxTimeOutOfWay} mins."); continue; } } return(RideWithPassenger(offer, passenger)); } return(EmptyRide(offer, driverRoute)); /// <summary> /// Tests whether any point in the rect is close enough to <see cref="route"/>. /// </summary> bool NearRoute(Rect rect) { // Ignore passengers more than approximately 1km of the route. // TODO Take large max-time-out-of-way values into account when choosing max-dist-out-of-way. double maxDistMeters = 1000; double maxDistDegrees = offer.RideOffer.Trip.Source.DegreesUpperBound(maxDistMeters); GeoPolyline route = driverRoute.overviewPolyline; return(route.RectWithinDistance(rect, maxDistDegrees)); } /// <summary> /// Tests whether this passenger is going in the same direction as the driver. /// </summary> bool GoingInDriversDirection(MatchableRideRequest request) { var driverDest = offer.RideOffer.Trip.Destination; var driverOrig = offer.RideOffer.Trip.Source; var driverSeg = new GeoSegment(driverOrig, driverDest); var passDest = request.Request.RideRequest.Trip.Destination; var passOrig = request.Request.RideRequest.Trip.Source; var passSeg = new GeoSegment(passOrig, passDest); // Use GeoSegments so that this works near prime meridian. var passDiff = passSeg.Point2Representative - passSeg.Point1Representative; var driverDiff = driverSeg.Point2Representative - driverSeg.Point1Representative; // Compute the dot product of the vectors. This is a pretty rough // estimate and doesn't take into account the Earth's curvature. return(passDiff.Dot(driverDiff) > 0); } }
public static CLLocationCoordinate2D[] ToCoordinates(this GeoPolyline polyline) => polyline.Points.Select(ToCoordinate).ToArray();
public static MKPolyline ToMKPolyline(this GeoPolyline polyline) => MKPolyline.FromCoordinates(polyline.ToCoordinates());
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * default constructor. */ public MapPline() { SetMapObjectType(PLINE); PenStyle = new MapPen(); Pline = null; }
private static GeoPolyline unprojectPolyline(Polyline polyline, GnomonicProjection projection) { GeoPolyline geoPolyline = new GeoPolyline(); foreach (LinePath path in polyline.Paths) { GeoPath geoPath = new GeoPath(); foreach (ICoordinate p in path.Vertices) geoPath.Vertices.Add(unprojectPoint(new PointD(p), projection)); geoPolyline.Paths.Add(geoPath); } return geoPolyline; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Set GeoPolyline of the map Pline. * @param pline the GeoPolyline object. */ public void SetPline(GeoPolyline pline) { Pline = pline; }
private void SearchResponse(GDirections gDirection, Response response) { Exception ex = response.GetException(); if (ex != null || response.GetCode() != HttpStatusCode.OK) { if (gDirection._listener != null) { gDirection._listener.Done(gDirection._routeQuery, null); } return; } try { Result result = response.GetResult(); gDirection._mapDirection.Name = result.GetAsString("name"); gDirection._mapDirection.Status = result.GetAsInteger("Status.code"); gDirection._mapDirection.Duration = result.GetAsInteger("Directions.Duration.seconds"); gDirection._mapDirection.Distance = result.GetAsInteger("Directions.Distance.meters"); gDirection._mapDirection.Summary = _html2Text.Convert(result.GetAsString("Directions.summaryHtml")); string points = result.GetAsString("Directions.Polyline.points"); string levels = result.GetAsString("Directions.Polyline.levels"); int zoomFactor = result.GetAsInteger("Directions.Polyline.ZoomFactor"); int numLevels = result.GetAsInteger("Directions.Polyline.NumLevels"); gDirection._mapDirection.Polyline = GeoPolyline.FromEncoded(0x00FF00, 4, 1, points, zoomFactor, levels, numLevels); int numOfGeocodes = result.GetSizeOfArray("Placemark"); if (numOfGeocodes > 0) { gDirection._mapDirection.GeoCodes = new MapPoint[numOfGeocodes]; for (int i = 0; i < numOfGeocodes; i++) { gDirection._mapDirection.GeoCodes[i] = new MapPoint(); gDirection._mapDirection.GeoCodes[i].Name = result.GetAsString("Placemark[" + i + "].address"); string location = result.GetAsString("Placemark[" + i + "].Point.coordinates"); GeoLatLng latLng = MapLayer.FromStringToLatLng(location); gDirection._mapDirection.GeoCodes[i].SetPoint(latLng); } } int numOfRoutes = result.GetSizeOfArray("Directions.Routes"); if (numOfRoutes > 0) { gDirection._mapDirection.Routes = new MapRoute[numOfRoutes]; for (int i = 0; i < numOfRoutes; i++) { string routeString = "Directions.Routes[" + i + "]"; gDirection._mapDirection.Routes[i] = MapDirection.NewRoute(); gDirection._mapDirection.Routes[i].Summary = _html2Text.Convert(result.GetAsString(routeString + ".summaryHtml")); gDirection._mapDirection.Routes[i].Distance = result.GetAsInteger(routeString + ".Distance.meters"); gDirection._mapDirection.Routes[i].Duration = result.GetAsInteger(routeString + ".Duration.seconds"); string lastLatLng = result.GetAsString(routeString + ".End.coordinates"); gDirection._mapDirection.Routes[i].LastLatLng = MapLayer.FromStringToLatLng(lastLatLng); int numOfSteps = result.GetSizeOfArray(routeString + ".Steps"); if (numOfSteps > 0) { gDirection._mapDirection.Routes[i].Steps = new MapStep[numOfSteps]; for (int j = 0; j < numOfSteps; j++) { string stepString = routeString + ".Steps[" + j + "]"; gDirection._mapDirection.Routes[i].Steps[j] = MapRoute.NewStep(); gDirection._mapDirection.Routes[i].Steps[j].Description = _html2Text.Convert(result.GetAsString(stepString + ".descriptionHtml")); gDirection._mapDirection.Routes[i].Steps[j].Distance = result.GetAsInteger(stepString + ".Distance.meters"); gDirection._mapDirection.Routes[i].Steps[j].Duration = result.GetAsInteger(stepString + ".Duration.seconds"); gDirection._mapDirection.Routes[i].Steps[j].FirstLocationIndex = result.GetAsInteger(stepString + ".polylineIndex"); string firstLocation = result.GetAsString(stepString + ".Point.coordinates"); gDirection._mapDirection.Routes[i].Steps[j].FirstLatLng = MapLayer.FromStringToLatLng(firstLocation); } } } } } catch (Exception) { if (gDirection._listener != null) { gDirection._listener.Done(gDirection._routeQuery, null); } return; } if (gDirection._listener != null) { MapDirection mapDirection = gDirection._mapDirection; if (mapDirection.GeoCodes.Length == mapDirection.Routes.Length + 1) { for (int i = 0; i < mapDirection.Routes.Length; i++) { mapDirection.Routes[i].StartGeocode = mapDirection.GeoCodes[i]; mapDirection.Routes[i].EndGeocode = mapDirection.GeoCodes[i + 1]; } } for (int i = 0; i < mapDirection.Routes.Length; i++) { MapRoute mapRoute = mapDirection.Routes[i]; for (int j = 0; j < mapRoute.Steps.Length - 1; j++) { MapStep mapStep = mapRoute.Steps[j]; mapStep.LastLocationIndex = mapRoute.Steps[j + 1].FirstLocationIndex; mapStep.LastLatLng = mapDirection.Polyline.GetVertex(mapRoute.Steps[j + 1].FirstLocationIndex); } mapRoute.Steps[mapRoute.Steps.Length - 1].LastLocationIndex = mapDirection.Polyline.GetVertexCount() - 1; mapRoute.Steps[mapRoute.Steps.Length - 1].LastLatLng = mapDirection.Polyline.GetVertex(mapDirection.Polyline.GetVertexCount() - 1); } GeoPolyline polyline = mapDirection.Polyline; if (polyline.GetVertexCount() > 1) { GeoLatLng latLngTemp = polyline.GetVertex(0); mapDirection.Bounds = new GeoLatLngBounds(latLngTemp, latLngTemp); for (int i = 0; i < mapDirection.Routes.Length; i++) { MapRoute mapRoute = mapDirection.Routes[i]; latLngTemp = polyline.GetVertex(mapRoute.Steps[0].FirstLocationIndex); mapRoute.Bounds = new GeoLatLngBounds(latLngTemp, latLngTemp); for (int j = 0; j < mapRoute.Steps.Length; j++) { latLngTemp = polyline.GetVertex(mapRoute.Steps[j].FirstLocationIndex); MapStep mapStep = mapRoute.Steps[j]; mapStep.Bounds = new GeoLatLngBounds(latLngTemp, latLngTemp); for (int k = mapStep.FirstLocationIndex; k <= mapStep.LastLocationIndex; k++) { GeoLatLng latLng = polyline.GetVertex(k); mapStep.Bounds.Add(latLng.Lng(), latLng.Lat()); mapRoute.Bounds.Add(latLng.Lng(), latLng.Lat()); mapDirection.Bounds.Add(latLng.Lng(), latLng.Lat()); } } } } gDirection._listener.Done(gDirection._routeQuery, mapDirection); } }
private static GeoPolygon getPolylineBuffer(GeoPolyline geoPolyline, double angleDistance, int pointsPerCircle, bool allowParallels) { geoPolyline = (GeoPolyline)geoPolyline.Clone(); double minAngle = Math.Sin(Math.Abs(angleDistance)) * Math.Sin(Math.PI / pointsPerCircle); geoPolyline.ReduceSegments(minAngle); geoPolyline.Densify(minAngle); GnomonicProjection projection; IGeometry geometry; projectGeography(geoPolyline, out projection, out geometry); Polyline planePolyline = (Polyline)geometry; GeographyCollection geographyCollection = new GeographyCollection(); Polygon temp = new Polygon(); List <Polygon> partialBuffers = new List <Polygon>(); ICollection <IGeometry> unionResult = null; int c = 0; foreach (GeoPath path in geoPolyline.Paths) { for (int i = 0; i < path.Vertices.Count - 1; i++) { GeoPoint p = path.Vertices[i]; GeoPolygon tempPolygon = getPointBuffer(p, angleDistance, pointsPerCircle); geographyCollection.Clear(); geographyCollection.Add(tempPolygon); GeometryCollection gc = GeometrySpreader.GetGeometries(geographyCollection, projection); if (gc[0] is Polygon) { unionResult = temp.Union((Polygon)gc[0]); } if (unionResult.Count > 0) { temp = (Polygon)((GeometryCollection)unionResult)[0]; } c++; if (c == 3) { partialBuffers.Add(temp); temp = new Polygon(); c = 0; } } } if (temp.CoordinateCount > 0) { partialBuffers.Add(temp); } Polygon planeBuffer = mergePartialBuffers(partialBuffers, allowParallels); GeometryCollection geometryCollection = new GeometryCollection(); geometryCollection.Add(planeBuffer); geographyCollection = GeometrySpreader.GetGeographies(geometryCollection, projection); foreach (IGeography g in geographyCollection) { if (g is GeoPolygon) { return((GeoPolygon)g); } } return(new GeoPolygon()); }
private static GeoPolygon getPolylineBuffer(GeoPolyline geoPolyline, double angleDistance, int pointsPerCircle, bool allowParallels) { geoPolyline = (GeoPolyline)geoPolyline.Clone(); double minAngle = Math.Sin(Math.Abs(angleDistance)) * Math.Sin(Math.PI / pointsPerCircle); geoPolyline.ReduceSegments(minAngle); geoPolyline.Densify(minAngle); GnomonicProjection projection; IGeometry geometry; projectGeography(geoPolyline, out projection, out geometry); Polyline planePolyline = (Polyline)geometry; GeographyCollection geographyCollection = new GeographyCollection(); Polygon temp = new Polygon(); List<Polygon> partialBuffers = new List<Polygon>(); ICollection<IGeometry> unionResult = null; int c = 0; foreach (GeoPath path in geoPolyline.Paths) { for (int i = 0; i < path.Vertices.Count - 1; i++) { GeoPoint p = path.Vertices[i]; GeoPolygon tempPolygon = getPointBuffer(p, angleDistance, pointsPerCircle); geographyCollection.Clear(); geographyCollection.Add(tempPolygon); GeometryCollection gc = GeometrySpreader.GetGeometries(geographyCollection, projection); if (gc[0] is Polygon) unionResult = temp.Union((Polygon)gc[0]); if (unionResult.Count > 0) temp = (Polygon)((GeometryCollection)unionResult)[0]; c++; if (c == 3) { partialBuffers.Add(temp); temp = new Polygon(); c = 0; } } } if (temp.CoordinateCount > 0) partialBuffers.Add(temp); Polygon planeBuffer = mergePartialBuffers(partialBuffers, allowParallels); GeometryCollection geometryCollection = new GeometryCollection(); geometryCollection.Add(planeBuffer); geographyCollection = GeometrySpreader.GetGeographies(geometryCollection, projection); foreach (IGeography g in geographyCollection) if (g is GeoPolygon) return (GeoPolygon)g; return new GeoPolygon(); }