35#include "drain/util/BoundingBox.h"
36#include "drain/util/Geo.h"
37#include "drain/util/Proj6.h"
65 GeoFrame(
unsigned int width = 0,
unsigned int height = 0);
90 return ((frameWidth > 0) && (frameHeight > 0));
100 return (
bBoxD.getArea() > 0.0);
116 void setGeometry(
unsigned int width,
unsigned int height);
134 void setBoundingBox(
double lonLL,
double latLL,
double lonUR,
double latUR);
139 setBoundingBox(bbox.lowerLeft.x, bbox.lowerLeft.y, bbox.upperRight.x, bbox.upperRight.y);
145 void setBoundingBoxD(
double lonLL,
double latLL,
double lonUR,
double latUR);
151 setBoundingBoxD(bboxD.lowerLeft.x, bboxD.lowerLeft.y, bboxD.upperRight.x, bboxD.upperRight.y);
158 setBoundingBoxD(RAD2DEG*lonLL, RAD2DEG*latLL, RAD2DEG*lonUR, RAD2DEG*latUR);
164 setBoundingBoxR(bboxR.lowerLeft.x, bboxR.lowerLeft.y, bboxR.upperRight.x, bboxR.upperRight.y);
234 cropWithM(bboxM.lowerLeft.x, bboxM.lowerLeft.y, bboxM.upperRight.x, bboxM.upperRight.y);
238 void cropWithM(
double xLL,
double yLL,
double xUR,
double yUR);
243 void deg2pix(
double lon,
double lat,
int & i,
int & j)
const {
247 m2pix(lon, lat, i,j);
253 deg2pix(loc.x, loc.y, pix.x, pix.y);
260 void deg2m(
double lon,
double lat,
double &x,
double &y)
const {
269 deg2m(pDeg.x, pDeg.y, pMet.x, pMet.y);
274 void pix2deg(
int i,
int j,
double & lon,
double & lat)
const {
283 void pix2rad(
int i,
int j,
double & lon,
double & lat)
const {
295 pix2deg(pix.x,pix.y, loc.x,loc.y);
300 void pix2LLdeg(
int i,
int j,
double & lon,
double & lat)
const {
312 void m2deg(
double x,
double y,
double & lon,
double & lat)
const {
345 void m2pix(
double x,
double y,
int & i,
int & j)
const {
350 j = frameHeight-1 - ::lround((y -
bBoxNative.lowerLeft.y) / yScale);
359 pImage.y = frameHeight-1 - ::lround((pMetric.y -
bBoxNative.lowerLeft.y) / yScale);
373 void pix2m(
int i,
int j,
double & x,
double & y)
const {
375 y = (
static_cast<double>(frameHeight-1 - j)+0.5)*yScale +
bBoxNative.lowerLeft.y;
382 pMetric.x = (
static_cast<double>(pImage.x)+0.5)*
xScale +
bBoxNative.lowerLeft.x;
383 pMetric.y = (
static_cast<double>(frameHeight-1 - pImage.y)+0.5)*yScale +
bBoxNative.lowerLeft.y;
397 void pix2LLm(
int i,
int j,
double & x,
double & y)
const {
399 y = (
static_cast<double>(frameHeight-1 - j))*yScale +
bBoxNative.lowerLeft.y;
457 bool isLongLat()
const {
466 std::ostream & toStream(std::ostream & ostr)
const;
507std::ostream & operator<<(std::ostream & ostr,
const GeoFrame & frame){
508 frame.GeoFrame::toStream(ostr);
void setProjectionDst(const std::string &projDef, Projector::CRS_mode crs=Projector::FORCE_CRS)
Sets destination projection.
Definition Proj6.h:110
bool isLongLat() const
Check if destination projection is longitude-latitude degrees.
Definition Proj6.h:228
const std::string & getProjectionSrc() const
Returns the projection std::string applied by the last setProjection call.
Definition Proj6.h:144
void projectFwd(double &x, double &y) const
Forward projection (in-place)
Definition Proj6.h:172
void setProjection(const std::string &str, CRS_mode crs=FORCE_CRS)
Sets projection defined as Proj string.
Definition Projector.cpp:97
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:477
void setBoundingBox(const drain::Rectangle< double > &bbox)
Sets bounding box in degrees in the target coordinate system.
Definition GeoFrame.h:138
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 pixel centres.
Definition GeoFrame.h:381
const std::string & getCoordinateSystem() const
Returns the source projection (should be radian array, lon & lat).
Definition GeoFrame.h:431
virtual void m2pix(double x, double y, int &i, int &j) const
Scales geographic map coordinates to image coordinates.
Definition GeoFrame.h:345
const drain::Rectangle< double > & getDataOverlapBBoxNat() const
Return the common overlapping geographical area (intersection) implied by input data.
Definition GeoFrame.h:442
const drain::Rectangle< double > & getBoundingBoxRad() const
Returns the geographical scope in Radians.
Definition GeoFrame.h:210
const std::string & getProjection() const
Returns the projection of the composite image as a proj4 std::string.
Definition GeoFrame.h:426
void setProjectionEPSG(int epsg)
Sets the projection of the image as a EPSG code.
Definition GeoFrame.h:416
void updateScaling()
Geometric scaling.
Definition GeoFrame.cpp:331
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:283
virtual void m2deg(const drain::Point2D< double > &pMetric, drain::Point2D< double > &pDeg) const
Convert metric coordinates to degrees.
Definition GeoFrame.h:322
void updateProjection()
Updates bboxes, if needed.
Definition GeoFrame.cpp:289
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:294
void updateDataExtentNat(const drain::Rectangle< double > &inputBBoxNat)
Definition GeoFrame.cpp:428
void setBoundingBoxR(double lonLL, double latLL, double lonUR, double latUR)
Sets bounding box in radians in the target coordinate system.
Definition GeoFrame.h:157
const drain::Rectangle< double > & getDataBBoxNat() const
Return the actual geographical boundingBox suggested by implied by input data.
Definition GeoFrame.h:437
double xScale
Utility for deriving extent (degrees) required by input data.
Definition GeoFrame.h:501
void updateBoundingBoxR()
Proj 6 NEW: Given BBox in geo coords [deg], adjust geo coords [rad].
Definition GeoFrame.cpp:242
void updateBoundingBoxD()
Given BBox in geo coords [rad], adjust geo coords [deg].
Definition GeoFrame.cpp:234
const drain::Rectangle< double > & getBoundingBoxNat() const
Returns the geographical scope in Meters.
Definition GeoFrame.h:206
bool bboxIsSet() const
Returns true, if the bounding box (geographical extent) has been set.
Definition GeoFrame.h:99
int getFrameHeight() const
Return the nominal height, not the height of the memory array which does not have to be allocated.
Definition GeoFrame.h:124
void updateDataExtentDeg(const drain::Rectangle< double > &inputBBoxDeg)
Extend to include this input.
Definition GeoFrame.cpp:414
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:300
drain::Rectangle< double > dataBBoxNat
For deriving extent (~union) of input data.
Definition GeoFrame.h:488
bool geometryIsSet() const
Return true, if array area is greater than zero.
Definition GeoFrame.h:89
bool projectionIsSet() const
Returns true, if the geographical extent has been set.
Definition GeoFrame.h:83
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:90
void setBoundingBoxM(double xLL, double yLL, double xUR, double yUR)
Sets bounding box in meters in the target coordinate system.
Definition GeoFrame.cpp:168
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 pixel.
Definition GeoFrame.h:397
void setBoundingBoxM(const drain::UniTuple< double, 4 > &bboxM)
Sets bounding box in meters in the target coordinate system.
Definition GeoFrame.h:177
drain::Rectangle< double > bBoxNative
Geographical scope in meters, or degrees in case of long/lat.
Definition GeoFrame.h:483
virtual void pix2m(int i, int j, double &x, double &y) const
Scales image coordinates (i,j) to map coordinates (x,y) in the pixel centres.
Definition GeoFrame.h:373
virtual void deg2m(double lon, double lat, double &x, double &y) const
Convert degrees to native (often metric) coordinates.
Definition GeoFrame.h:260
void setBoundingBoxR(const drain::Rectangle< double > &bboxR)
Sets bounding box in radians in the target coordinate system.
Definition GeoFrame.h:163
void updateBoundingBoxM()
Given BBox in geo coords [rad], adjust metric bounding box. Do not update xScale or yScale.
Definition GeoFrame.cpp:250
virtual void m2deg(double x, double y, double &lon, double &lat) const
Convert metric coordinates to degrees.
Definition GeoFrame.h:312
bool isDefined() const
Returns true, if the projection, array area and geographical extent bounding box has been set.
Definition GeoFrame.h:109
virtual void deg2pix(double lon, double lat, int &i, int &j) const
Projects geographic coordinates to image coordinates.
Definition GeoFrame.h:243
drain::Rectangle< double > dataOverlapBBoxNat
For deriving common extent (~intersection) of input data.
Definition GeoFrame.h:492
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:274
const drain::Rectangle< double > & getBoundingBoxDeg() const
Returns the geographical scope in Degrees.
Definition GeoFrame.h:202
void setProjection(const std::string &projDef)
Sets the projection of the image as a Proj string.
Definition GeoFrame.h:409
double getYScale() const
Return vertical resolution of a pixel in meters (if metric) or degrees (if unprojected,...
Definition GeoFrame.h:222
drain::Proj6 projGeo2Native
Radial to metric.
Definition GeoFrame.h:462
void deg2pix(const drain::Point2D< double > &loc, drain::Point2D< int > &pix) const
Project geographic coordinates (degrees) to image coordinates (pixels).
Definition GeoFrame.h:252
void setBoundingBoxD(const drain::Rectangle< double > &bboxD)
Sets bounding box in degrees in the target coordinate system.
Definition GeoFrame.h:150
void cropWithM(drain::Rectangle< double > &bboxM)
Crops the initial bounding box with a given bounding box.
Definition GeoFrame.h:233
double getXScale() const
Return horizontal resolution of a pixel in meters (if metric) or degrees (if unprojected,...
Definition GeoFrame.h:216
void deg2m(const drain::Point2D< double > &pDeg, drain::Point2D< double > &pMet) const
Convert degrees to native (often metric) coordinates.
Definition GeoFrame.h:268
void setBoundingBoxD(double lonLL, double latLL, double lonUR, double latUR)
Sets bounding box in degrees in the target coordinate system.
Definition GeoFrame.cpp:149
drain::Rectangle< double > bBoxD
Geographical scope in Degrees.
Definition GeoFrame.h:480
int getFrameWidth() const
Return the nominal width, not the width of the memory array which does not have to be allocated.
Definition GeoFrame.h:120
Definition DataSelector.cpp:1277
Rectange defined through lower left and upper right coordinates.
Definition Rectangle.h:65