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 {
266 deg2m(pDeg.x, pDeg.y, pMet.x, pMet.y);
271 void pix2deg(
int i,
int j,
double & lon,
double & lat)
const {
280 void pix2rad(
int i,
int j,
double & lon,
double & lat)
const {
293 pix2deg(pix.x,pix.y, loc.x,loc.y);
298 void pix2LLdeg(
int i,
int j,
double & lon,
double & lat)
const {
310 void m2deg(
double x,
double y,
double & lon,
double & lat)
const {
343 void m2pix(
double x,
double y,
int & i,
int & j)
const {
348 j = frameHeight-1 - ::lround((y -
bBoxNative.lowerLeft.y) / yScale);
357 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;
381 pMetric.x = (
static_cast<double>(pImage.x)+0.5)*
xScale +
bBoxNative.lowerLeft.x;
382 pMetric.y = (
static_cast<double>(frameHeight-1 - pImage.y)+0.5)*yScale +
bBoxNative.lowerLeft.y;
395 void pix2LLm(
int i,
int j,
double & x,
double & y)
const {
397 y = (
static_cast<double>(frameHeight-1 - j))*yScale +
bBoxNative.lowerLeft.y;
455 bool isLongLat()
const {
464 std::ostream & toStream(std::ostream & ostr)
const;
505 std::ostream & operator<<(std::ostream & ostr,
const GeoFrame & frame){
506 frame.GeoFrame::toStream(ostr);
void setProjectionDst(const std::string &projDef, Projector::CRS_mode crs=Projector::FORCE_CRS)
Sets destination projection.
Definition: Proj6.h:286
bool isLongLat() const
Check if destination projection is longitude-latitude degrees.
Definition: Proj6.h:482
void projectFwd(double &x, double &y) const
Forward projection (in-place)
Definition: Proj6.h:359
const std::string & getProjectionSrc() const
Returns the projection std::string applied by the last setProjection call.
Definition: Proj6.h:310
void setProjection(const std::string &str, CRS_mode crs=FORCE_CRS)
Sets projection defined as Proj string.
Definition: Proj6.cpp:70
Array with georeferencing support.
Definition: GeoFrame.h:58
drain::Rectangle< double > bBoxR
Geographical scope in Radians.
Definition: GeoFrame.h:475
void setBoundingBox(const drain::Rectangle< double > &bbox)
Sets bounding box in degrees in the target coordinate system.
Definition: GeoFrame.h:138
virtual void m2pix(double x, double y, int &i, int &j) const
Scales geographic map coordinates to image coordinates.
Definition: GeoFrame.h:343
void setProjectionEPSG(int epsg)
Sets the projection of the image as a EPSG code.
Definition: GeoFrame.h:414
void updateScaling()
Geometric scaling.
Definition: GeoFrame.cpp:331
virtual void pix2rad(int i, int j, double &lon, double &lat) const
Calculates the geographic coordinates [rad] of the center of a pixel at (i,j).
Definition: GeoFrame.h:280
virtual void m2deg(const drain::Point2D< double > &pMetric, drain::Point2D< double > &pDeg) const
Convert metric coordinates to degrees.
Definition: GeoFrame.h:320
void updateProjection()
Updates bboxex, 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:292
const drain::Rectangle< double > & getDataBBoxNat() const
Return the actual geographical boundingBox suggested by implied by input data.
Definition: GeoFrame.h:435
void updateDataExtentNat(const drain::Rectangle< double > &inputBBoxNat)
Definition: GeoFrame.cpp:428
const drain::Rectangle< double > & getBoundingBoxNat() const
Returns the geographical scope in Meters.
Definition: GeoFrame.h:206
void setBoundingBoxR(double lonLL, double latLL, double lonUR, double latUR)
Sets bounding box in radians in the target coordinate system.
Definition: GeoFrame.h:157
double xScale
Utility for deriving extent (degrees) required by input data.
Definition: GeoFrame.h:499
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
bool bboxIsSet() const
Returns true, if the bounding box (geographical extent) has been set.
Definition: GeoFrame.h:99
const drain::Rectangle< double > & getDataOverlapBBoxNat() const
Return the common overlapping geographical area (intersection) implied by input data.
Definition: GeoFrame.h:440
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
GeoFrame(unsigned int width=0, unsigned int height=0)
Default constructor.
Definition: GeoFrame.cpp:60
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:298
drain::Rectangle< double > dataBBoxNat
For deriving extent (~union) of input data.
Definition: GeoFrame.h:486
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
const drain::Rectangle< double > & getBoundingBoxRad() const
Returns the geographical scope in Radians.
Definition: GeoFrame.h:210
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 geographic map coordinates (x,y) of the lower left corner pixel.
Definition: GeoFrame.h:395
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:481
virtual void pix2m(int i, int j, double &x, double &y) const
Scales image coordinates (i,j) to geographic 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 metric coordinates to degrees.
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:310
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:490
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:271
void setProjection(const std::string &projDef)
Sets the projection of the image as a Proj string.
Definition: GeoFrame.h:407
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:460
const std::string & getProjection() const
Returns the projection of the composite image as a proj4 std::string.
Definition: GeoFrame.h:424
void deg2pix(const drain::Point2D< double > &loc, drain::Point2D< int > &pix) const
Project geographic coordinates to image coordinates.
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
const drain::Rectangle< double > & getBoundingBoxDeg() const
Returns the geographical scope in Degrees.
Definition: GeoFrame.h:202
const std::string & getCoordinateSystem() const
Returns the source projection (should be radian array, lon & lat).
Definition: GeoFrame.h:429
double getXScale() const
Return horizontal resolution of a pixel in meters (if metric) or degrees (if unprojected,...
Definition: GeoFrame.h:216
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:478
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: GeoFrame.h:48
Definition: DataSelector.cpp:1277