Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	DEM.Net.Core/Model/Imagery/ImageryProviders.Predefined.cs
  • Loading branch information
xfischer committed May 31, 2020
2 parents 36564f4 + e04a174 commit 85962b1
Show file tree
Hide file tree
Showing 13 changed files with 446 additions and 280 deletions.
6 changes: 6 additions & 0 deletions DEM.Net.Core/DEM.Net.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
<PropertyGroup Condition=" '$(TargetFramework)' == 'net461'">
<DefineConstants>NET461;NETFULL</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<!-- Conditionally obtain references for the .NET Framework 4.6.1 target -->
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.Net.Http" />
Expand Down
76 changes: 68 additions & 8 deletions DEM.Net.Core/Model/BoundingBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ public double yMax
set { _yMax = value; }
}

private double _zMin;
public double zMin
{
get { return _zMin; }
set { _zMin = value; }
}

private double _zMax;
public double zMax
{
get { return _zMax; }
set { _zMax = value; }
}

public double Width
{
get
Expand All @@ -78,12 +92,31 @@ public double Height
}
}

public BoundingBox(double xmin, double xmax, double ymin, double ymax)
public double Depth
{
get
{
return _zMax - _zMin;
}
}

public BoundingBox() : this(double.MaxValue, double.MinValue
, double.MaxValue, double.MinValue
, double.MaxValue, double.MinValue)
{
}
public BoundingBox(double xmin, double xmax, double ymin, double ymax) : this(xmin, xmax, ymin, ymax, double.MaxValue, double.MinValue)
{
}

public BoundingBox(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax)
{
_xMin = xmin;
_xMax = xmax;
_yMin = ymin;
_yMax = ymax;
_zMin = zmin;
_zMax = zmax;
}

public bool IsValid()
Expand All @@ -95,14 +128,25 @@ public bool IsValid()
&& GpsLocation.IsValidLatitude(_yMin)
&& GpsLocation.IsValidLatitude(_yMax);
}
public void UnionWith(double x, double y, double z)
{
_xMin = Math.Min(_xMin, x);
_xMax = Math.Max(_xMax, x);
_yMin = Math.Min(_yMin, y);
_yMax = Math.Max(_yMax, y);
_zMin = Math.Min(_zMin, z);
_zMax = Math.Max(_zMax, z);
}

/// <summary>
/// Reorders min / max and returns a new BoundingBox
/// </summary>
/// <returns></returns>
public BoundingBox ReorderMinMax()
{
return new BoundingBox(Math.Min(_xMin, _xMax), Math.Max(_xMin, _xMax), Math.Min(_yMin, _yMax), Math.Max(_yMin, _yMax));
return new BoundingBox(Math.Min(_xMin, _xMax), Math.Max(_xMin, _xMax)
, Math.Min(_yMin, _yMax), Math.Max(_yMin, _yMax)
, Math.Min(_zMin, _zMax), Math.Max(_zMin, _zMax));
}

public override bool Equals(object obj)
Expand All @@ -117,7 +161,13 @@ public BoundingBox Scale(double scale)
}
public BoundingBox Scale(double scaleX, double scaleY)
{
return new BoundingBox(xMin - Width * scaleX, xMax + Width * scaleX, yMin - Height * scaleY, yMax + Height * scaleY);
return Scale(scaleX, scaleY, 1);
}
public BoundingBox Scale(double scaleX, double scaleY, double scaleZ)
{
return new BoundingBox(xMin - Width * scaleX, xMax + Width * scaleX
, yMin - Height * scaleY, yMax + Height * scaleY
, zMin - Depth * scaleZ, zMax + Depth * scaleZ);
}
/// <summary>
/// Add padding around bbox (bbox must be projected to cartesian first)
Expand All @@ -126,18 +176,26 @@ public BoundingBox Scale(double scaleX, double scaleY)
/// <returns></returns>
public BoundingBox Pad(double paddingMeters)
{
return new BoundingBox(xMin - paddingMeters, xMax + paddingMeters, yMax + paddingMeters, yMin - paddingMeters);
return new BoundingBox(xMin - paddingMeters, xMax + paddingMeters
, yMax + paddingMeters, yMin - paddingMeters
, zMax + paddingMeters, zMin - paddingMeters);
}
public BoundingBox ScaleAbsolute(double scaleX, double scaleY)
public BoundingBox ScaleAbsolute(double scaleX, double scaleY, double scaleZ = 1)
{
return new BoundingBox(xMin * scaleX, xMax * scaleX, yMin * scaleY, yMax * scaleY);
return new BoundingBox(xMin * scaleX, xMax * scaleX
, yMin * scaleY, yMax * scaleY
, zMin * scaleZ, zMax * scaleZ);
}

