Skip to content

Commit

Permalink
Merge pull request #131 from Tronald/develop
Browse files Browse the repository at this point in the history
2.5.1.1
  • Loading branch information
Tronald authored Mar 31, 2020
2 parents 4585cc3 + c1d5d35 commit 6b60ec9
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 27 deletions.
1 change: 1 addition & 0 deletions CoordinateSharp/Coordinate/Coordinate.Formatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Organizations or use cases that fall under the following conditions may receive
For more information, please contact Signature Group, LLC at this address: [email protected]
*/

using System;

namespace CoordinateSharp
Expand Down
22 changes: 10 additions & 12 deletions CoordinateSharp/Coordinate/Coordinate.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public partial class Coordinate : INotifyPropertyChanged
/// </example>
public Coordinate()
{
Coordinate_Builder(0, 0, new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc), new EagerLoad());
Coordinate_Builder(0, 0, new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc), GlobalSettings.Default_EagerLoad);
}
/// <summary>
/// Creates a populated Coordinate based on signed degrees formated latitude and longitude.
Expand All @@ -86,7 +86,7 @@ public Coordinate()
/// </example>
public Coordinate(double lat, double longi)
{
Coordinate_Builder(lat, longi, new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc), new EagerLoad());
Coordinate_Builder(lat, longi, new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc), GlobalSettings.Default_EagerLoad);
}
/// <summary>
/// Creates a populated Coordinate object with an assigned GeoDate.
Expand All @@ -105,7 +105,7 @@ public Coordinate(double lat, double longi)
/// </example>
public Coordinate(double lat, double longi, DateTime date)
{
Coordinate_Builder(lat, longi, date, new EagerLoad());
Coordinate_Builder(lat, longi, date, GlobalSettings.Default_EagerLoad);
}
/// <summary>
/// Creates an empty Coordinates object with specified eager loading options.
Expand Down Expand Up @@ -206,9 +206,7 @@ private void Coordinate_Builder(double lat, double longi, DateTime date, EagerLo
{
//SET EagerLoading Setting
EagerLoadSettings = eagerLoad;

FormatOptions = new CoordinateFormatOptions();


//Use default constructor if signed degree is 0 for performance.
if (lat == 0) { latitude = new CoordinatePart(CoordinateType.Lat); }
else { latitude = new CoordinatePart(lat, CoordinateType.Lat); }
Expand Down Expand Up @@ -780,7 +778,7 @@ public static bool TryParse(string value, out Coordinate coordinate)
if (FormatFinder.TryParse(value, CartesianType.Cartesian, out coordinate))
{
Parse_Format_Type pft = coordinate.Parse_Format;
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble()); //Reset with EagerLoad back on.
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble()); //Reset with EagerLoad default settings
coordinate.parse_Format = pft;

return true;
Expand Down Expand Up @@ -810,7 +808,7 @@ public static bool TryParse(string value, DateTime geoDate, out Coordinate coord
if (FormatFinder.TryParse(value, CartesianType.Cartesian, out coordinate))
{
Parse_Format_Type pft = coordinate.Parse_Format;
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate); //Reset with EagerLoad back on.
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate); //Reset with EagerLoad default settings
coordinate.parse_Format = pft;

return true;
Expand Down Expand Up @@ -844,12 +842,12 @@ public static bool TryParse(string value, CartesianType cartesianType, out Coord
if (cartesianType == CartesianType.ECEF)
{
Distance h = coordinate.ecef.GeoDetic_Height;
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble()); //Reset with EagerLoad back on.
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble()); //Reset with EagerLoad default settings
coordinate.ecef.Set_GeoDetic_Height(coordinate, h);
}
else
{
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble()); //Reset with EagerLoad back on.
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble()); //Reset with EagerLoad default settings
}
coordinate.parse_Format = pft;

