aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-12-06 18:03:14 +0100
committerEven Rouault <even.rouault@spatialys.com>2019-12-06 21:35:15 +0100
commit22792cd55ba41ffadb248c246cc871612a5139c1 (patch)
tree1ff8fa7fd812fea2ae53792b5488a90f6418095c /src
parent916a92062ffa2f2b59007047fae2176bbb463ca3 (diff)
downloadPROJ-22792cd55ba41ffadb248c246cc871612a5139c1.tar.gz
PROJ-22792cd55ba41ffadb248c246cc871612a5139c1.zip
Add a Grid base class for HorizontalShiftGrid and VerticalShiftGrid
Diffstat (limited to 'src')
-rw-r--r--src/4D_api.cpp81
-rw-r--r--src/grids.cpp18
-rw-r--r--src/grids.hpp37
3 files changed, 65 insertions, 71 deletions
diff --git a/src/4D_api.cpp b/src/4D_api.cpp
index 3300a6bb..efb4a86a 100644
--- a/src/4D_api.cpp
+++ b/src/4D_api.cpp
@@ -1556,39 +1556,44 @@ PJ_GRID_INFO proj_grid_info(const char *gridname) {
PJ_CONTEXT *ctx = pj_get_default_ctx();
memset(&grinfo, 0, sizeof(PJ_GRID_INFO));
+ const auto fillGridInfo = [&grinfo, ctx, gridname]
+ (const NS_PROJ::Grid& grid, const std::string& format)
{
- const auto gridSet = NS_PROJ::VerticalShiftGridSet::open(ctx, gridname);
- if( gridSet )
- {
- const auto& grids = gridSet->grids();
- if( !grids.empty() )
- {
- const auto& grid = grids.front();
- const auto& extent = grid->extentAndRes();
+ const auto& extent = grid.extentAndRes();
- /* name of grid */
- strncpy (grinfo.gridname, gridname, sizeof(grinfo.gridname) - 1);
+ /* name of grid */
+ strncpy (grinfo.gridname, gridname, sizeof(grinfo.gridname) - 1);
- /* full path of grid */
- pj_find_file(ctx, gridname, grinfo.filename, sizeof(grinfo.filename) - 1);
+ /* full path of grid */
+ pj_find_file(ctx, gridname, grinfo.filename, sizeof(grinfo.filename) - 1);
- /* grid format */
- strncpy (grinfo.format, gridSet->format().c_str(), sizeof(grinfo.format) - 1);
+ /* grid format */
+ strncpy (grinfo.format, format.c_str(), sizeof(grinfo.format) - 1);
- /* grid size */
- grinfo.n_lon = grid->width();
- grinfo.n_lat = grid->height();
+ /* grid size */
+ grinfo.n_lon = grid.width();
+ grinfo.n_lat = grid.height();
- /* cell size */
- grinfo.cs_lon = extent.resLon;
- grinfo.cs_lat = extent.resLat;
+ /* cell size */
+ grinfo.cs_lon = extent.resLon;
+ grinfo.cs_lat = extent.resLat;
- /* bounds of grid */
- grinfo.lowerleft.lam = extent.westLon;
- grinfo.lowerleft.phi = extent.southLat;
- grinfo.upperright.lam = extent.eastLon;
- grinfo.upperright.phi = extent.northLat;
+ /* bounds of grid */
+ grinfo.lowerleft.lam = extent.westLon;
+ grinfo.lowerleft.phi = extent.southLat;
+ grinfo.upperright.lam = extent.eastLon;
+ grinfo.upperright.phi = extent.northLat;
+ };
+ {
+ const auto gridSet = NS_PROJ::VerticalShiftGridSet::open(ctx, gridname);
+ if( gridSet )
+ {
+ const auto& grids = gridSet->grids();
+ if( !grids.empty() )
+ {
+ const auto& grid = grids.front();
+ fillGridInfo(*grid, gridSet->format());
return grinfo;
}
}
@@ -1602,31 +1607,7 @@ PJ_GRID_INFO proj_grid_info(const char *gridname) {
if( !grids.empty() )
{
const auto& grid = grids.front();
- const auto& extent = grid->extentAndRes();
-
- /* name of grid */
- strncpy (grinfo.gridname, gridname, sizeof(grinfo.gridname) - 1);
-
- /* full path of grid */
- pj_find_file(ctx, gridname, grinfo.filename, sizeof(grinfo.filename) - 1);
-
- /* grid format */
- strncpy (grinfo.format, gridSet->format().c_str(), sizeof(grinfo.format) - 1);
-
- /* grid size */
- grinfo.n_lon = grid->width();
- grinfo.n_lat = grid->height();
-
- /* cell size */
- grinfo.cs_lon = extent.resLon;
- grinfo.cs_lat = extent.resLat;
-
- /* bounds of grid */
- grinfo.lowerleft.lam = extent.westLon;
- grinfo.lowerleft.phi = extent.southLat;
- grinfo.upperright.lam = extent.eastLon;
- grinfo.upperright.phi = extent.northLat;
-
+ fillGridInfo(*grid, gridSet->format());
return grinfo;
}
}
diff --git a/src/grids.cpp b/src/grids.cpp
index 54dae555..7d19b1f7 100644
--- a/src/grids.cpp
+++ b/src/grids.cpp
@@ -70,13 +70,24 @@ bool ExtentAndRes::fullWorldLongitude() const {
// ---------------------------------------------------------------------------
+Grid::Grid(int widthIn, int heightIn, const ExtentAndRes &extentIn)
+ : m_width(widthIn), m_height(heightIn), m_extent(extentIn) {}
+
+// ---------------------------------------------------------------------------
+
+Grid::~Grid() = default;
+
+// ---------------------------------------------------------------------------
+
VerticalShiftGrid::VerticalShiftGrid(int widthIn, int heightIn,
const ExtentAndRes &extentIn)
- : m_width(widthIn), m_height(heightIn), m_extent(extentIn) {}
+ : Grid(widthIn, heightIn, extentIn) {}
// ---------------------------------------------------------------------------
-VerticalShiftGrid::~VerticalShiftGrid() = default;
+bool VerticalShiftGrid::isNodata(float /*val*/, double /* multiplier */) const {
+ return false;
+}
// ---------------------------------------------------------------------------
@@ -98,6 +109,7 @@ class NullVerticalShiftGrid : public VerticalShiftGrid {
public:
NullVerticalShiftGrid() : VerticalShiftGrid(3, 3, globalExtent()) {}
+ bool isNullGrid() const override { return true; }
bool valueAt(int, int, float &out) const override;
bool isNodata(float, double) const override { return false; }
};
@@ -306,7 +318,7 @@ const VerticalShiftGrid *VerticalShiftGridSet::gridAt(double lon,
HorizontalShiftGrid::HorizontalShiftGrid(int widthIn, int heightIn,
const ExtentAndRes &extentIn)
- : m_width(widthIn), m_height(heightIn), m_extent(extentIn) {}
+ : Grid(widthIn, heightIn, extentIn) {}
// ---------------------------------------------------------------------------
diff --git a/src/grids.hpp b/src/grids.hpp
index 975f7716..65bf502b 100644
--- a/src/grids.hpp
+++ b/src/grids.hpp
@@ -49,26 +49,36 @@ struct ExtentAndRes {
// ---------------------------------------------------------------------------
-class VerticalShiftGrid {
+class Grid {
protected:
int m_width;
int m_height;
ExtentAndRes m_extent;
- std::vector<std::unique_ptr<VerticalShiftGrid>> m_children{};
+
+ Grid(int widthIn, int heightIn, const ExtentAndRes &extentIn);
public:
- VerticalShiftGrid(int widthIn, int heightIn, const ExtentAndRes &extentIn);
- virtual ~VerticalShiftGrid();
+ virtual ~Grid();
int width() const { return m_width; }
int height() const { return m_height; }
const ExtentAndRes &extentAndRes() const { return m_extent; }
+ virtual bool isNullGrid() const { return false; }
+};
+
+// ---------------------------------------------------------------------------
+
+class VerticalShiftGrid : public Grid {
+ protected:
+ std::vector<std::unique_ptr<VerticalShiftGrid>> m_children{};
+
+ public:
+ VerticalShiftGrid(int widthIn, int heightIn, const ExtentAndRes &extentIn);
+
const VerticalShiftGrid *gridAt(double lon, double lat) const;
- virtual bool isNodata(float /*val*/, double /* multiplier */) const {
- return false;
- }
+ virtual bool isNodata(float /*val*/, double /* multiplier */) const;
// x = 0 is western-most column, y = 0 is southern-most line
virtual bool valueAt(int x, int y, float &out) const = 0;
@@ -99,26 +109,17 @@ class VerticalShiftGridSet {
// ---------------------------------------------------------------------------
-class HorizontalShiftGrid {
+class HorizontalShiftGrid : public Grid {
protected:
- int m_width;
- int m_height;
- ExtentAndRes m_extent;
std::vector<std::unique_ptr<HorizontalShiftGrid>> m_children{};
public:
HorizontalShiftGrid(int widthIn, int heightIn,
const ExtentAndRes &extentIn);
- virtual ~HorizontalShiftGrid();
-
- int width() const { return m_width; }
- int height() const { return m_height; }
- const ExtentAndRes &extentAndRes() const { return m_extent; }
+ ~HorizontalShiftGrid() override;
const HorizontalShiftGrid *gridAt(double lon, double lat) const;
- virtual bool isNullGrid() const { return false; }
-
// x = 0 is western-most column, y = 0 is southern-most line
virtual bool valueAt(int x, int y, float &lonShift,
float &latShift) const = 0;