/// <summary> /// Reprojects a <see cref="Bitmap"/> and corresponding georeferenced metadata to /// a new coordinate system. /// </summary> /// <param name="sourceReference">The georeferenced metadata of <paramref name="sourceTile"/>.</param> /// <param name="sourceTile">The tile image.</param> /// <param name="targetReference">Output: The reprojected georeferenced metadata.</param> /// <param name="targetTile">Output: The reprojected tile image.</param> public void Reproject(WorldFile sourceReference, Bitmap sourceTile, out WorldFile targetReference, out Bitmap targetTile) { if (source == null || target == null || source.Equals(target)) { targetReference = sourceReference; targetTile = sourceTile; return; } Rectangle targetTileExtentInPixelCoordinates = GetTargetExtentInPixelCoordinates(sourceReference, sourceTile); // Get the intersection with the current viewport targetTileExtentInPixelCoordinates.Intersect(mapArgs.ImageRectangle); // Is it empty, don't return anything if (targetTileExtentInPixelCoordinates.Width == 0 || targetTileExtentInPixelCoordinates.Height == 0) { targetTile = null; targetReference = null; return; } int offsetX = targetTileExtentInPixelCoordinates.X; int offsetY = targetTileExtentInPixelCoordinates.Y; // Prepare the result tile targetTile = new Bitmap(targetTileExtentInPixelCoordinates.Size.Width, targetTileExtentInPixelCoordinates.Size.Height, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(targetTile)) { g.Clear(Color.Transparent); } ColorAccess sourceTileColorAccess = ColorAccess.Create(sourceTile); ColorAccess targetTileColorAccess = ColorAccess.Create(targetTile); // Copy values to output buffer Size sourceTileSize = sourceTile.Size; for (var i = 0; i < targetTile.Height; i++) { foreach (Tuple <Point, Point> ppair in GetValidPoints(offsetY + i, offsetY, offsetX, offsetX + targetTile.Width, sourceReference, sourceTileSize)) { Color c = sourceTileColorAccess[ppair.Item1.X, ppair.Item1.Y]; targetTileColorAccess[ppair.Item2.X, ppair.Item2.Y] = c; } } // Copy to output tile targetTileColorAccess.SetBufferToImageAtOriginalLocation(targetTile); // Compute the reference Extent outExtent = mapArgs.PixelToProj(targetTileExtentInPixelCoordinates); targetReference = new WorldFile( outExtent.Width / targetTileExtentInPixelCoordinates.Width, 0, 0, -outExtent.Height / targetTileExtentInPixelCoordinates.Height, outExtent.X, outExtent.Y); }
public static List <Coordinate> Reproject(this IEnumerable <Coordinate> coords, ProjectionInfo srcProjection, ProjectionInfo destProjection) { List <Coordinate> destCoords = null; if (coords == null) { return(destCoords); } destCoords = new List <Coordinate>(); if (srcProjection == null || destProjection == null || srcProjection.Equals(destProjection)) { destCoords.AddRange(coords); } else { double[] z = { 0, 0 }; var coordCount = coords.Count(); double[] mapVertices = new double[2 * coordCount]; for (int i = 0; i < coordCount; i++) { var coord = coords.ElementAt(i); mapVertices[i * 2] = coord.X; mapVertices[i * 2 + 1] = coord.Y; } Projections.Reproject.ReprojectPoints(mapVertices, z, srcProjection, destProjection, 0, mapVertices.Length / 2); for (int i = 0; i < coordCount; i++) { var coord = new Coordinate(mapVertices[i * 2], mapVertices[i * 2 + 1]); destCoords.Add(coord); } } return(destCoords); }
public override bool Equals(object obj) { CoordinateSystem other = obj as CoordinateSystem; if (other == null) { return(false); } return(Projection.Equals(other.Projection)); }
public void ToEsriStringWGS1984Test() { ProjectionInfo p1 = KnownCoordinateSystems.Geographic.World.WGS1984; const string esri = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; ProjectionInfo p2 = ProjectionInfo.FromEsriString(esri); string expected = p2.ToEsriString(); string actual = p1.ToEsriString(); Assert.AreEqual(expected, actual); Assert.IsTrue(p1.Equals(p2)); }
public void ToEsriStringNorthAmericanDatum1983Test() { ProjectionInfo p1 = KnownCoordinateSystems.Geographic.NorthAmerica.NorthAmericanDatum1983; const string esri = "GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101004]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; ProjectionInfo p2 = ProjectionInfo.FromEsriString(esri); string expected = p2.ToEsriString(); string actual = p1.ToEsriString(); Assert.AreEqual(expected, actual); Assert.IsTrue(p1.Equals(p2)); }
/// <summary> /// Converts all feature related data from <paramref name="data"/> to <paramref name="layer"/>. /// </summary> /// <param name="data">The data to convert the feature related data from.</param> /// <param name="layer">The layer to convert the feature related data to.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="data"/> or <paramref name="layer"/> is <c>null</c>.</exception> public void ConvertLayerFeatures(TFeatureBasedMapData data, TMapFeatureLayer layer) { ValidateParameters(data, layer); ClearLayerData(data, layer); SetDataTableColumns(data.MetaData, layer); ProjectionInfo originalLayerProjection = layer.Projection; if (originalLayerProjection == null || !originalLayerProjection.Equals(MapDataConstants.FeatureBasedMapDataCoordinateSystem)) { layer.Projection = MapDataConstants.FeatureBasedMapDataCoordinateSystem; } Dictionary <string, int> attributeMapping = GetAttributeMapping(data); foreach (MapFeature mapFeature in data.Features) { IEnumerable <IFeature> features = CreateFeatures(mapFeature); foreach (IFeature feature in features) { AddFeatureToLayer(layer, feature, mapFeature, attributeMapping); } } layer.DataSet.InitializeVertices(); layer.DataSet.UpdateExtent(); if (originalLayerProjection != null && !originalLayerProjection.Equals(MapDataConstants.FeatureBasedMapDataCoordinateSystem)) { layer.Reproject(originalLayerProjection); } layer.AssignFastDrawnStates(); }
public static bool Reproject(double srcX, double srcY, ProjectionInfo srcProjection, ProjectionInfo destProjection, out double destX, out double destY) { bool ret = false; destX = srcX; destY = srcY; if (srcProjection == null || destProjection == null || srcProjection.Equals(destProjection)) { return(ret); } double[] z = { 0, 0 }; var mapVertices = new[] { srcX, srcY }; Projections.Reproject.ReprojectPoints(mapVertices, z, srcProjection, destProjection, 0, mapVertices.Length / 2); destX = mapVertices[0]; destY = mapVertices[1]; ret = true; return(ret); }
private void OnMouseMove(object sender, GeoMouseArgs e) { double x = e.GeographicLocation.X; double y = e.GeographicLocation.Y; if (!targetProjection.Equals(map.Projection)) { double[] xy = { x, y }; Reproject.ReprojectPoints(xy, new[] { 0.0 }, map.Projection, targetProjection, 0, 1); x = xy[0]; y = xy[1]; } xLabel.Text = $@"X: {x:0.#####}"; yLabel.Text = $@"Y: {y:0.#####}"; }
public static Extent Reproject(this Extent extent, ProjectionInfo srcProjection, ProjectionInfo destProjection) { Extent destExtent = extent.Copy(); if (extent == null || srcProjection == null || destProjection == null || srcProjection.Equals(destProjection)) { return(destExtent); } var xmin = extent.MinX; var xmax = extent.MaxX; var ymin = extent.MinY; var ymax = extent.MaxY; double[] z = { 0, 0 }; var mapVertices = new[] { xmin, ymax, xmax, ymin }; Projections.Reproject.ReprojectPoints(mapVertices, z, srcProjection, destProjection, 0, mapVertices.Length / 2); destExtent.MinX = mapVertices[0]; destExtent.MinY = mapVertices[3]; destExtent.MaxX = mapVertices[2]; destExtent.MaxY = mapVertices[1]; return(destExtent); }
public bool Identity() { return(Source.Equals(Target)); }
public void HandleRow(string textline) { Hashtable rs = _aisParser.Parse(textline); if (rs != null) { if (rs.ContainsKey("MessageType")) { switch ((uint)rs["MessageType"]) { case 1: case 2: case 3: double[] pointCoords = { (double)rs["Longitude"], (double)rs["Latitude"] }; double[] z = { 0 }; if (!_projectionInfo.Equals(KnownCoordinateSystems.Geographic.World.WGS1984)) { Reproject.ReprojectPoints(pointCoords, z, KnownCoordinateSystems.Geographic.World.WGS1984, _projectionInfo, 0, 1); } Coordinate coord = new Coordinate(pointCoords[0], pointCoords[1]); IFeature feature; List <int> results = VesselsFeatureSet.Find(string.Format("[MMSI]={0}", rs["MMSI"])); if (results != null && results.Any()) { feature = VesselsFeatureSet.GetFeature(results[0]); feature.Coordinates[0] = coord; } else { DotSpatial.Topology.Point point = new DotSpatial.Topology.Point(coord); feature = VesselsFeatureSet.AddFeature(point); } // // Fix values outside range if (double.IsInfinity((double)rs["CourseOverGround"]) || double.IsNaN((double)rs["CourseOverGround"])) { rs["CourseOverGround"] = 0F; } if (double.IsInfinity((double)rs["SpeedOverGround"]) || double.IsNaN((double)rs["SpeedOverGround"])) { rs["SpeedOverGround"] = 0F; } foreach (DictionaryEntry item in rs) { feature.DataRow[item.Key.ToString()] = item.Value; } break; case 5: break; default: break; } } } }