Expand Down Expand Up @@ -885,12 +883,12 @@ public static bool TryParse(string value, DateTime geoDate, CartesianType cartes
if (cartesianType == CartesianType.ECEF)
{
Distance h = coordinate.ecef.GeoDetic_Height;
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate); //Reset with EagerLoad back on.
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate); //Reset with EagerLoad default settings
coordinate.ecef.Set_GeoDetic_Height(coordinate, h);
}
else
{
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate); //Reset with EagerLoad back on.
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate); //Reset with EagerLoad default setting
}
coordinate.parse_Format = pft;

Expand Down
7 changes: 5 additions & 2 deletions CoordinateSharp/Coordinate/Coordinate.Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ public partial class Coordinate : INotifyPropertyChanged
private MilitaryGridReferenceSystem mgrs;
private Cartesian cartesian;
private ECEF ecef;


//Used to store movement/drawing information
private Coordinate drawingStartPoint;
private Coordinate previousDrawingCoordinate;

private Celestial celestialInfo;

internal double equatorial_radius;
Expand Down Expand Up @@ -256,7 +259,7 @@ public Celestial CelestialInfo
/// <summary>
/// Coordinate string formatting options.
/// </summary>
public CoordinateFormatOptions FormatOptions { get; set; }
public CoordinateFormatOptions FormatOptions { get; set; } = GlobalSettings.Default_CoordinateFormatOptions;
/// <summary>
/// Eagerloading settings.
/// </summary>
Expand Down
8 changes: 5 additions & 3 deletions CoordinateSharp/CoordinateSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ For more information, please contact Signature Group, LLC at this address: sales
<TargetFrameworks>net40; netstandard1.3; netstandard1.4; netstandard2.0; netstandard2.1;</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>2.4.3.1</Version>
<Version>2.5.1.1</Version>
<Authors>Signature Group, LLC</Authors>
<Company />
<PackageProjectUrl>https://github.com/Tronald/CoordinateSharp</PackageProjectUrl>
<PackageLicenseUrl></PackageLicenseUrl>
<Copyright>Copyright 2020</Copyright>
<Description>A simple library designed to assist with geographic coordinate conversions, formatting and location based solar and lunar information.</Description>
<PackageReleaseNotes>Adds eager loading overload to parsers for improved efficiency.</PackageReleaseNotes>
<PackageReleaseNotes>Adds a geo-fence drawer subclass that will allow for continuous shape drawing and plotting of coordinates. Adds global settings to allow application wide eager loading and output format specifications.</PackageReleaseNotes>
<PackageTags>CoordinateSharp Latitude Longitude Coordinates Geography Sun Moon Solar Lunar Time MGRS UTM Julian ECEF Sunset Sunrise Set Moonset Moonrise</PackageTags>
<!-- <PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>-->
<PackageLicenseFile>License.txt</PackageLicenseFile> <PackageIconUrl></PackageIconUrl>
<PackageId>CoordinateSharp</PackageId>
<Title>CoordinateSharp</Title>
<AssemblyVersion>2.4.3.1</AssemblyVersion>
<AssemblyVersion>2.5.1.1</AssemblyVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<SignAssembly>false</SignAssembly>
<PackageIcon>CoordinateSharpPNG.png</PackageIcon>
Expand Down Expand Up @@ -94,6 +94,8 @@ For more information, please contact Signature Group, LLC at this address: sales

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net40|AnyCPU'">
<DocumentationFile>bin\Debug\net40\CoordinateSharp.xml</DocumentationFile>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard1.3|AnyCPU'">
<DocumentationFile>bin\Debug\netstandard1.3\CoordinateSharp.xml</DocumentationFile>
Expand Down
6 changes: 3 additions & 3 deletions CoordinateSharp/Distance/Distance.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public Distance(double km)
feet = meters * 3.28084;
miles = meters * 0.000621371;
nauticalMiles = meters * 0.0005399565;
bearing = 0;//None specified
}

