Skip to content

Commit

Permalink
Support War Office and National Yard Grid
Browse files Browse the repository at this point in the history
Add initial implementation of War Office (GB and Ireland) and National Yard projections. Needs more testing.
  • Loading branch information
Ritchie333 committed Sep 18, 2024
1 parent a6813b1 commit aecfd4e
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 66 deletions.
53 changes: 53 additions & 0 deletions src/CopyPixels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CopyPixels *CopyPixels::Create(const char *type)
MASK_ENTRY("G", CopyPixelsWithOsMask )
MASK_ENTRY("O", CopyPixelsWithRawMask )
MASK_ENTRY("OS", CopyPixelsWithRawMask )
MASK_ENTRY("OSY", CopyPixelsWithOSYMask )
MASK_ENTRY("C", CopyPixelsWithCassini )
MASK_ENTRY("CAS", CopyPixelsWithCassini )
MASK_ENTRY("B", CopyPixelsWithBonne )
Expand All @@ -35,6 +36,8 @@ CopyPixels *CopyPixels::Create(const char *type)
MASK_ENTRY("PM", CopyPixelsWithParisMercator )
MASK_ENTRY("M", CopyPixelsWithMercator )
MASK_ENTRY("UTM", CopyPixelsWithUTM )
MASK_ENTRY("WO", CopyPixelsWithWO )
MASK_ENTRY("WOI", CopyPixelsWithWOI )
END_MASK_MAP()

if( !mask ) {
Expand Down Expand Up @@ -82,6 +85,24 @@ void CopyPixelsWithOsMask::UpdateBoundingBox(const char *mapref)
}
}

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;
if (!boxset || gsouth > dNorthing)
gsouth = dNorthing;
if (!boxset || gnorth < dNorthing)
gnorth = dNorthing;
if (!boxset || geast < dEasting)
geast = dEasting;
if (!boxset || gwest > dEasting)
gwest = dEasting;
boxset = 1;
}
}

long CopyPixelsWithUTM::UTMEasting( const int zone, const int easting )
{
Expand Down Expand Up @@ -116,6 +137,38 @@ void CopyPixelsWithUTM::UpdateBoundingBox(const char *mapref)
}
}

bool
CopyPixelsWithWO::CheckIfInBox(double lat, double lon)
{
double pnorth, peast;
gConverter.ConvertWgs84ToWO(lat, lon, 0.0, peast, pnorth);
if (pnorth < gsouth)
return false;
if (pnorth > gnorth)
return false;
if (peast < gwest)
return false;
if (peast > geast)
return false;
return true;
}

bool
CopyPixelsWithWOI::CheckIfInBox(double lat, double lon)
{
double pnorth, peast;
gConverter.ConvertWgs84ToWOI(lat, lon, 0.0, peast, pnorth);
if (pnorth < gsouth)
return false;
if (pnorth > gnorth)
return false;
if (peast < gwest)
return false;
if (peast > geast)
return false;
return true;
}

void CopyPixelsWithRawMask::UpdateBoundingBox(const char *mapref)
{
int dEasting = 0, dNorthing = 0;
Expand Down
21 changes: 21 additions & 0 deletions src/CopyPixels.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class CopyPixelsWithOsMask : public CopyPixels
virtual bool CheckIfInBox(double lat, double lon);
};

class CopyPixelsWithOSYMask : public CopyPixelsWithOsMask
{
public:
CopyPixelsWithOSYMask() {}
virtual void UpdateBoundingBox(const char *mapref);
};

class CopyPixelsWithRawMask : public CopyPixelsWithOsMask
{
public:
Expand Down Expand Up @@ -90,6 +97,20 @@ class CopyPixelsWithUTM : public CopyPixels

};

class CopyPixelsWithWO : public CopyPixelsWithCassini
{
public:
CopyPixelsWithWO() {}
virtual bool CheckIfInBox(double lat, double lon);
};

class CopyPixelsWithWOI : public CopyPixelsWithCassini
{
public:
CopyPixelsWithWOI() {}
virtual bool CheckIfInBox(double lat, double lon);
};

class CopyPixelsWithMercator : public CopyPixels
{
public:
Expand Down
2 changes: 2 additions & 0 deletions src/GenTiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ int main(int argc, char **argv)
mergeTiles = (po.GetIntArg("merge") == 1);
if (po.HasArg("output"))
outFolder = po.GetArg("output");
if( po.HasArg("out"))
outFolder = po.GetArg("out");
if (po.HasArg("bounds"))
boundsFilename = po.GetArg("bounds");

Expand Down
70 changes: 69 additions & 1 deletion src/WarpOs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ class PolyProjectArgs
BonneS,
BonneI,
BonneF,
OSI
OSI,
WO,
WOI,
OSGBY
} ProjType;

