Skip to content

Commit

Permalink
Added support for National Yard Grid
Browse files Browse the repository at this point in the history
Support National Yard Grid (tested now!)
  • Loading branch information
Ritchie333 committed Sep 19, 2024
1 parent 58774fe commit bb45506
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/CopyPixels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ void CopyPixelsWithOSYMask::UpdateBoundingBox(const char *mapref)
int dEasting = 0, dNorthing = 0;
if (2 == sscanf(mapref, "%d:%d", &dEasting, &dNorthing))
{
dEasting *= METRES_IN_YARD;
dNorthing *= METRES_IN_YARD;
int me = 0, mn = 0;
YardsToMetres( dEasting, dNorthing, me, mn );
dEasting = me;
dNorthing = mn;
if (!boxset || gsouth > dNorthing)
gsouth = dNorthing;
if (!boxset || gnorth < dNorthing)
Expand Down
8 changes: 6 additions & 2 deletions src/WarpOs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const Point ProjRefToOutImg(const Point& ref, PolyProjectArgs::ProjType projType
{
class PolyProjectArgs *args = (class PolyProjectArgs *)userPtr;
double lat = 0.0, lon = 0.0, alt = 0.0;
int me = 0, mn = 0;
switch (projType)
{
case PolyProjectArgs::OSGB:
Expand All @@ -95,7 +96,8 @@ const Point ProjRefToOutImg(const Point& ref, PolyProjectArgs::ProjType projType
}
break;
case PolyProjectArgs::OSGBY:
gFallbackConverter.ConvertGbos1936ToWgs84(ref.x * METRES_IN_YARD, ref.y * METRES_IN_YARD, 0.0, lat, lon, alt);
YardsToMetres( ref.x, ref.y, me, mn );
gFallbackConverter.ConvertGbos1936ToWgs84(me, mn, 0.0, lat, lon, alt);
break;

case PolyProjectArgs::Mercator:
Expand Down Expand Up @@ -456,8 +458,10 @@ int main(int argc, char *argv[])
{
string mapref = line[1].GetVals();
sscanf(mapref.c_str(), "%d:%d", &dEasting, &dNorthing);
int me = 0, mn = 0;
YardsToMetres( dEasting, dNorthing, me, mn );
// Add point to transform constraints
gConverter.ConvertGbos1936ToWgs84(dEasting * METRES_IN_YARD, dNorthing * METRES_IN_YARD, 0.0, lat, lon, alt);
gConverter.ConvertGbos1936ToWgs84(me, mn, 0.0, lat, lon, alt);
}
if (strcmp(line[0].GetVals(), "osi") == 0)
{
Expand Down
6 changes: 6 additions & 0 deletions src/gbos1936/Gbos1936.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,12 @@ Function TrueAzimuth(AtEast, AtNorth, ToEast, ToNorth, a, b, e0, n0, f0, PHI0)
End Function*/

void YardsToMetres( const int ine, const int inn, int& oute, int& outn )
{
oute = ( ( ine - 1000000 ) * METRES_IN_YARD ) + 400000;
outn = ( ( inn - 1000000 ) * METRES_IN_YARD ) - 100000;
}

void ConvertCasToGeo(double ea, double no, double he,
double &latOut, double &lonOut, double &heOut,
const GridData& CSGrid )
Expand Down
4 changes: 3 additions & 1 deletion src/gbos1936/Gbos1936.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define PARIS_CENTRE_LON 2.336506

const double METRES_IN_MILE = 1609.347955248;
const double METRES_IN_YARD = 0.9144022473;
const double METRES_IN_YARD = 0.9144;

struct Ellip
{
Expand Down Expand Up @@ -101,6 +101,8 @@ double E_N_to_Lat(double East, double North, double a, double b, double e0, doub
double E_N_to_Long(double East, double North, double a, double b, double e0, double n0, double f0, double PHI0, double LAM0);
double calc_M(long double latdiff, long double latsum, long double nn, long double eb, double F0);

void YardsToMetres( const int ine, const int inn, int& oute, int& outn );

void TM2Geo( double East, double North, const GridData& TMgrid, double& latOut, double& lngOut );
void Geo2TM( double lat, double lon, const GridData& TMgrid, double &eaOut, double &noOut );
void Geo2Geo( double lat, double lon, const struct Datum& datum_a, const struct Datum& datum_b, double& latOut, double &lngOut );
Expand Down

0 comments on commit bb45506

Please sign in to comment.