public double[] Center
{
get
{
return new double[] { (xMax - xMin) / 2d + xMin, (yMax - yMin) / 2 + yMin };
return new double[] {
(xMax - xMin) / 2d + xMin
, (yMax - yMin) / 2d + yMin
, (zMax - zMin) / 2d + zMin
};
}
}

Expand All @@ -164,7 +222,9 @@ public static BoundingBox AroundPoint(double lat, double lon, double size)

public override string ToString()
{
return $"Xmin: {xMin}, Xmax: {xMax}, Ymin: {yMin}, Ymax: {yMax}";
// "Xmin: {xMin}, Xmax: {xMax}, Ymin: {yMin}, Ymax: {yMax}, Zmin: {zMin}, Zmax: {zMax}, Center: {this.Center[0]}, this.Center";
return string.Format(CultureInfo.InvariantCulture, "Xmin: {0}, Xmax: {1}, Ymin: {2}, Ymax: {3}, Zmin: {4}, Zmax: {5}, Center: {6}, {7}, {8}"
, xMin, xMax, yMin, yMax, zMin, zMax, Center[0], Center[1], Center[2]);
}

public bool Equals(BoundingBox other)
Expand Down
32 changes: 14 additions & 18 deletions DEM.Net.Core/Model/Imagery/ImageryProviders.Predefined.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace DEM.Net.Core.Imagery
namespace DEM.Net.Core.Imagery
{
public partial class ImageryProvider
{
public const string ATTRIBUTION_SUBJECT = "Imagery";
#if DEBUG
public static readonly ImageryProvider DebugProvider = new TileDebugProvider(null);
#endif
public static readonly ImageryProvider MapBoxSatellite = new ImageryProvider()
public static readonly ImageryProvider MapBoxSatellite = new ImageryProvider
{
Name = "MapBox-Satellite",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "MapBox Satellite", "https://www.mapbox.com", "© MapBox - OpenStreetMap contributors"),
Expand All @@ -20,7 +16,7 @@ public partial class ImageryProvider
TileSize = 256,
MaxZoom = 23
};
public static readonly ImageryProvider MapBoxSatelliteStreet = new ImageryProvider()
public static readonly ImageryProvider MapBoxSatelliteStreet = new ImageryProvider
{
Name = "MapBox-SatelliteStreet",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "MapBox Satellite Street", "https://www.mapbox.com", "© MapBox - OpenStreetMap contributors"),
Expand All @@ -29,7 +25,7 @@ public partial class ImageryProvider
TokenUserSecretsKey = "MapBoxToken",
MaxZoom = 23
};
public static readonly ImageryProvider MapBoxStreets = new ImageryProvider()
public static readonly ImageryProvider MapBoxStreets = new ImageryProvider
{
Name = "MapBox-Streets",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "MapBox Streets", "https://www.mapbox.com", "© MapBox - OpenStreetMap contributors"),
Expand All @@ -38,7 +34,7 @@ public partial class ImageryProvider
//UrlModel = new UrlModel("https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/256/{z}/{x}/{y}?access_token={t}", null),
MaxZoom = 23
};
public static readonly ImageryProvider MapBoxOutdoors = new ImageryProvider()
public static readonly ImageryProvider MapBoxOutdoors = new ImageryProvider
{
Name = "MapBox-Outdoors",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "MapBox Outdoors", "https://www.mapbox.com", "© MapBox - OpenStreetMap contributors"),
Expand All @@ -47,7 +43,7 @@ public partial class ImageryProvider
//UrlModel = new UrlModel("https://api.mapbox.com/styles/v1/mapbox/outdoors-v11/tiles/256/{z}/{x}/{y}?access_token={t}", null),
MaxZoom = 23
};
public static readonly ImageryProvider MapBoxLight = new ImageryProvider()
public static readonly ImageryProvider MapBoxLight = new ImageryProvider
{
Name = "MapBox-Light",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "MapBox Light", "https://www.mapbox.com", "© MapBox - OpenStreetMap contributors"),
Expand All @@ -56,7 +52,7 @@ public partial class ImageryProvider
//UrlModel = new UrlModel("https://api.mapbox.com/styles/v1/mapbox/light-v10/tiles/256/{z}/{x}/{y}?access_token={t}", null),
MaxZoom = 23
};
public static readonly ImageryProvider MapBoxDark = new ImageryProvider()
public static readonly ImageryProvider MapBoxDark = new ImageryProvider
{
Name = "MapBox-Dark",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "MapBox Dark", "https://www.mapbox.com", "© MapBox - OpenStreetMap contributors"),
Expand All @@ -65,53 +61,53 @@ public partial class ImageryProvider
//UrlModel = new UrlModel("https://api.mapbox.com/styles/v1/mapbox/dark-v10/tiles/256/{z}/{x}/{y}?access_token={t}", null),
MaxZoom = 23
};
public static readonly ImageryProvider StamenToner = new ImageryProvider()
public static readonly ImageryProvider StamenToner = new ImageryProvider
{
Name = "Stamen-Toner",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "Stamen Toner", "https://stamen.com/", "Map tiles by <a href=\"http://stamen.com\">Stamen Design</a>, under <a href=\"http://creativecommons.org/licenses/by/3.0\">CC BY 3.0</a>. Data by <a href=\"http://openstreetmap.org\">OpenStreetMap</a>, under <a href=\"http://www.openstreetmap.org/copyright\">ODbL</a>."),
UrlModel = new UrlModel("http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png", new[] { "a", "b", "c", "d" }),
MaxZoom = 14
};
public static readonly ImageryProvider StamenWaterColor = new ImageryProvider()
public static readonly ImageryProvider StamenWaterColor = new ImageryProvider
{
Name = "Stamen-Watercolor",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "Stamen Watercolor", "https://stamen.com/", "Map tiles by <a href=\"http://stamen.com\">Stamen Design</a>, under <a href=\"http://creativecommons.org/licenses/by/3.0\">CC BY 3.0</a>. Data by <a href=\"http://openstreetmap.org\">OpenStreetMap</a>, under <a href=\"http://creativecommons.org/licenses/by-sa/3.0\">CC BY SA</a>."),
UrlModel = new UrlModel("http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg", new[] { "a", "b", "c", "d" }),
MaxZoom = 14
};
public static readonly ImageryProvider OpenTopoMap = new ImageryProvider()
public static readonly ImageryProvider OpenTopoMap = new ImageryProvider
{
Name = "OpenTopoMap",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "OpenTopoMap",
"Map data: © <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors, <a href=\"http://viewfinderpanoramas.org\"> SRTM</a> | Map style: &copy; <a href=\"https://opentopomap.org\" > OpenTopoMap</a> (<a href=\"https://creativecommons.org/licenses/by-sa/3.0/\" > CC-BY-SA</a>)"),
UrlModel = new UrlModel("https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png", new[] { "a", "b", "c" }),
MaxZoom = 17
};
public static readonly ImageryProvider EsriWorldImagery = new ImageryProvider()
public static readonly ImageryProvider EsriWorldImagery = new ImageryProvider
{
Name = "Esri.WorldImagery",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "Esri World Imagery", "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer", "Source: Esri, DigitalGlobe, GeoEye, Earthstar Geographics, CNES/Airbus DS, USDA, USGS, AeroGRID, IGN, and the GIS User Community"),
UrlModel = new UrlModel("https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}", null),
MaxZoom = 18,
PrivateUseOnly = true
};
public static readonly ImageryProvider ThunderForestOutdoors = new ImageryProvider()
public static readonly ImageryProvider ThunderForestOutdoors = new ImageryProvider
{
Name = "ThunderForest-Outdoors",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "ThunderForest", "https://www.thunderforest.com", "Maps © www.thunderforest.com, Data © www.osm.org/copyright"),
UrlModel = new UrlModel("https://tile.thunderforest.com/outdoors/{z}/{x}/{y}.png?apikey={t}", null),
TokenUserSecretsKey = "ThunderForestApiKey",
MaxZoom = 22
};
public static readonly ImageryProvider ThunderForestLandscape = new ImageryProvider()
public static readonly ImageryProvider ThunderForestLandscape = new ImageryProvider
{
Name = "ThunderForest-Landscape",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "ThunderForest", "https://www.thunderforest.com", "Maps © www.thunderforest.com, Data © www.osm.org/copyright"),
UrlModel = new UrlModel("https://tile.thunderforest.com/landscape/{z}/{x}/{y}.png?apikey={t}", null),
TokenUserSecretsKey = "ThunderForestApiKey",
MaxZoom = 22
};
public static readonly ImageryProvider ThunderForestNeighbourhood = new ImageryProvider()
public static readonly ImageryProvider ThunderForestNeighbourhood = new ImageryProvider
{
Name = "ThunderForest-Neighbourhood",
Attribution = new Attribution(ATTRIBUTION_SUBJECT, "ThunderForest", "https://www.thunderforest.com", "Maps © www.thunderforest.com, Data © www.osm.org/copyright"),
Expand Down
1 change: 0 additions & 1 deletion DEM.Net.Core/Model/Imagery/MapTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ public MapTile(byte[] imgBytes, int tileSize, Uri tileUri, MapTileInfo mapTileIn
public Uri Uri { get; set; }
public byte[] Image { get; set; }


}
}
46 changes: 46 additions & 0 deletions DEM.Net.Core/Model/Imagery/MapTileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,51 @@ public MapTileInfo(PointInt xy, int zoom)
public int X { get; set; }
public int Y { get; set; }
public int Zoom { get; set; }

