SHARE
TWEET

GIS functions.

chmodseven Jan 24th, 2020 125 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using GeoUK;
  3. using GeoUK.Coordinates;
  4. using GeoUK.Ellipsoids;
  5. using GeoUK.Projections;
  6. using Convert = GeoUK.Convert;
  7.  
  8. // ReSharper disable UnusedMember.Global
  9.  
  10. namespace Tesseraction.Maps
  11. {
  12.     public static class GisFunctions
  13.     {
  14.         private const bool UseOstnAddonDefault = true;
  15.  
  16.         public static GisPosition FromEastingNorthingToLatitudeLongitude (GisPosition eastingNorthingPosition, bool useOstnAddon = UseOstnAddonDefault)
  17.         {
  18.             try
  19.             {
  20.                 if (useOstnAddon)
  21.                 {
  22.                     Cartesian osgb36Cartesian = Convert.ToCartesian (new Airy1830 (), new BritishNationalGrid (),
  23.                         new EastingNorthing (eastingNorthingPosition.easting, eastingNorthingPosition.northing));
  24.                     Cartesian etrs89Cartesian = Transform.Osgb36ToEtrs89 (osgb36Cartesian);
  25.                     LatitudeLongitude wgs84LatLong = Convert.ToLatitudeLongitude (new Wgs84 (), etrs89Cartesian);
  26.                     return new GisPosition (wgs84LatLong.Longitude, wgs84LatLong.Latitude);
  27.                 }
  28.                 else
  29.                 {
  30.                     Cartesian osgb36Cartesian = Convert.ToCartesian (new Airy1830 (), new BritishNationalGrid (),
  31.                         new EastingNorthing (eastingNorthingPosition.easting, eastingNorthingPosition.northing));
  32.                     Cartesian etrs89Cartesian = Transform.Osgb36ToEtrs89 (osgb36Cartesian);
  33.                     LatitudeLongitude wgs84LatLong = Convert.ToLatitudeLongitude (new Wgs84 (), etrs89Cartesian);
  34.                     return new GisPosition (wgs84LatLong.Longitude, wgs84LatLong.Latitude);
  35.                 }
  36.             }
  37.             catch (Exception)
  38.             {
  39.                 return GisPosition.InvalidPosition ();
  40.             }
  41.         }
  42.  
  43.         public static GisPosition FromEastingNorthingToLatitudeLongitude (double easting, double northing, bool useOstnAddon = UseOstnAddonDefault)
  44.         {
  45.             return FromEastingNorthingToLatitudeLongitude (new GisPosition (easting, northing, GisPositionType.EastingNorthing), useOstnAddon);
  46.         }
  47.  
  48.         public static GisPosition FromLatitudeLongitudeToEastingNorthing (GisPosition latitudeLongitudePosition, bool useOstnAddon = UseOstnAddonDefault)
  49.         {
  50.             try
  51.             {
  52.                 if (useOstnAddon)
  53.                 {
  54.                     LatitudeLongitude wgs84LatLong = new LatitudeLongitude (latitudeLongitudePosition.latitude, latitudeLongitudePosition.longitude);
  55.                     Osgb36 osgb36Coordinates = GeoUK.OSTN.Transform.Etrs89ToOsgb (wgs84LatLong);
  56.                     return new GisPosition (osgb36Coordinates.Easting, osgb36Coordinates.Northing);
  57.                 }
  58.                 else
  59.                 {
  60.                     LatitudeLongitude wgs84LatLong = new LatitudeLongitude (latitudeLongitudePosition.latitude, latitudeLongitudePosition.longitude);
  61.                     Cartesian etrs89Cartesian = Convert.ToCartesian (new Wgs84 (), wgs84LatLong);
  62.                     Cartesian osgb36Cartesian = Transform.Etrs89ToOsgb36 (etrs89Cartesian);
  63.                     EastingNorthing osgb36EastingNorthing = Convert.ToEastingNorthing (new Airy1830 (), new BritishNationalGrid (), osgb36Cartesian);
  64.                     return new GisPosition (osgb36EastingNorthing.Easting, osgb36EastingNorthing.Northing);
  65.                 }
  66.             }
  67.             catch (Exception)
  68.             {
  69.                 return GisPosition.InvalidPosition ();
  70.             }
  71.         }
  72.  
  73.         public static GisPosition FromLatitudeLongitudeToEastingNorthing (double latitude, double longitude, bool useOstnAddon = UseOstnAddonDefault)
  74.         {
  75.             return FromLatitudeLongitudeToEastingNorthing (new GisPosition (longitude, latitude, GisPositionType.EastingNorthing), useOstnAddon);
  76.         }
  77.     }
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top