Skip to content

Commit b68f3f6

Browse files
Merge pull request #95 from baagaard-usgs/fix-coordinate-system-type-detection
Fix coordinate system type detection in CSGeo for computing surface normal
2 parents e6839ba + 24913e6 commit b68f3f6

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Main branch
2+
3+
* **Fixed**
4+
* Detect Proj string coordinate system type when computing surface normal. Default to (0, 0, 1) if coordinate system type is not recognized.
5+
* Add missing include directive for cstddef to CoordSys.hh.
6+
17
## Version 3.1.0 (2023/12/13)
28

39
* Add `AnalyticDB` for a spatial database composed of analytic functions.

libsrc/spatialdata/geocoords/CSGeo.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ spatialdata::geocoords::CSGeo::computeSurfaceNormal(double* dir,
121121
case PJ_TYPE_GEOGRAPHIC_3D_CRS:
122122
case PJ_TYPE_GEODETIC_CRS:
123123
case PJ_TYPE_PROJECTED_CRS:
124+
case PJ_TYPE_OTHER_COORDINATE_OPERATION:
124125
for (size_t i = 0; i < numLocs; ++i) {
125126
dir[i*numDims+0] = +0.0;
126127
dir[i*numDims+1] = +0.0;
@@ -146,9 +147,14 @@ spatialdata::geocoords::CSGeo::computeSurfaceNormal(double* dir,
146147
break;
147148
} // PJ_TYPE_GEOCENTRIC_CRS
148149
default: {
149-
std::ostringstream msg;
150-
msg << "Unknown coordinate system type (" << projType << ") for coordinate system '" << _string << "'.";
151-
throw std::logic_error(msg.str());
150+
std::cout << "Internal error: Coordinate system type (" << projType
151+
<< ") not recognized for coordinate system '" << _string << "' "
152+
<< "when computing normal of ground surface. Using default value of (0, 0, +1).";
153+
for (size_t i = 0; i < numLocs; ++i) {
154+
dir[i*numDims+0] = +0.0;
155+
dir[i*numDims+1] = +0.0;
156+
dir[i*numDims+2] = +1.0;
157+
} // for
152158
} // default
153159

154160
} // switch

tests/libtests/geocoords/TestCSGeo.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,28 @@ spatialdata::geocoords::TestCSGeo::testComputeSurfaceNormal(void) {
152152
delete[] dirs;dirs = 0;
153153
} // UTM zone 10
154154

155+
{ // Transverse mercator projection
156+
cs.setString("+proj=tmerc +datum=WGS84 +lon_0=-100.0 +lat_0=+40.0 +k=0.9996 +units=km");
157+
const size_t numLocs = 4;
158+
const size_t numDims = 3;
159+
const size_t size = numLocs * numDims;
160+
const double coords[size] = {
161+
57.0, 41.0, -1.0,
162+
40.0, 40.0, 2.0,
163+
30.0, 42.0, 3.0,
164+
55.0, 41.0, 4.0,
165+
};
166+
double* dirs = new double[size];
167+
cs.setSpaceDim(numDims);
168+
cs.computeSurfaceNormal(dirs, coords, numLocs, numDims);
169+
for (size_t iLoc = 0, i = 0; iLoc < numLocs; ++iLoc) {
170+
CHECK(0.0 == dirs[i++]);
171+
CHECK(0.0 == dirs[i++]);
172+
CHECK(1.0 == dirs[i++]);
173+
} // for
174+
delete[] dirs;dirs = 0;
175+
} // Transverse mercator projection
176+
155177
{ // Geocentric ECEF
156178
cs.setString("EPSG:4978");
157179

0 commit comments

Comments
 (0)