public int TileSize => 256;

public TileRange ZoomIn()
{
if (Zoom == 23) return new TileRange(this,this,this.TileSize);

return new TileRange(this.ZoomIn("0"), this.ZoomIn("3"), this.TileSize);
}
public TileRange ToTileRange()
{
return new TileRange(this, this, this.TileSize);
}
public MapTileInfo ZoomIn(string quadIndex)
{
if (Zoom == 23) return this;

TileUtils.QuadKeyToTileXY(string.Concat(TileUtils.TileXYToQuadKey(X, Y, Zoom), quadIndex), out int x0, out int y0, out int z0);
return new MapTileInfo(x0, y0, z0);
}
public MapTileInfo ZoomOut()
{
if (Zoom == 1) return this;

var quadKey = TileUtils.TileXYToQuadKey(X, Y, Zoom);
TileUtils.QuadKeyToTileXY(quadKey.Substring(0, quadKey.Length - 1), out int x0, out int y0, out int z0);
return new MapTileInfo(x0, y0, z0);
}

public override string ToString()
{
return $"{X}_{Y}_z{Zoom}";
}

public BoundingBox BoundingBox
{
get
{
var bboxTopLeft = TileUtils.TileXYToPixelXY(this.X, this.Y);
var bboxBottomRight = TileUtils.TileXYToPixelXY(this.X + 1, this.Y + 1);
var coordTopLeft = TileUtils.PixelXYToLatLong(bboxTopLeft.X, bboxTopLeft.Y, Zoom);
var coordBottomRight= TileUtils.PixelXYToLatLong(bboxBottomRight.X-1, bboxBottomRight.Y-1, Zoom);

return new BoundingBox(coordTopLeft.Long, coordBottomRight.Long, coordBottomRight.Lat, coordTopLeft.Lat);
}
}
}
}

0 comments on commit 85962b1

Please sign in to comment.