ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
geoTiles.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2020 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  * Daniel Heß - initial implementation
13  * Thomas Lobig
14  ********************************************************************************/
15 
16 #pragma once
17 #include <cmath>
18 #include <string>
19 #include <sstream>
20 #include <iostream>
21 #include <iomanip>
22 
23 namespace adore
24 {
25 
26  namespace PLOT
27  {
32  class GeoTiles
33  {
34  private:
35  double width_meters_;
36  std::string base_url_;
37  bool overlaps(double a0, double a1,double b0, double b1)
38  {
39  return b0<=a0 && a0<=b1 || b0<=a1 && a1<=b1;
40  }
41  public:
42  GeoTiles(std::string base_url, double width_meters)
43  {
44  base_url_ = base_url;
45  width_meters_ = width_meters;
46  }
47 
48  double getWidthM()
49  {
50  return width_meters_;
51  }
52  std::string getURL(double xUTM,double yUTM)
53  {
54  std::stringstream s;
55  s.str("");
56  s<<base_url_<<(int)(xUTM)<<","<<(int)(yUTM)<<","<<(int)(xUTM+width_meters_)<<","<<(int)(yUTM+width_meters_);
57  return s.str();
58  }
59  std::string getURL(double X0,double Y0,double X1,double Y1,double res)
60  {
61  int width_start = base_url_.find("width=",0)+6;
62  int width_end = base_url_.find("&",width_start);
63  int height_start = base_url_.find("height=",0)+7;
64  int height_end = base_url_.find("&",height_start);
65  // int width = (int)((std::max(X0,X1)-std::min(X0,X1))*res);
66  // int height = (int)((std::max(Y0,Y1)-std::min(Y0,Y1))*res);
67  //TODO: why is image loading from geoserver corrupted for non-square images?
68  int width=res;
69  int height=res;
70  std::stringstream ss;
71  if(width_start<height_start)
72  {
73  ss<<base_url_.substr(0,width_start)
74  <<width
75  <<base_url_.substr(width_end,height_start-width_end)
76  <<height
77  <<base_url_.substr(height_end);
78  }
79  else
80  {
81  ss<<base_url_.substr(0,height_start)
82  <<width
83  <<base_url_.substr(height_end,width_start-height_end)
84  <<height
85  <<base_url_.substr(width_end);
86  }
87  ss<<std::fixed<<std::setprecision(0);
88  ss<<(std::min)(X0,X1)<<","<<(std::min)(Y0,Y1)<<","<<(std::max)(X0,X1)<<","<<(std::max)(Y0,Y1);
89  return ss.str();
90  }
91  std::string getURL(std::pair<int,int> id)
92  {
93  return getURL(((double)id.first)*width_meters_,((double)id.second)*width_meters_);
94  }
95  double getCenterX(std::pair<int,int> id)
96  {
97  return ((double)id.first)*width_meters_+width_meters_*0.5;
98  }
99  double getCenterY(std::pair<int,int> id)
100  {
101  return ((double)id.second)*width_meters_+width_meters_*0.5;
102  }
103  std::pair<int,int> getTileID(double xUTM,double yUTM)
104  {
105  return std::make_pair((int)(xUTM/width_meters_),(int)(yUTM/width_meters_));
106  }
107  bool overlapsBox(std::pair<int,int> id,double xUTM0,double yUTM0,double xUTM1,double yUTM1)
108  {
109  double x = ((double)id.first)*width_meters_;
110  double y = ((double)id.second)*width_meters_;
111  bool ix = overlaps(x,x+width_meters_,xUTM0,xUTM1);
112  bool iy = overlaps(y,y+width_meters_,yUTM0,yUTM1);
113  return ix && iy;
114  }
115  void getVisibleRange(double xUTM0,double yUTM0,double xUTM1,double yUTM1,int& imin,int& jmin,int& imax,int& jmax)
116  {
117  imin = (int)(xUTM0/width_meters_);
118  jmin = (int)(yUTM0/width_meters_);
119  imax = imin + std::floor((xUTM1-((double)imin)*width_meters_)/width_meters_);
120  jmax = jmin + std::floor((yUTM1-((double)jmin)*width_meters_)/width_meters_);
121  }
122  std::string getPlotID(std::pair<int,int> id)
123  {
124  std::stringstream s;
125  s.str("");
126  s<<"#GeoTile("<<id.first<<","<<id.second<<")";
127  return s.str();
128  }
129  };
130  }
131 
132 }
Class to help with handling of tile servers used for satellite image background tiles.
Definition: geoTiles.h:33
double width_meters_
Definition: geoTiles.h:35
bool overlaps(double a0, double a1, double b0, double b1)
Definition: geoTiles.h:37
std::string getURL(std::pair< int, int > id)
Definition: geoTiles.h:91
double getCenterY(std::pair< int, int > id)
Definition: geoTiles.h:99
double getWidthM()
Definition: geoTiles.h:48
double getCenterX(std::pair< int, int > id)
Definition: geoTiles.h:95
std::pair< int, int > getTileID(double xUTM, double yUTM)
Definition: geoTiles.h:103
std::string getURL(double xUTM, double yUTM)
Definition: geoTiles.h:52
void getVisibleRange(double xUTM0, double yUTM0, double xUTM1, double yUTM1, int &imin, int &jmin, int &imax, int &jmax)
Definition: geoTiles.h:115
std::string base_url_
Definition: geoTiles.h:36
std::string getPlotID(std::pair< int, int > id)
Definition: geoTiles.h:122
std::string getURL(double X0, double Y0, double X1, double Y1, double res)
Definition: geoTiles.h:59
bool overlapsBox(std::pair< int, int > id, double xUTM0, double yUTM0, double xUTM1, double yUTM1)
Definition: geoTiles.h:107
GeoTiles(std::string base_url, double width_meters)
Definition: geoTiles.h:42
T min(T a, T b, T c, T d)
Definition: adoremath.h:663
adoreMatrix< T, N, M > max(adoreMatrix< T, N, M > a, const adoreMatrix< T, N, M > &b)
Definition: adoremath.h:686
x
Definition: adore_set_goal.py:30
y
Definition: adore_set_goal.py:31
Definition: areaofeffectconverter.h:20