public void Reproject_DifferentCoordinateSystems_ReprojectImageAndMetaData() { // Setup var mapArgs = new MapArgs(new Rectangle(0, 0, 722, 349), new Extent(520981.864447542, 6853700.54100246, 709995.365081098, 6945065.79269375)); ProjectionInfo sourceProjection = ProjectionInfo.FromEpsgCode(25831); ProjectionInfo targetProjection = KnownCoordinateSystems.Projected.World.WebMercator; var projector = new TileReprojector(mapArgs, sourceProjection, targetProjection); var sourceReference = new WorldFile(140, 0.0, 0.0, -140, 641716.59261121, 5825498); Bitmap sourceTile = Resources.source; WorldFile targetReference; Bitmap targetTile; // Call projector.Reproject(sourceReference, sourceTile, out targetReference, out targetTile); // Assert // Note: These ground truth values have been defined using https://github.com/FObermaier/DotSpatial.Plugins/blob/master/DotSpatial.Plugins.BruTileLayer/Reprojection/TileReprojector.cs Assert.AreEqual(261.791552124038, targetReference.A11, 1e-8); Assert.AreEqual(0.0, targetReference.A21); Assert.AreEqual(0.0, targetReference.A12); Assert.AreEqual(-261.79155212403651, targetReference.A22, 1e-8); Assert.AreEqual(564962.84520438069, targetReference.B1, 1e-8); Assert.AreEqual(6902131.9781454066, targetReference.B2, 1e-8); TestHelper.AssertImagesAreEqual(Resources.target, targetTile); }
private void DrawTile(MapArgs args, TileInfo info, Resolution resolution, byte[] buffer, TileReprojector tr = null) { if (buffer == null || buffer.Length == 0) { return; } tr = tr ?? new TileReprojector(args, _sourceProjection, _targetProjection); using (var bitmap = (Bitmap)Image.FromStream(new MemoryStream(buffer))) { var inWorldFile = new WorldFile(resolution.UnitsPerPixel, 0, 0, -resolution.UnitsPerPixel, info.Extent.MinX, info.Extent.MaxY); WorldFile outWorldFile; Bitmap outBitmap; tr.Reproject(inWorldFile, bitmap, out outWorldFile, out outBitmap); if (outWorldFile == null) { return; } var lt = args.ProjToPixel(outWorldFile.ToGround(0, 0)); var rb = args.ProjToPixel(outWorldFile.ToGround(outBitmap.Width, outBitmap.Height)); var rect = new Rectangle(lt, Size.Subtract(new Size(rb), new Size(lt))); args.Device.DrawImage(outBitmap, rect, 0, 0, outBitmap.Width, outBitmap.Height, GraphicsUnit.Pixel, _imageAttributes); if (outBitmap != bitmap) { outBitmap.Dispose(); } if (FrameTile) { if (FramePen != null) { args.Device.DrawRectangle(FramePen, rect); } } } }
public void Reproject_SameProjection_ReturnSourceMaterial() { // Setup ProjectionInfo projection = KnownCoordinateSystems.Projected.NationalGrids.Rijksdriehoekstelsel; var mapArgs = new MapArgs(new Rectangle(), new Extent()); var projector = new TileReprojector(mapArgs, projection, projection); var sourceReference = new WorldFile(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); Bitmap sourceTile = Resources.testImage; WorldFile targetReference; Bitmap targetTile; // Call projector.Reproject(sourceReference, sourceTile, out targetReference, out targetTile); // Assert Assert.AreSame(sourceReference, targetReference); Assert.AreSame(sourceTile, targetTile); }
public void Reproject_TargetTileWouldNotBeVisibleInViewport_ReturnNull() { // Setup ProjectionInfo sourceProjection = KnownCoordinateSystems.Projected.NationalGrids.Rijksdriehoekstelsel; ProjectionInfo targetProjection = KnownCoordinateSystems.Projected.World.WebMercator; var mapArgs = new MapArgs(new Rectangle(0, 0, 10, 10), new Extent(5, 50, 10, 100)); var projector = new TileReprojector(mapArgs, sourceProjection, targetProjection); var sourceReference = new WorldFile(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); Bitmap sourceTile = Resources.testImage; WorldFile targetReference; Bitmap targetTile; // Call projector.Reproject(sourceReference, sourceTile, out targetReference, out targetTile); // Assert Assert.IsNull(targetReference); Assert.IsNull(targetTile); }