UTMUPS.cpp 7.4 KB
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
/**
 * \file NETGeographicLib/UTMUPS.cpp
 * \brief Implementation for NETGeographicLib::UTMUPS class
 *
 * NETGeographicLib is copyright (c) Scott Heiman (2013)
 * GeographicLib is Copyright (c) Charles Karney (2010-2012)
 * <charles@karney.com> and licensed under the MIT/X11 License.
 * For more information, see
 * https://geographiclib.sourceforge.io/
 **********************************************************************/
#include "stdafx.h"
#include "GeographicLib/UTMUPS.hpp"
#include "UTMUPS.h"
#include "NETGeographicLib.h"

using namespace NETGeographicLib;

//*****************************************************************************
int UTMUPS::StandardZone(double lat, double lon, int setzone)
{
    try
    {
        return GeographicLib::UTMUPS::StandardZone( lat, lon, setzone );
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
void UTMUPS::Forward(double lat, double lon,
                    [System::Runtime::InteropServices::Out] int% zone,
                    [System::Runtime::InteropServices::Out] bool% northp,
                    [System::Runtime::InteropServices::Out] double% x,
                    [System::Runtime::InteropServices::Out] double% y,
                    [System::Runtime::InteropServices::Out] double% gamma,
                    [System::Runtime::InteropServices::Out] double% k,
                    int setzone, bool mgrslimits)
{
    try
    {
        int lzone;
        bool lnorthp;
        double lx, ly, lgamma, lk;
        GeographicLib::UTMUPS::Forward(lat, lon,
                                       lzone, lnorthp, lx, ly,
                                       lgamma, lk,
                                       setzone, mgrslimits);
        zone = lzone;
        northp = lnorthp;
        x = lx;
        y = ly;
        gamma = lgamma;
        k = lk;
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
void UTMUPS::Reverse(int zone, bool northp, double x, double y,
                    [System::Runtime::InteropServices::Out] double% lat,
                    [System::Runtime::InteropServices::Out] double% lon,
                    [System::Runtime::InteropServices::Out] double% gamma,
                    [System::Runtime::InteropServices::Out] double% k,
                    bool mgrslimits)
{
    try
    {
        double llat, llon, lgamma, lk;
        GeographicLib::UTMUPS::Reverse( zone, northp, x, y, llat, llon, lgamma,
                                        lk, mgrslimits );
        lat = llat;
        lon = llon;
        gamma = lgamma;
        k = lk;
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
void UTMUPS::Forward(double lat, double lon,
                    [System::Runtime::InteropServices::Out] int% zone,
                    [System::Runtime::InteropServices::Out] bool% northp,
                    [System::Runtime::InteropServices::Out] double% x,
                    [System::Runtime::InteropServices::Out] double% y,
                    int setzone, bool mgrslimits )
{
    try
    {
        double gamma, k, lx, ly;
        bool lnorthp;
        int lzone;
        GeographicLib::UTMUPS::Forward(lat, lon, lzone, lnorthp, lx, ly,
                                       gamma, k, setzone, mgrslimits);
        x = lx;
        y = ly;
        zone = lzone;
        northp = lnorthp;
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
void UTMUPS::Reverse(int zone, bool northp, double x, double y,
                    [System::Runtime::InteropServices::Out] double% lat,
                    [System::Runtime::InteropServices::Out] double% lon,
                    bool mgrslimits)
{
    try
    {
        double gamma, k, llat, llon;
        GeographicLib::UTMUPS::Reverse(zone, northp, x, y, llat, llon, gamma,
                                        k, mgrslimits);
        lat = llat;
        lon = llon;
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
void UTMUPS::Transfer(int zonein, bool northpin, double xin, double yin,
                        int zoneout, bool northpout,
                        [System::Runtime::InteropServices::Out] double% xout,
                        [System::Runtime::InteropServices::Out] double% yout,
                        [System::Runtime::InteropServices::Out] int% zone)
{
    try
    {
        int lzone;
        double lxout, lyout;
        GeographicLib::UTMUPS::Transfer(zonein, northpin, xin, yin,
                                        zoneout, northpout, lxout, lyout,
                                        lzone);
        xout = lxout;
        yout = lyout;
        zone = lzone;
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
void UTMUPS::DecodeZone(System::String^ zonestr,
    [System::Runtime::InteropServices::Out] int% zone,
    [System::Runtime::InteropServices::Out] bool% northp)
{
    try
    {
        std::string zoneIn = StringConvert::ManagedToUnmanaged( zonestr );
        int lzone;
        bool lnorthp;
        GeographicLib::UTMUPS::DecodeZone( zoneIn, lzone, lnorthp );
        zone = lzone;
        northp = lnorthp;
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
System::String^ UTMUPS::EncodeZone(int zone, bool northp, bool abbrev)
{
    try
    {
        return StringConvert::UnmanagedToManaged( GeographicLib::UTMUPS::EncodeZone( zone, northp, abbrev ) );
    }
    catch ( const std::exception& err )
    {
        throw gcnew GeographicErr( err.what() );
    }
}

//*****************************************************************************
void UTMUPS::DecodeEPSG(int epsg,
    [System::Runtime::InteropServices::Out] int% zone,
    [System::Runtime::InteropServices::Out] bool% northp)
{
    int lzone;
    bool lnorthp;
    GeographicLib::UTMUPS::DecodeEPSG( epsg, lzone, lnorthp );
    zone = lzone;
    northp = lnorthp;
}

//*****************************************************************************
int UTMUPS::EncodeEPSG(int zone, bool northp)
{
    return GeographicLib::UTMUPS::EncodeEPSG( zone, northp );
}

//****************************************************************************
double UTMUPS::UTMShift() { return GeographicLib::UTMUPS::UTMShift(); }

//****************************************************************************
double UTMUPS::EquatorialRadius() { return GeographicLib::UTMUPS::EquatorialRadius(); }

//****************************************************************************
double UTMUPS::Flattening() { return GeographicLib::UTMUPS::Flattening(); }