Skip to content

Commit

Permalink
Merge pull request #10297 from jjimenezshaw/isg-dms
Browse files Browse the repository at this point in the history
Parse dms in ISG format
  • Loading branch information
rouault authored Jun 25, 2024
2 parents 379a131 + 4946532 commit abc5f9e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 10 deletions.
28 changes: 28 additions & 0 deletions autotest/gdrivers/data/isg/header_dms.isg
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
begin_of_head ================================================
model name : GSIGEO2024bata
model year : 2024
model type : gravimetric
data type : geoid
data units : meters
data format : grid
data ordering : N-to-S, W-to-E
ref ellipsoid : GRS80
ref frame : ---
height datum : ---
tide system : ---
coord type : geodetic
coord units : dms
map projection : ---
EPSG code : 6668
lat min = 15°00'00"
lat max = 50°00'00"
lon min = 120°00'00"
lon max = 160°00'00"
delta lat = 0°01'00"
delta lon = 0°01'30"
nrows = 2101
ncols = 1601
nodata = -9999.0000
creation date = 27/03/2024
ISG format = 2.0
end_of_head ==================================================
14 changes: 14 additions & 0 deletions autotest/gdrivers/isg.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,17 @@ def test_isg_header_larger_than_1024bytes():
ds = gdal.Open("data/isg/header_larger_than_1024bytes.isg")
expected_gt = [12.99375, 0.0125, 0.0, 47.00416666666666, 0.0, -0.008333333333333333]
assert ds.GetGeoTransform() == pytest.approx(expected_gt, rel=1e-8)


###############################################################################
# Test if we can read dms angles


def test_isg_dms():

gdal.ErrorReset()
# Header of https://www.gsi.go.jp/butsuri/data/GSIGEO2024beta.zip
ds = gdal.Open("data/isg/header_dms.isg")
assert gdal.GetLastErrorMsg() == ""
expected_gt = [119.9875, 0.025, 0.0, 50.0083333333, 0.0, -0.01666666666]
assert ds.GetGeoTransform() == pytest.approx(expected_gt, rel=1e-8)
39 changes: 29 additions & 10 deletions frmts/aaigrid/aaigriddataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,18 +863,37 @@ int ISGDataset::ParseHeader(const char *pszHeader, const char *)
"ISG: coord type = %s not supported", osCoordType.c_str());
return FALSE;
}
if (!osCoordUnits.empty() && osCoordUnits != "deg")

auto parseDMS = [](auto str)
{
CPLError(CE_Failure, CPLE_NotSupported,
"ISG: coord units = %s not supported", osCoordUnits.c_str());
return FALSE;
std::string degreeSymbol{"\xc2\xb0"};
str.replaceAll(degreeSymbol, "D");
return CPLDMSToDec(str);
};

bool useDMS = false;
if (!osCoordUnits.empty())
{
if (osCoordUnits == "dms")
{
// CPLDMSToDec does not support the non ascii char for degree used in ISG.
// just replace it with "D" to make it compatible.
useDMS = true;
}
else if (osCoordUnits != "deg")
{
CPLError(CE_Failure, CPLE_NotSupported,
"ISG: coord units = %s not supported",
osCoordUnits.c_str());
return FALSE;
}
}
double dfLatMin = CPLAtof(osLatMin);
double dfLatMax = CPLAtof(osLatMax);
double dfLonMin = CPLAtof(osLonMin);
double dfLonMax = CPLAtof(osLonMax);
double dfDeltaLon = CPLAtof(osDeltaLon);
double dfDeltaLat = CPLAtof(osDeltaLat);
double dfLatMin = useDMS ? parseDMS(osLatMin) : CPLAtof(osLatMin);
double dfLatMax = useDMS ? parseDMS(osLatMax) : CPLAtof(osLatMax);
double dfLonMin = useDMS ? parseDMS(osLonMin) : CPLAtof(osLonMin);
double dfLonMax = useDMS ? parseDMS(osLonMax) : CPLAtof(osLonMax);
double dfDeltaLon = useDMS ? parseDMS(osDeltaLon) : CPLAtof(osDeltaLon);
double dfDeltaLat = useDMS ? parseDMS(osDeltaLat) : CPLAtof(osDeltaLat);
if (dfVersion >= 2.0)
{
dfLatMin -= dfDeltaLat / 2.0;
Expand Down

0 comments on commit abc5f9e

Please sign in to comment.