34 Egcs::Egcs(
unsigned short level)
39 unsigned short Egcs::cell2level(
const std::string& cellCode)
const{
40 size_t pos=cellCode.find(
"-");
41 std::string TILE=cellCode.substr(0,pos);
42 unsigned short level=0;
43 int base_level=19-(TILE.size()/2-1)*3;
45 if(pos!=std::string::npos)
46 quad_level=cellCode.size()-pos-1;
59 unsigned short Egcs::res2level(
double resolution)
const{
60 double base=pow(10,log(resolution*4.0)/log(10.0));
61 double diff=base/(2*resolution);
62 return 0.5+(log(base)/log(10.0)*3+1-diff);
65 double Egcs::getResolution()
const{
66 unsigned short exponent=(m_level+1)/3;
67 double base=pow(10.0,exponent);
70 else if((m_level)%3==0)
76 void Egcs::force2grid(
double& ulx,
double& uly,
double& lrx,
double &lry)
const{
77 double dx=getResolution();
81 ulx-=
static_cast<int>(ulx)%(static_cast<int>(dx));
84 if(static_cast<int>(uly)%static_cast<int>(dy))
86 uly-=
static_cast<int>(uly)%(static_cast<int>(dy));
89 if(static_cast<int>(lrx)%static_cast<int>(dx))
91 lrx-=
static_cast<int>(lrx)%(static_cast<int>(dx));
94 lry-=
static_cast<int>(lry)%(static_cast<int>(dy));
97 void Egcs::cell2bb(
const std::string& cellCode,
int &ulx,
int &uly,
int &lrx,
int &lry)
const{
98 size_t pos=cellCode.find(
"-");
99 std::string TILE=cellCode.substr(0,pos);
100 std::string TILEX=TILE.substr(0,TILE.size()/2);
101 std::string TILEY=TILE.substr(TILE.size()/2);
104 std::istringstream stilex(TILEX);
105 std::istringstream stiley(TILEY);
111 switch((19-m_level)%3){
113 assert(pos==std::string::npos);
116 assert(pos+1!=std::string::npos);
117 QUAD=cellCode.substr(pos+1);
118 QUAD2=QUAD.substr(1,1).c_str()[0];
123 lly+=getBaseSize()/4;
126 lly+=getBaseSize()/4;
128 llx+=getBaseSize()/4;
133 assert(pos+1!=std::string::npos);
134 QUAD=cellCode.substr(pos+1);
136 QUAD1=QUAD.substr(0,1).c_str()[0];
141 lly+=getBaseSize()/2;
144 lly+=getBaseSize()/2;
146 llx+=getBaseSize()/2;
152 uly=
static_cast<int>(lly+getSize());
153 lrx=
static_cast<int>(llx+getSize());
157 void Egcs::cell2mid(
const std::string& cellCode,
double& midX,
double& midY)
const{
159 cell2bb(cellCode,ulx,uly,lrx,lry);
164 std::string Egcs::geo2cell(
double geoX,
double geoY)
const{
165 int ndgts=7-(m_level+1)/3;
166 double xcel=
static_cast<int>(geoX)/getBaseSize();
167 double ycel=
static_cast<int>(geoY)/getBaseSize();
168 std::ostringstream osx;
169 std::ostringstream osy, osxy;
174 osx << std::fixed << geoX;
175 osy << std::fixed << geoY;
176 std::string quad1=
"";
177 std::string quad2=
"";
178 switch((19-m_level)%3){
180 if(static_cast<int>(geoX)%(getBaseSize()/2)>=getBaseSize()/2.0){
181 if(static_cast<int>(geoY)%(getBaseSize()/2)>=getBaseSize()/2.0)
186 else if(static_cast<int>(geoY)%getBaseSize()>=getBaseSize()/4.0)
191 if(static_cast<int>(geoX)%getBaseSize()>=getBaseSize()/2.0){
192 if(static_cast<int>(geoY)%getBaseSize()>=getBaseSize()/2.0)
197 else if(static_cast<int>(geoY)%getBaseSize()>=getBaseSize()/2.0)
205 osxy << osx.str().substr(0,ndgts) << osy.str().substr(0,ndgts) << quad1 << quad2;