Renamed GeoImage

This commit is contained in:
Clemens 2022-01-16 18:39:50 +01:00
parent abde6ad9fd
commit 41cd7c569d
7 changed files with 307 additions and 22 deletions

View file

@ -29,7 +29,7 @@ using System.Windows.Media.Imaging;
namespace MapControl.Images
{
public partial class GeoTaggedImage
public partial class GeoImage
{
private const string PixelScaleQuery = "/ifd/{ushort=33550}";
private const string TiePointQuery = "/ifd/{ushort=33922}";
@ -37,7 +37,7 @@ namespace MapControl.Images
private const string NoDataQuery = "/ifd/{ushort=42113}";
public static readonly DependencyProperty PathProperty = DependencyProperty.RegisterAttached(
"Path", typeof(string), typeof(GeoTaggedImage), new PropertyMetadata(null, PathPropertyChanged));
"Path", typeof(string), typeof(GeoImage), new PropertyMetadata(null, PathPropertyChanged));
public BitmapSource Bitmap { get; }
public Matrix Transform { get; }
@ -45,7 +45,7 @@ namespace MapControl.Images
public BoundingBox BoundingBox { get; }
public double Rotation { get; }
public GeoTaggedImage(BitmapSource bitmap, Matrix transform, MapProjection projection)
public GeoImage(BitmapSource bitmap, Matrix transform, MapProjection projection)
{
Bitmap = bitmap;
Transform = transform;
@ -87,7 +87,7 @@ namespace MapControl.Images
image.SetValue(PathProperty, path);
}
public static Task<GeoTaggedImage> ReadImage(string imageFilePath)
public static Task<GeoImage> ReadImage(string imageFilePath)
{
var ext = Path.GetExtension(imageFilePath);
if (ext.Length < 4)
@ -107,7 +107,7 @@ namespace MapControl.Images
return ReadGeoTiff(imageFilePath);
}
public static async Task<GeoTaggedImage> ReadImage(string imageFilePath, string worldFilePath, string projFilePath = null)
public static async Task<GeoImage> ReadImage(string imageFilePath, string worldFilePath, string projFilePath = null)
{
var transform = ReadWorldFile(worldFilePath);
@ -117,7 +117,7 @@ namespace MapControl.Images
var bitmap = (BitmapSource)await ImageLoader.LoadImageAsync(imageFilePath);
return new GeoTaggedImage(bitmap, transform, projection);
return new GeoImage(bitmap, transform, projection);
}
public static Matrix ReadWorldFile(string path)

View file

@ -40,14 +40,14 @@
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Shared\GeoTaggedImage.cs">
<Link>GeoTaggedImage.cs</Link>
<Compile Include="..\Shared\GeoImage.cs">
<Link>GeoImage.cs</Link>
</Compile>
<Compile Include="..\Shared\GroundOverlayPanel.cs">
<Link>GroundOverlayPanel.cs</Link>
</Compile>
<Compile Include="..\WinUI\GeoTaggedImage.WinUI.cs">
<Link>GeoTaggedImage.WinUI.cs</Link>
<Compile Include="..\WinUI\GeoImage.WinUI.cs">
<Link>GeoImage.WinUI.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Properties\MapImages.UWP.rd.xml" />

View file

@ -11,11 +11,11 @@ using System.Windows.Media.Imaging;
namespace MapControl.Images
{
public partial class GeoTaggedImage
public partial class GeoImage
{
public static Task<GeoTaggedImage> ReadGeoTiff(string imageFilePath)
public static Task<GeoImage> ReadGeoTiff(string imageFilePath)
{
return Task.Run(() =>
return Task.Run((Func<GeoImage>)(() =>
{
BitmapSource bitmap;
Matrix transform;
@ -27,12 +27,12 @@ namespace MapControl.Images
var metadata = bitmap.Metadata as BitmapMetadata;
if (metadata.GetQuery(PixelScaleQuery) is double[] pixelScale && pixelScale.Length == 3 &&
metadata.GetQuery(TiePointQuery) is double[] tiePoint && tiePoint.Length >= 6)
if (metadata.GetQuery((string)PixelScaleQuery) is double[] pixelScale && pixelScale.Length == 3 &&
metadata.GetQuery((string)TiePointQuery) is double[] tiePoint && tiePoint.Length >= 6)
{
transform = new Matrix(pixelScale[0], 0d, 0d, -pixelScale[1], tiePoint[3], tiePoint[4]);
}
else if (metadata.GetQuery(TransformQuery) is double[] tform && tform.Length == 16)
else if (metadata.GetQuery((string)TransformQuery) is double[] tform && tform.Length == 16)
{
transform = new Matrix(tform[0], tform[1], tform[4], tform[5], tform[3], tform[7]);
}
@ -41,13 +41,13 @@ namespace MapControl.Images
throw new ArgumentException("No coordinate transformation found in \"" + imageFilePath + "\".");
}
if (metadata.GetQuery(NoDataQuery) is string noData && int.TryParse(noData, out int noDataValue))
if (metadata.GetQuery((string)NoDataQuery) is string noData && int.TryParse(noData, out int noDataValue))
{
bitmap = ConvertTransparentPixel(bitmap, noDataValue);
}
return new GeoTaggedImage(bitmap, transform, null);
});
return new GeoImage(bitmap, transform, (MapProjection)null);
}));
}
public static BitmapSource ConvertTransparentPixel(BitmapSource source, int transparentPixel)

View file

@ -17,9 +17,9 @@ using Windows.UI.Xaml.Media.Imaging;
namespace MapControl.Images
{
public partial class GeoTaggedImage
public partial class GeoImage
{
public static async Task<GeoTaggedImage> ReadGeoTiff(string imageFilePath)
public static async Task<GeoImage> ReadGeoTiff(string imageFilePath)
{
var file = await StorageFile.GetFileFromPathAsync(Path.GetFullPath(imageFilePath));
@ -60,7 +60,7 @@ namespace MapControl.Images
throw new ArgumentException("No coordinate transformation found in \"" + imageFilePath + "\".");
}
return new GeoTaggedImage(bitmap, transform, null);
return new GeoImage(bitmap, transform, null);
}
}
}