vector<double> imgToRefPoly;
Expand Down Expand Up @@ -91,6 +94,9 @@ const Point ProjRefToOutImg(const Point& ref, PolyProjectArgs::ProjType projType
alt = 0.0;
}
break;
case PolyProjectArgs::OSGBY:
gFallbackConverter.ConvertGbos1936ToWgs84(ref.x * METRES_IN_YARD, ref.y * METRES_IN_YARD, 0.0, lat, lon, alt);
break;

case PolyProjectArgs::Mercator:
lat = ref.y;
Expand All @@ -112,6 +118,12 @@ const Point ProjRefToOutImg(const Point& ref, PolyProjectArgs::ProjType projType
case PolyProjectArgs::BonneF:
gFallbackConverter.ConvertBnFToWgs84(ref.x, ref.y, 0.0, lat, lon, alt );
break;
case PolyProjectArgs::WO:
gFallbackConverter.ConvertWOToWgs84(ref.x, ref.y, 0.0, lat, lon, alt);
break;
case PolyProjectArgs::WOI:
gFallbackConverter.ConvertWOIToWgs84(ref.x, ref.y, 0.0, lat, lon, alt);
break;
}
if (projType != PolyProjectArgs::OSGB && !args->mercatorOut)
{
Expand Down Expand Up @@ -307,6 +319,22 @@ int main(int argc, char *argv[])
{
projType = PolyProjectArgs::OSI;
}
if( inproj == "wo")
{
projType = PolyProjectArgs::WO;
}
if( inproj == "woi")
{
projType = PolyProjectArgs::WOI;
}
if( inproj == "osgb")
{
projType = PolyProjectArgs::OSGB;
}
if( inproj == "osgby")
{
projType = PolyProjectArgs::OSGBY;
}
}

if (inputImageFilename.length() == 0)
Expand Down Expand Up @@ -424,12 +452,31 @@ int main(int argc, char *argv[])
// Add point to transform constraints
gConverter.ConvertGbos1936ToWgs84(dEasting, dNorthing, 0.0, lat, lon, alt);
}
if (strcmp(line[0].GetVals(), "osy") == 0)
{
string mapref = line[1].GetVals();
sscanf(mapref.c_str(), "%d:%d", &dEasting, &dNorthing);
// Add point to transform constraints
gConverter.ConvertGbos1936ToWgs84(dEasting * METRES_IN_YARD, dNorthing * METRES_IN_YARD, 0.0, lat, lon, alt);
}
if (strcmp(line[0].GetVals(), "osi") == 0)
{
string mapref = line[1].GetVals();
sscanf(mapref.c_str(), "%d:%d", &dEasting, &dNorthing);
gConverter.ConvertOsiToWgs84(dEasting, dNorthing, 0.0, lat, lon, alt);
}
if (strcmp(line[0].GetVals(), "wo") == 0)
{
string mapref = line[1].GetVals();
sscanf(mapref.c_str(), "%d:%d", &dEasting, &dNorthing);
gConverter.ConvertWOToWgs84(dEasting, dNorthing, 0.0, lat, lon, alt);
}
if (strcmp(line[0].GetVals(), "woi") == 0)
{
string mapref = line[1].GetVals();
sscanf(mapref.c_str(), "%d:%d", &dEasting, &dNorthing);
gConverter.ConvertWOIToWgs84(dEasting, dNorthing, 0.0, lat, lon, alt);
}
if (lat != -1.0 && lon != -1.0)
{
if (projType != PolyProjectArgs::Mercator)
Expand Down Expand Up @@ -484,6 +531,27 @@ int main(int argc, char *argv[])

gConverter.ConvertOsiToWgs84(dEasting, dNorthing, 0.0, lat, lon, alt);
}
if (strcmp(line[0].GetVals(), "wo") == 0)
{
dEasting = line[1].GetVald();
dNorthing = line[2].GetVald();

gConverter.ConvertWOToWgs84(dEasting, dNorthing, 0.0, lat, lon, alt);
}
if (strcmp(line[0].GetVals(), "woi") == 0)
{
dEasting = line[1].GetVald();
dNorthing = line[2].GetVald();

gConverter.ConvertWOIToWgs84(dEasting, dNorthing, 0.0, lat, lon, alt);
}
if (strcmp(line[0].GetVals(), "wp") == 0)
{
dEasting = line[1].GetVald();
dNorthing = line[2].GetVald();

gConverter.ConvertWOToWgs84(dEasting, dNorthing, 0.0, lat, lon, alt);
}
if (strcmp(line[0].GetVals(), "cas") == 0)
{
dEasting = line[1].GetVald();
Expand Down
Loading

0 comments on commit aecfd4e

Please sign in to comment.