/// <summary>
Expand Down Expand Up @@ -231,9 +230,10 @@ private void Haversine(Coordinate coord1, Coordinate coord2)
double long1 = coord1.Longitude.ToRadians();
double lat2 = coord2.Latitude.ToRadians();
double long2 = coord2.Longitude.ToRadians();

//Distance Calcs
double R = 6371000; //6378137.0;//6371e3; //meters
double R = 6371000; //6378137.0;

double latRad = coord2.Latitude.ToRadians() - coord1.Latitude.ToRadians();
double longRad = coord2.Longitude.ToRadians() - coord1.Longitude.ToRadians();

Expand Down
6 changes: 3 additions & 3 deletions CoordinateSharp/Distance/Distance.Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public partial class Distance
private double miles;
private double feet;
private double meters;
private double bearing;
private double nauticalMiles;
private double bearing=0;
private double nauticalMiles;

/// <summary>
/// Distance in Kilometers
Expand Down Expand Up @@ -100,6 +100,6 @@ public double Feet
public double Bearing
{
get { return bearing; }
}
}
}
}
181 changes: 181 additions & 0 deletions CoordinateSharp/GeoFence/GeoFence.Drawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
CoordinateSharp is a .NET standard library that is intended to ease geographic coordinate
format conversions and location based celestial calculations.
https://github.com/Tronald/CoordinateSharp
Many celestial formulas in this library are based on Jean Meeus's
Astronomical Algorithms (2nd Edition). Comments that reference only a chapter
are referring to this work.
License
CoordinateSharp is split licensed and may be licensed under the GNU Affero General Public License version 3 or a commercial use license as stated.
Copyright (C) 2019, Signature Group, LLC
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY Signature Group, LLC. Signature Group, LLC DISCLAIMS THE WARRANTY OF
NON INFRINGEMENT OF THIRD PARTY RIGHTS.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU
Affero General Public License along with this program; if not, see http://www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA, 02110-1301 USA, or download the license from the following URL:
https://www.gnu.org/licenses/agpl-3.0.html
The interactive user interfaces in modified source and object code versions of this program must display Appropriate Legal Notices,
as required under Section 5 of the GNU Affero General Public License.
You can be released from the requirements of the license by purchasing a commercial license. Buying such a license is mandatory
as soon as you develop commercial activities involving the CoordinateSharp software without disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP, on the fly location based calculations in a web application,
or shipping CoordinateSharp with a closed source product.
Organizations or use cases that fall under the following conditions may receive a free commercial use license upon request.
-Department of Defense
-Department of Homeland Security
-Open source contributors to this library
-Scholarly or scientific uses on a case by case basis.
-Emergency response / management uses on a case by case basis.
For more information, please contact Signature Group, LLC at this address: [email protected]
*/
using System;
using System.Collections.Generic;
using System.Linq;

namespace CoordinateSharp
{

public partial class GeoFence
{
/// <summary>
/// GenFence subclass used for continuous shape drawing
/// </summary>
[Serializable]
public class Drawer
{
private Coordinate initialCoordinate; //This is the intial and always the last drawn point in the shape.
private Coordinate referenceCoordinate; //This coordinate is referenced for final bearing calculations

private double bearing;
private double finalBearing;
private Shape shape;

private List<Coordinate> points = new List<Coordinate>(); //Stores all drawn points

/// <summary>
/// Initializes the GeoFence Drawer with an initial point a bearing/facing direction.
/// </summary>
/// <param name="coordinate">Starting Coordinate</param>
/// <param name="earthShape">Earth Shape for calculations</param>
/// <param name="initialBearing">Initial bearing or direction facing</param>
/// <example>
/// The following example creates a GeoFence Drawer.
/// <code>
/// //Create a coordinate with EagerLoading off for efficiency during drawing.
/// Coordinate c = new Coordinate(31.65, -84.02, new EagerLoad(false));
///
/// //Create the GeoFence Drawer, specifying an ellipsoidal earth
/// //shape with a start bearing / direction faced of 0 degrees.
/// GeoFence.Drawer gd = new GeoFence.Drawer(c, Shape.Ellipsoid, 0);
/// </code>
/// </example>
public Drawer(Coordinate coordinate, Shape earthShape, double initialBearing)
{
//Create initial coordinate to move.
Coordinate nc = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), coordinate.GeoDate, coordinate.EagerLoadSettings);
nc.equatorial_radius = coordinate.equatorial_radius;
nc.inverse_flattening = coordinate.inverse_flattening;

//Create first point to add to points list.
Coordinate firstPoint= new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), coordinate.GeoDate, coordinate.EagerLoadSettings);
nc.equatorial_radius = coordinate.equatorial_radius;
nc.inverse_flattening = coordinate.inverse_flattening;

