34#include <drain/util/Units.h>
36#include "drain/util/BoundingBox.h"
37#include "drain/util/Proj6.h"
66 GeoFrame(
unsigned int width,
unsigned int height);
91 return ((frame.width > 0) && (frame.height > 0));
101 return (
bBoxD.getArea() > 0.0);
117 void setGeometry(
unsigned int width,
unsigned int height);
135 void setBoundingBox(
double lonLL,
double latLL,
double lonUR,
double latUR);
140 setBoundingBox(bbox.lowerLeft.x, bbox.lowerLeft.y, bbox.upperRight.x, bbox.upperRight.y);
146 void setBoundingBoxD(
double lonLL,
double latLL,
double lonUR,
double latUR);
152 setBoundingBoxD(bboxD.lowerLeft.x, bboxD.lowerLeft.y, bboxD.upperRight.x, bboxD.upperRight.y);
159 setBoundingBoxD(RAD2DEG*lonLL, RAD2DEG*latLL, RAD2DEG*lonUR, RAD2DEG*latUR);
165 setBoundingBoxR(bboxR.lowerLeft.x, bboxR.lowerLeft.y, bboxR.upperRight.x, bboxR.upperRight.y);
235 cropWithM(bboxM.lowerLeft.x, bboxM.lowerLeft.y, bboxM.upperRight.x, bboxM.upperRight.y);
239 void cropWithM(
double xLL,
double yLL,
double xUR,
double yUR);
244 void deg2pix(
double lon,
double lat,
int & i,
int & j)
const {
248 m2pix(lon, lat, i,j);
254 deg2pix(loc.x, loc.y, pix.x, pix.y);
261 void deg2m(
double lon,
double lat,
double &x,
double &y)
const {
270 deg2m(pDeg.x, pDeg.y, pMet.x, pMet.y);
275 void pix2deg(
int i,
int j,
double & lon,
double & lat)
const {
284 void pix2rad(
int i,
int j,
double & lon,
double & lat)
const {
296 pix2deg(pix.x,pix.y, loc.x,loc.y);
301 void pix2LLdeg(
int i,
int j,
double & lon,
double & lat)
const {
313 void m2deg(
double x,
double y,
double & lon,
double & lat)
const {
346 void m2pix(
double x,
double y,
int & i,
int & j)
const {
350 i = ::lround((x -
bBoxNative.lowerLeft.x) / xScale);
351 j = frame.height-1 - ::lround((y -
bBoxNative.lowerLeft.y) / yScale);
358 m2pix(pMetric.x, pMetric.y, pImage.x, pImage.y);
374 void pix2m(
int i,
int j,
double & x,
double & y)
const {
375 x = (
static_cast<double>(i)+0.5)*xScale +
bBoxNative.lowerLeft.x;
376 y = (
static_cast<double>(frame.height-1 - j)+0.5)*yScale +
bBoxNative.lowerLeft.y;
385 pMetric.x = (
static_cast<double>(pImage.x)+0.5)*xScale +
bBoxNative.lowerLeft.x;
386 pMetric.y = (
static_cast<double>(frame.height-1 - pImage.y)+0.5)*yScale +
bBoxNative.lowerLeft.y;
399 void pix2LLm(
int i,
int j,
double & x,
double & y)
const {
400 x = (
static_cast<double>(i))*xScale +
bBoxNative.lowerLeft.x;
401 y = (
static_cast<double>(frame.height-1 - j))*yScale +
bBoxNative.lowerLeft.y;
406 void setProjection(
const Projector & proj){
407 if (proj.getEPSG() > 0){
440 int getEPSG()
const {
481 bool isLongLat()
const {
488 std::ostream & toStream(std::ostream & ostr)
const;
530std::ostream & operator<<(std::ostream & ostr,
const GeoFrame & frame){
531 frame.GeoFrame::toStream(ostr);
Something that has width and height.
Definition Frame.h:55
bool isLongLat() const
Check if destination projection is longitude-latitude degrees.
Definition Proj6.h:255
const std::string & getProjStrSrc() const
Returns the projection std::string applied by the last setProjection call.
Definition Proj6.h:161
void projectFwd(double &x, double &y) const
Forward projection (in-place)
Definition Proj6.h:186
void setProjectionDst(const T &...args)
Sets destination projection.
Definition Proj6.h:127
Definition Projector.h:54
Tuple of N elements of type T.
Definition UniTuple.h:65
Array with georeferencing support.
Definition GeoFrame.h:58
drain::Rectangle< double > bBoxR
Geographical scope in Radians.
Definition GeoFrame.h:507
const std::string & getProjStr() const
Returns the projection of the composite image as a proj4 std::string.
Definition GeoFrame.h:446
void setBoundingBox(const drain::Rectangle< double > &bbox)
Sets bounding box in degrees in the target coordinate system.
Definition GeoFrame.h:139
virtual void pix2m(const drain::Point2D< int > &pImage, drain::Point2D< double > &pMetric) const
Scales image coordinates (i,j) to map coordinates (x,y) in the center of the pixel.
Definition GeoFrame.h:384
virtual void m2pix(double x, double y, int &i, int &j) const
Scales geographic map coordinates to image coordinates.
Definition GeoFrame.h:346
GeoFrame()
Default constructor.
Definition GeoFrame.cpp:49
const drain::Rectangle< double > & getDataOverlapBBoxNat() const
Return the common overlapping geographical area (intersection) implied by input data.
Definition GeoFrame.h:466
const drain::Rectangle< double > & getBoundingBoxRad() const
Returns the geographical scope in Radians.
Definition GeoFrame.h:211
void setProjectionEPSG(int epsg)
Sets the projection of the image as a EPSG code.
Definition GeoFrame.h:425
void updateScaling()
Geometric scaling.
Definition GeoFrame.cpp:311
virtual void pix2rad(int i, int j, double &lon, double &lat) const
Calculates the geographic coordinates (lon,lat) [rad] of the center of a pixel at (i,...
Definition GeoFrame.h:284
virtual void m2deg(const drain::Point2D< double > &pMetric, drain::Point2D< double > &pDeg) const
Convert metric coordinates to degrees.
Definition GeoFrame.h:323
void updateProjection()
Updates bboxes, if needed.
Definition GeoFrame.cpp:269
const Proj6 & getProj() const
Returns the projection of the composite image as a proj4 std::string.
Definition GeoFrame.h:435
void pix2deg(const drain::Point2D< int > &pix, drain::Point2D< double > &loc) const
Calculates the geographic coordinates of the center of a pixel at (i,j).
Definition GeoFrame.h:295
void updateDataExtentNat(const drain::Rectangle< double > &inputBBoxNat)
Definition GeoFrame.cpp:398
void setBoundingBoxR(double lonLL, double latLL, double lonUR, double latUR)
Sets bounding box in radians in the target coordinate system.
Definition GeoFrame.h:158
const drain::Rectangle< double > & getDataBBoxNat() const
Return the actual geographical boundingBox suggested by implied by input data.
Definition GeoFrame.h:461
void updateBoundingBoxR()
Proj 6 NEW: Given BBox in geo coords [deg], adjust geo coords [rad].
Definition GeoFrame.cpp:219
const drain::Rectangle< double > & getBoundingBoxNat() const
Returns the geographical scope in Meters.
Definition GeoFrame.h:207
bool bboxIsSet() const
Returns true, if the bounding box (geographical extent) has been set.
Definition GeoFrame.h:100
int getFrameHeight() const
Return the nominal height, not the height of the memory array which does not have to be allocated.
Definition GeoFrame.h:125
void updateDataExtentDeg(const drain::Rectangle< double > &inputBBoxDeg)
Extend to include this input.
Definition GeoFrame.cpp:384
virtual void pix2LLdeg(int i, int j, double &lon, double &lat) const
Calculates the geographic coordinates of the lower left corner of a pixel at (i,j).
Definition GeoFrame.h:301
drain::Rectangle< double > dataBBoxNat
For deriving extent (~union) of input data.
Definition GeoFrame.h:517
bool geometryIsSet() const
Return true, if array area is greater than zero.
Definition GeoFrame.h:90
bool projectionIsSet() const
Returns true, if the geographical extent has been set.
Definition GeoFrame.h:84
void setBoundingBox(double lonLL, double latLL, double lonUR, double latUR)
Sets bounding box in degrees OR in metres in the target coordinate system.
Definition GeoFrame.cpp:84
virtual void pix2LLm(int i, int j, double &x, double &y) const
Scales image coordinates (i,j) to map coordinates (x,y) of the lower left corner of the pixel.
Definition GeoFrame.h:399
drain::Rectangle< double > bBoxNative
Geographical scope in meters, or degrees in case of long/lat.
Definition GeoFrame.h:513
virtual void pix2m(int i, int j, double &x, double &y) const
Scales image coordinates (i,j) to map coordinates (x,y) in the center of the pixel.
Definition GeoFrame.h:374
virtual void deg2m(double lon, double lat, double &x, double &y) const
Convert degrees to native (often metric) coordinates.
Definition GeoFrame.h:261
void setBoundingBoxNat(const drain::UniTuple< double, 4 > &bboxM)
Sets bounding box in meters in the target coordinate system.
Definition GeoFrame.h:178
void setBoundingBoxR(const drain::Rectangle< double > &bboxR)
Sets bounding box in radians in the target coordinate system.
Definition GeoFrame.h:164
virtual void m2deg(double x, double y, double &lon, double &lat) const
Convert metric coordinates to degrees.
Definition GeoFrame.h:313
bool isDefined() const
Returns true, if the projection, array area and geographical extent bounding box has been set.
Definition GeoFrame.h:110
virtual void deg2pix(double lon, double lat, int &i, int &j) const
Projects geographic coordinates to image coordinates.
Definition GeoFrame.h:244
const std::string & getInputProjStr() const
Returns the source projection (should be radian array, lon & lat).
Definition GeoFrame.h:453
void setBoundingBoxNat(double xLL, double yLL, double xUR, double yUR)
Sets bounding box in meters in the target coordinate system.
Definition GeoFrame.cpp:143
drain::Rectangle< double > dataOverlapBBoxNat
For deriving common extent (~intersection) of input data.
Definition GeoFrame.h:521
virtual void pix2deg(int i, int j, double &lon, double &lat) const
Calculates the geographic coordinates of the center of a pixel at (i,j).
Definition GeoFrame.h:275
const drain::Rectangle< double > & getBoundingBoxDeg() const
Returns the geographical scope in Degrees.
Definition GeoFrame.h:203
void setProjection(const std::string &projDef)
Sets the projection of the image as a Proj string.
Definition GeoFrame.h:418
double getYScale() const
Return vertical resolution of a pixel in meters (if metric) or degrees (if unprojected,...
Definition GeoFrame.h:223
drain::Proj6 projGeo2Native
Radial to metric.
Definition GeoFrame.h:495
void deg2pix(const drain::Point2D< double > &loc, drain::Point2D< int > &pix) const
Project geographic coordinates (degrees) to image coordinates (pixels).
Definition GeoFrame.h:253
void setBoundingBoxD(const drain::Rectangle< double > &bboxD)
Sets bounding box in degrees in the target coordinate system.
Definition GeoFrame.h:151
void cropWithM(drain::Rectangle< double > &bboxM)
Crops the initial bounding box with a given bounding box.
Definition GeoFrame.h:234
void updateBoundingBoxNat()
Given BBox in geo coords [rad], adjust geo coords [deg].
Definition GeoFrame.cpp:227
double getXScale() const
Return horizontal resolution of a pixel in meters (if metric) or degrees (if unprojected,...
Definition GeoFrame.h:217
void deg2m(const drain::Point2D< double > &pDeg, drain::Point2D< double > &pMet) const
Convert degrees to native (often metric) coordinates.
Definition GeoFrame.h:269
void setBoundingBoxD(double lonLL, double latLL, double lonUR, double latUR)
Sets bounding box in degrees in the target coordinate system.
Definition GeoFrame.cpp:123
drain::Rectangle< double > bBoxD
Geographical scope in Degrees.
Definition GeoFrame.h:510
int getFrameWidth() const
Return the nominal width, not the width of the memory array which does not have to be allocated.
Definition GeoFrame.h:121
Definition DataSelector.cpp:1277
Rectange defined through lower left and upper right coordinates.
Definition Rectangle.h:65