public static BoundingBox RectToBoundingBox(IProjection projection, Rectangle rectangle) { var minPoint = projection.Project(new Vector3(rectangle.BottomLeft.x, 0, rectangle.BottomLeft.y)); var maxPoint = projection.Project(new Vector3(rectangle.TopRight.x, 0, rectangle.TopRight.y)); return(new BoundingBox(minPoint, maxPoint)); }
public IEnumerable <IFeature> GetFeatures(FetchInfo fetchInfo) { // Note that the FetchInfo.CRS is ignored in this method. A better solution // would be to use the fetchInfo.CRS everywhere, but that would only make // sense if GetExtent would also get a CRS argument. Room for improvement. if (fetchInfo.Extent == null) { return(new List <IFeature>()); } var copiedExtent = new MRect(fetchInfo.Extent); // throws exception when CRS or _provider.CRS is null (so I don't have to check it here) _projection.Project(CRS !, _provider.CRS !, copiedExtent); fetchInfo = new FetchInfo(copiedExtent, fetchInfo.Resolution, CRS, fetchInfo.ChangeType); var features = _provider.GetFeatures(fetchInfo) ?? new List <IFeature>(); if (!CrsHelper.IsProjectionNeeded(_provider.CRS, CRS)) { return(features); } if (!CrsHelper.IsCrsProvided(_provider.CRS, CRS)) { throw new NotSupportedException($"CRS is not provided. From CRS: {_provider.CRS}. To CRS {CRS}"); } var copiedFeatures = features.Copy().ToList(); _projection.Project(_provider.CRS, CRS, copiedFeatures); return(copiedFeatures); }
public static Rectangle QuadKeyToRect(IProjection projection, QuadKey quadKey) { var boundingBox = QuadKeyToBoundingBox(quadKey); var minPoint = projection.Project(boundingBox.MinPoint, 0); var maxPoint = projection.Project(boundingBox.MaxPoint, 0); return new Rectangle(minPoint.x, minPoint.z, maxPoint.x - minPoint.x, maxPoint.z - minPoint.z); }
public static Rectangle QuadKeyToRect(IProjection projection, QuadKey quadKey) { var boundingBox = QuadKeyToBoundingBox(quadKey); var minPoint = projection.Project(boundingBox.MinPoint, 0); var maxPoint = projection.Project(boundingBox.MaxPoint, 0); return(new Rectangle(minPoint.x, minPoint.z, maxPoint.x - minPoint.x, maxPoint.z - minPoint.z)); }
private static void GetBoundsAndOffset(string osmPath) { // get an offset because we want the center of the osm file // to be the 0|0 point on the game map bounds = GetOsmBounds(osmPath); var projBoundsMin = projection.Project( bounds.Min.Latitude, bounds.Min.Longitude); var projBoundsMax = projection.Project( bounds.Max.Latitude, bounds.Max.Longitude); projectedBounds = new BBox <Point>(projBoundsMin, projBoundsMax); // change bounds to match the UV grid of the sat images projectedBounds.Min.X -= projectedBounds.Min.X % TerrainCreator.XSize; projectedBounds.Min.Y -= projectedBounds.Min.Y % TerrainCreator.YSize; CalculateOffset(bounds.Min, bounds.Max); }
/// <summary> /// Returns the coordinates of a way's nodes projected and with elevation. /// </summary> /// <param name="way"></param> /// <param name="offsetX"></param> /// <param name="offsetY"></param> /// <returns></returns> public static List<Vector3> ProjectWay(CompleteWay way, Point offset, IProjection projection, Elevation elevation, bool fetchElevation = true) { var nodes = new List<Vector3>(); for (int i = 0; i < way.Nodes.Length; i++) { var node = way.Nodes[i]; // convert to X/Y var projPos = projection.Project(node); // apply offset projPos.X -= offset.X; projPos.Y -= offset.Y; // flip vertically because Z is down projPos.Y *= -1; double el = 0; if (fetchElevation) el = elevation.GetElevation(node.Latitude.Value, node.Longitude.Value); var vector = new Vector3((float)projPos.X, (float)el, (float)projPos.Y); nodes.Add(vector); } return nodes; }
public MRect?GetExtent() { if (_provider.GetExtent() == null) { return(null); } var extent = _provider.GetExtent() !; if (!CrsHelper.IsProjectionNeeded(_provider.CRS, CRS)) { return(extent); } if (!CrsHelper.IsCrsProvided(_provider.CRS, CRS)) { throw new NotSupportedException($"CRS is not provided. From CRS: {_provider.CRS}. To CRS {CRS}"); } // This projects the full extent of the source. Usually the full extent of the source does not change, // so perhaps this should be calculated just once. Then again, there are probably situations where it does // change so a way to refresh this should be possible. var copiedExtent = new MRect(extent); _projection.Project(_provider.CRS, CRS, copiedExtent); return(copiedExtent); }
/// <inheritdoc /> public async Task <IProcessingResult> Process(CommittedEvent @event, PartitionId partitionId, ExecutionContext executionContext, CancellationToken cancellationToken) { Log.EventProcessorIsProcessing(_logger, Identifier, @event.Type.Id, partitionId); if (!ShouldProcessEvent(@event)) { return(new SuccessfulProcessing()); } var tryGetCurrentState = await TryGetCurrentState(@event, partitionId, cancellationToken).ConfigureAwait(false); if (!tryGetCurrentState.Success) { return(new FailedProcessing(tryGetCurrentState.Exception.Message)); } var result = await _projection.Project(tryGetCurrentState.Result, @event, partitionId, executionContext, cancellationToken).ConfigureAwait(false); return(await HandleResult(tryGetCurrentState.Result.Key, result).ConfigureAwait(false)); }
public Polygon2 Project(IProjection projection, IList <Point3> pointList) { var polygon2 = new Polygon2(); foreach (var projected in Points.Select(i => projection.Project(pointList[i])).Where(projected => projected != null)) { polygon2.AddPoint((PointF)projected); } return(polygon2); }
/// <summary> /// Converts a way into a projected path that includes a point for every elevation change on the path. /// </summary> /// <param name="way"></param> /// <param name="offset"></param> /// <param name="projection"></param> /// <param name="elevation"></param> /// <returns></returns> public static List<Vector3> ProjectWayWithLineElevation(CompleteWay way, Point offset, IProjection projection, Elevation elevation) { // get line points var geoPoints = elevation.GetWayElevation(way.Nodes).ToList(); // convert to projected points var nodes = geoPoints.Select(point => { // convert to X/Y var projPos = projection.Project(point.Latitude, point.Longitude); // apply offset projPos.X -= offset.X; projPos.Y -= offset.Y; // flip vertically because Z is down projPos.Y *= -1; return new Vector3((float)projPos.X, (float)point.Elevation, (float)projPos.Y); }).ToList(); // remove points that are too close to each other to avoid "Curve item is too small" errors const float epsilon = 0.8f; const float epsilonSquared = epsilon * epsilon; var unique = new List<Vector3>(nodes.Count); unique.Add(nodes[0]); for (int i = 1; i < nodes.Count; i++) { if (Vector3.DistanceSquared(nodes[i - 1], nodes[i]) < epsilonSquared) continue; else unique.Add(nodes[i]); } return unique; }
/// <inheritdoc /> public Vector3 Project(GeoCoordinate coordinate, double height) { return(_projection.Project(coordinate, height) * _scale); }