34#include "drain/StringTools.h"
35#include "drain/util/BoundingBox.h"
36#include "drain/util/Proj6.h"
37#include "drain/util/Units.h"
64 GeoFrame(
unsigned int width,
unsigned int height);
84 return ((frame.width > 0) && (frame.height > 0));
94 return (
bBoxD.getArea() > 0.0);
115 void setGeometry(
unsigned int width,
unsigned int height);
138 void setBoundingBox(
double lonLL,
double latLL,
double lonUR,
double latUR);
143 setBoundingBox(bbox.lowerLeft.x, bbox.lowerLeft.y, bbox.upperRight.x, bbox.upperRight.y);
149 void setBoundingBoxD(
double lonLL,
double latLL,
double lonUR,
double latUR);
155 setBoundingBoxD(bboxD.lowerLeft.x, bboxD.lowerLeft.y, bboxD.upperRight.x, bboxD.upperRight.y);
162 setBoundingBoxD(RAD2DEG*lonLL, RAD2DEG*latLL, RAD2DEG*lonUR, RAD2DEG*latUR);
168 setBoundingBoxR(bboxR.lowerLeft.x, bboxR.lowerLeft.y, bboxR.upperRight.x, bboxR.upperRight.y);
238 cropWithM(bboxM.lowerLeft.x, bboxM.lowerLeft.y, bboxM.upperRight.x, bboxM.upperRight.y);
242 void cropWithM(
double xLL,
double yLL,
double xUR,
double yUR);
247 void deg2pix(
double lon,
double lat,
int & i,
int & j)
const {
251 m2pix(lon, lat, i,j);
257 deg2pix(loc.x, loc.y, pix.x, pix.y);
264 void deg2m(
double lon,
double lat,
double &x,
double &y)
const {
273 deg2m(pDeg.x, pDeg.y, pMet.x, pMet.y);
278 void pix2deg(
int i,
int j,
double & lon,
double & lat)
const {
287 void pix2rad(
int i,
int j,
double & lon,
double & lat)
const {
299 pix2deg(pix.x,pix.y, loc.x,loc.y);
304 void pix2LLdeg(
int i,
int j,
double & lon,
double & lat)
const {
316 void m2deg(
double x,
double y,
double & lon,
double & lat)
const {
349 void m2pix(
double x,
double y,
int & i,
int & j)
const {
353 i = ::lround((x -
bBoxNative.lowerLeft.x) / xScale);
354 j = frame.height-1 - ::lround((y -
bBoxNative.lowerLeft.y) / yScale);
361 m2pix(pMetric.x, pMetric.y, pImage.x, pImage.y);
377 void pix2m(
int i,
int j,
double & x,
double & y)
const {
378 x = (
static_cast<double>(i)+0.5)*xScale +
bBoxNative.lowerLeft.x;
379 y = (
static_cast<double>(frame.height-1 - j)+0.5)*yScale +
bBoxNative.lowerLeft.y;
388 pMetric.x = (
static_cast<double>(pImage.x)+0.5)*xScale +
bBoxNative.lowerLeft.x;
389 pMetric.y = (
static_cast<double>(frame.height-1 - pImage.y)+0.5)*yScale +
bBoxNative.lowerLeft.y;
402 void pix2LLm(
int i,
int j,
double & x,
double & y)
const {
403 x = (
static_cast<double>(i))*xScale +
bBoxNative.lowerLeft.x;
404 y = (
static_cast<double>(frame.height-1 - j))*yScale +
bBoxNative.lowerLeft.y;
409 void setProjection(
const Projector & proj){
410 if (proj.getEPSG() > 0){
443 int getEPSG()
const {
484 bool isLongLat()
const {
492 template <
typename BB>
493 drain::Unit
convert(
const std::string & bboxStr, BB & bbox);
496 void convert(
const std::vector<double> &bb, drain::Unit unit,
500 drain::Unit
convert(
const std::string & bbox,
506 std::ostream & toStream(std::ostream & ostr)
const;
554template <
typename BB>
559 drain::Unit unit = drain::Units::extract<drain::Unit>(bboxStr);
560 if (unit == drain::Unit::UNDEFINED){
565 unit = drain::Unit::PIXEL;
573std::ostream & operator<<(std::ostream & ostr,
const GeoFrame & frame){
574 frame.GeoFrame::toStream(ostr);
bool isMetric() const
Check if this Bounding Box has metric coordinates, instead of degrees.
Definition BoundingBox.h:94
Something that has width and height.
Definition Frame.h:53
bool isLongLat() const
Check if destination projection is longitude-latitude degrees.
Definition Proj6.h:259
const std::string & getProjStrSrc() const
Returns the projection std::string applied by the last setProjection call.
Definition Proj6.h:165
void projectFwd(double &x, double &y) const
Forward projection (in-place)
Definition Proj6.h:190
void setProjectionDst(const T &...args)
Sets destination projection.
Definition Proj6.h:131
Definition Projector.h:52
Tuple of N elements of type T.
Definition UniTuple.h:65
Array with georeferencing support.
Definition GeoFrame.h:56
drain::Unit convert(const std::string &bboxStr, BB &bbox)
Split bbox string to numeric bbox, deriving the unit from the end of the string or numeric scale.
Definition GeoFrame.h:555
drain::Rectangle< double > bBoxR
Geographical scope in Radians.
Definition GeoFrame.h:525
const std::string & getProjStr() const
Returns the projection of the composite image as a proj4 std::string.
Definition GeoFrame.h:449
void setBoundingBox(const drain::Rectangle< double > &bbox)
Sets bounding box in degrees in the target coordinate system.
Definition GeoFrame.h:142
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:387
virtual void m2pix(double x, double y, int &i, int &j) const
Scales geographic map coordinates to image coordinates.
Definition GeoFrame.h:349
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:469
const drain::Rectangle< double > & getBoundingBoxRad() const
Returns the geographical scope in Radians.
Definition GeoFrame.h:214
void setProjectionEPSG(int epsg)
Sets the projection of the image as a EPSG code.
Definition GeoFrame.h:428
void updateScaling()
Geometric scaling.
Definition GeoFrame.cpp:320
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:287
virtual void m2deg(const drain::Point2D< double > &pMetric, drain::Point2D< double > &pDeg) const
Convert metric coordinates to degrees.
Definition GeoFrame.h:326
void updateProjection()
Updates bboxes, if needed.
Definition GeoFrame.cpp:278
const Proj6 & getProj() const
Returns the projection of the composite image as a proj4 std::string.
Definition GeoFrame.h:438
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:298
void updateDataExtentNat(const drain::Rectangle< double > &inputBBoxNat)
Definition GeoFrame.cpp:407
void setBoundingBoxR(double lonLL, double latLL, double lonUR, double latUR)
Sets bounding box in radians in the target coordinate system.
Definition GeoFrame.h:161
const drain::Rectangle< double > & getDataBBoxNat() const
Return the actual geographical boundingBox suggested by implied by input data.
Definition GeoFrame.h:464
void updateBoundingBoxR()
Proj 6 NEW: Given BBox in geo coords [deg], adjust geo coords [rad].
Definition GeoFrame.cpp:228
const drain::Rectangle< double > & getBoundingBoxNat() const
Returns the geographical scope in Meters.
Definition GeoFrame.h:210
bool bboxIsSet() const
Returns true, if the bounding box (geographical extent) has been set.
Definition GeoFrame.h:93
int getFrameHeight() const
Return the nominal height, not the height of the memory array which does not have to be allocated.
Definition GeoFrame.h:127
void updateDataExtentDeg(const drain::Rectangle< double > &inputBBoxDeg)
Extend to include this input.
Definition GeoFrame.cpp:393
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:304
void setGeometry(const Frame2D< int > &frame)
This does NOT allocate memory.
Definition GeoFrame.h:109
drain::Rectangle< double > dataBBoxNat
For deriving extent (~union) of input data.
Definition GeoFrame.h:535
bool geometryIsSet() const
Return true, if array area is greater than zero.
Definition GeoFrame.h:83
bool projectionIsSet() const
Returns true, if the geographical extent has been set.
Definition GeoFrame.h:77
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:91
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:402
drain::Rectangle< double > bBoxNative
Geographical scope in meters, or degrees in case of long/lat.
Definition GeoFrame.h:531
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:377
const Frame2D< int > & getGeometry() const
Return frame geometry - the nominal width and height.
Definition GeoFrame.h:119
virtual void deg2m(double lon, double lat, double &x, double &y) const
Convert degrees to native (often metric) coordinates.
Definition GeoFrame.h:264
void setBoundingBoxNat(const drain::UniTuple< double, 4 > &bboxM)
Sets bounding box in meters in the target coordinate system.
Definition GeoFrame.h:181
void setBoundingBoxR(const drain::Rectangle< double > &bboxR)
Sets bounding box in radians in the target coordinate system.
Definition GeoFrame.h:167
virtual void m2deg(double x, double y, double &lon, double &lat) const
Convert metric coordinates to degrees.
Definition GeoFrame.h:316
bool isDefined() const
Returns true, if the projection, array area and geographical extent bounding box has been set.
Definition GeoFrame.h:103
virtual void deg2pix(double lon, double lat, int &i, int &j) const
Projects geographic coordinates to image coordinates.
Definition GeoFrame.h:247
const std::string & getInputProjStr() const
Returns the source projection (should be radian array, lon & lat).
Definition GeoFrame.h:456
void setBoundingBoxNat(double xLL, double yLL, double xUR, double yUR)
Sets bounding box in meters in the target coordinate system.
Definition GeoFrame.cpp:152
drain::Rectangle< double > dataOverlapBBoxNat
For deriving common extent (~intersection) of input data.
Definition GeoFrame.h:539
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:278
const drain::Rectangle< double > & getBoundingBoxDeg() const
Returns the geographical scope in Degrees.
Definition GeoFrame.h:206
void setProjection(const std::string &projDef)
Sets the projection of the image as a Proj string.
Definition GeoFrame.h:421
double getYScale() const
Return vertical resolution of a pixel in meters (if metric) or degrees (if unprojected,...
Definition GeoFrame.h:226
drain::Proj6 projGeo2Native
Radial to metric.
Definition GeoFrame.h:513
void deg2pix(const drain::Point2D< double > &loc, drain::Point2D< int > &pix) const
Project geographic coordinates (degrees) to image coordinates (pixels).
Definition GeoFrame.h:256
void setBoundingBoxD(const drain::Rectangle< double > &bboxD)
Sets bounding box in degrees in the target coordinate system.
Definition GeoFrame.h:154
void cropWithM(drain::Rectangle< double > &bboxM)
Crops the initial bounding box with a given bounding box.
Definition GeoFrame.h:237
void updateBoundingBoxNat()
Given BBox in geo coords [rad], adjust geo coords [deg].
Definition GeoFrame.cpp:236
double getXScale() const
Return horizontal resolution of a pixel in meters (if metric) or degrees (if unprojected,...
Definition GeoFrame.h:220
void deg2m(const drain::Point2D< double > &pDeg, drain::Point2D< double > &pMet) const
Convert degrees to native (often metric) coordinates.
Definition GeoFrame.h:272
void setBoundingBoxD(double lonLL, double latLL, double lonUR, double latUR)
Sets bounding box in degrees in the target coordinate system.
Definition GeoFrame.cpp:132
drain::Rectangle< double > bBoxD
Geographical scope in Degrees.
Definition GeoFrame.h:528
int getFrameWidth() const
Return the nominal width, not the width of the memory array which does not have to be allocated.
Definition GeoFrame.h:123
Rectange defined through lower left and upper right coordinates.
Definition Rectangle.h:65