Library to work with geographic coordinates
- Support to
- Dependencies
- How to use
- Contribution
- .NET 9.0
- .NET 8.0
- .NET 7.0
- .NET 6.0
- .NET 5.0
- .NET 3.1
- .NET Standard 2.1
- .NET Framework 4.6.2 or more
- Newtonsoft.Json NuGet (.NET Framework 4.6.2 | .NET Framework 4.8 | .NET Standard 2.1)
This package is available through Nuget Packages: https://www.nuget.org/packages/PowerUtils.Geolocation
Nuget
Install-Package PowerUtils.Geolocation
.NET CLI
dotnet add package PowerUtils.Geolocation
namespace PowerUtils.Geolocation.Exceptions
InvalidCoordinateException(coordinate);
MinLatitudeException(coordinate);
MaxLatitudeException(coordinate);
MinLongitudeException(coordinate);
MaxLongitudeException(coordinate);
namespace PowerUtils.Geolocation.Types
public enum CardinalDirection
{
North,
South,
East,
West,
}
public enum DistanceUnit
{
kilometer,
Meter,
Mile
}
public enum GeographicalOrientation
{
Latitude,
Longitude
}
namespace PowerUtils.Geolocation
Convert kilometers to meters (int, uint, long, ulong, float, double, decimal)
// result = 45_000
var result = 45.FromKilometerToMeter();
Convert kilometers to miles (float, double, decimal)
// result = 137.472_122
var result = (221.24).FromKilometerToMile();
Converting (double, decimal, float) numbers in kilometers to a new unit
// result = 20_000
var result = 20.FromKilometerTo(DistanceUnit.Meter);
Convert meters to kilometers (int, uint, long, ulong, float, double, decimal)
// result = 45
var result = (45_000).FromMeterToKilometer();
Convert meters to kilometers (float, double, decimal)
// result = 7.098204899547
var result = (11_423.457).FromMeterToMile();
Converting (double, decimal, float) numbers in meters to a new unit
// result = 0.002
var result = 2.FromMeterTo(DistanceUnit.kilometer);
Convert miles to meters (float, double, decimal)
// result = 356_050.3816
var result = (221.24).FromMileToMeter();
Convert miles to kilometers (float, double, decimal)
// result = 356.05038160000004
var result = (221.24).FromMileToKilometer();
Converting (double, decimal, float) numbers in miles to a new unit
// result = 32_18.68
var result = 2.FromMileTo(DistanceUnit.kilometer);
Get the geographical orientation from a specific cardinal direction
// result = GeographicalOrientation.Longitude
var result = CardinalDirection.North.GetGeographicalOrientation();
Convert degree to radian (PI / 180)
// result = 0.19198621771937624
var result = 11.ToRadian();
Convert radian to degree (180 / PI)
// result = 11
var result = (0.19198621771937624).ToDegree();
Convert radian to degree (180 / PI)
// result = 11
var result = (0.19198621771937624).ToDegree();
Convert decimal degree point (string) to decimal degree point (double)
// result = -8.668_173
var result = "-8,668173".ToDDPoint();
namespace PowerUtils.Geolocation
Decimal degree coordinate
var coordinate = new GeoDDCoordinate(81.54, -54.1272);
(var latitude, var longitude) = coordinates;
Deconstruct GeoDDCoordinate to double latitude and double longitude
(var latitude, var longitude) = coordinates;
Create a new object 'GeoDDCoordinate' with the same data
(var newCoordinate = coordinates.Clone();
GeoDDCoordinate left = new(1.54, 54.1272);
GeoDDCoordinate right = new(1.54, 54.1272);
// result1 = true
var result1 = left == right;
// result2 = false
var result2 = left != right;
// result3 = true
var result3 = left.Equals(right);
var text1 = "-12.51214,14.1272";
var coordinate = (GeoDDCoordinate)text1;
var text2 = (string)coordinate;
var coordinate1 = GeoDDCoordinate.Parse("12,152", "-8,12");
var coordinate2 = GeoDDCoordinate.Parse("81.54 , -54.1272");
var result3 = GeoDDCoordinate.TryParse("12,152", "-8,12", out var coordinate3);
var result4 = GeoDDCoordinate.TryParse("81.54 , -54.1272", out var coordinate4);
// distance1 = 189143
var distance1 = GeoDDCoordinate.Distance(37.165611, -8.545786, 38.737545, -9.370047, 0);
// distance2 = 18542.719416538552
var distance2 = GeoDDCoordinate.PreciseDistance(37.068673, -7.939493, 37.098708, -8.145107);
GeoDDCoordinate left = new(37.068673, -7.939493);
GeoDDCoordinate right = new(37.098708, -8.145107);
// distance3 = 18543
var distance3 = left.Distance(right);
var coordinate = new GeoDDCoordinate(9.1, 12);
var result = new GeoJSON(coordinate);
var coordinate = new GeoDDCoordinate(9.1, 12);
var geoJSON = (GeoJSON)coordinate;
var result = (GeoDDCoordinate)geoJSON;
var latitude = GuardGeolocation.Against.Latitude(degree);
var longitude = GuardGeolocation.Against.Longitude(degree);
- Exception
- MinLatitudeException
- MaxLatitudeException
- Exception
- MinLongitudeException
- MaxLongitudeException
If you have any questions, comments, or suggestions, please open an issue or create a pull request