points.Add(firstPoint);

shape = earthShape;
initialCoordinate = nc;
bearing = (initialBearing) % 360; //normalize
finalBearing = (initialBearing) % 360; //normailza
}

/// <summary>
/// Draws line from the initial or last drawn point.
/// </summary>
/// <param name="d">Distance</param>
/// <param name="bearingChange">Bearing change in degrees</param>
/// <example>
/// The following example draws a 5 km square in the USA.
/// <code>
/// //Create a coordinate with EagerLoading off for efficiency during drawing.
/// Coordinate c = new Coordinate(31.65, -84.02, new EagerLoad(false));
///
/// //Create the GeoFence Drawer, specifying an ellipsoidal earth
/// //shape with a start bearing / direction faced of 0 degrees.
/// GeoFence.Drawer gd = new GeoFence.Drawer(c, Shape.Ellipsoid, 0);
///
/// //Draw the first line using the initial bearing (0 means no change in heading)
/// gd.Draw(new Distance(5), 0);
/// //Draw the next to line by changing 90 degrees at each point.
/// gd.Draw(new Distance(5), 90);
/// gd.Draw(new Distance(5), 90);
/// //Close the shape by drawing from the line end point to the initial coordinate.
/// gd.Close();
/// </code>
/// </example>
public void Draw(Distance d, double bearingChange)
{
//Store reference point for reverse bearing lookup
referenceCoordinate = new Coordinate(initialCoordinate.Latitude.ToDouble(), initialCoordinate.Longitude.ToDouble(), new EagerLoad(false));

//Get new bearing
//This formula will account for bearing changes of distance and offset the next movement
bearing = (finalBearing - bearing + bearing + bearingChange) % 360;
initialCoordinate.Move(d, bearing, shape);
finalBearing = (new Distance(initialCoordinate, referenceCoordinate, shape).Bearing + 180) % 360;

Coordinate nc = new Coordinate(initialCoordinate.Latitude.ToDouble(), initialCoordinate.Longitude.ToDouble(), initialCoordinate.GeoDate, initialCoordinate.EagerLoadSettings);
nc.equatorial_radius = initialCoordinate.equatorial_radius;
nc.inverse_flattening = initialCoordinate.inverse_flattening;

points.Add(nc);

}
/// <summary>
/// Draws a line to the Drawer start point (closes the shape).
/// </summary>
public void Close()
{
Coordinate c = points.First();
Coordinate nc = new Coordinate(c.Latitude.ToDouble(), c.Longitude.ToDouble(), c.GeoDate, c.EagerLoadSettings);
nc.equatorial_radius = c.equatorial_radius;
nc.inverse_flattening = c.inverse_flattening;

points.Add(nc);
}

/// <summary>
/// Get's the last point's ending Coordinate.
/// </summary>
public Coordinate Last
{
get
{
return points.Last();
}
}

/// <summary>
/// Gets all drawn points (the shape drawn).
/// </summary>
public List<Coordinate> Points
{
get { return points; }
}
}
}
}
Loading

0 comments on commit 6b60ec9

Please sign in to comment.