The purpose of the library is to check whether or not a coordinate point (Latitude, Longitude) is on water. It also provides a method to generate a random GeoPoint(double latitude, double longitude)
with a OnWater boolean as a parameter.
-
OnWater: C# Library project.
- OnWaterLib.cs: Main library which contains
IsOnWater(GeoPoint p)
andGenerateRandomGeoPoint(bool OnWater = false)
methods. - Utilities.cs: utility classes such as
PixelPoint
,GeoPoint
and some utility methods. - water_8k.png: 8k world water image used to check the point.
- OnWaterLib.cs: Main library which contains
-
OnWater.Tests: Console application used to test the library mentioned above.
It follows these steps:
- Get
GeoPoint (double latitude, double longitude)
point. - Convert it into
PixelPoint(int X, int Y)
point usingCoordsToPixels(double latitude, double longitude)
inside Utilities.cs. - Check the
(X, Y)
pixel's color inside water_8k.png. - If it is white the point is on water, otherwise it is on land.
private bool IsOnWater(PixelPoint p)
{
Color color = Bmp.GetPixel(p.X, p.Y);
if (color.Name == "ffffffff")
return true;
return false;
}
public static PixelPoint CoordsToPixels(double latitude, double longitude)
{
var x = (longitude + 180) / 360 * 8192;
var y = 4096 / 2 - latitude * 4096 / 180;
return new PixelPoint((int)x, (int)y);
}
It is a simple proportion knowing that longitude goes from -180 to +180 and latitude goes from -90 to +90. You can get additional information about how latitude and longitude works following this link. 8192 and 4096 are water_8k.png dimensions.
- 02 March 2019: First release