Browse Source

Gmt module: Using template-based projections names. Fix errors in string representations of projections.

gmtdatadir
Michael Uleysky 8 years ago
parent
commit
6e9dfbf0e7
  1. 40
      modules/gmt/modgmt_objects.cpp
  2. 47
      modules/gmt/modgmt_structs.h

40
modules/gmt/modgmt_objects.cpp

@ -36,41 +36,15 @@ std::map<std::string,gmt_projection::projection> gmt_projection::projnames;
void gmt_projection::FillProjNames() void gmt_projection::FillProjNames()
{ {
projnames["x"]=XY; projnames["(xy|decart)"]=XY;
projnames["xy"]=XY; projnames["c[ylindrical][( |_)]equidistant"]=CYL_EQU;
projnames["decart"]=XY;
projnames["q"]=CYL_EQU;
projnames["cyl_equid"]=CYL_EQU;
projnames["cylindrical equidistant"]=CYL_EQU;
projnames["m"]=MERCATOR;
projnames["merc"]=MERCATOR;
projnames["mercator"]=MERCATOR; projnames["mercator"]=MERCATOR;
projnames["t[ransverse][( |_)]mercator"]=TRANSMERCATOR;
projnames["t"]=TRANSMERCATOR; projnames["o[blique][( |_)]mercator"]=OBLIQMERCATOR;
projnames["tmerc"]=TRANSMERCATOR;
projnames["transverse mercator"]=TRANSMERCATOR;
projnames["o"]=OBLIQMERCATOR;
projnames["omerc"]=OBLIQMERCATOR;
projnames["oblique mercator"]=OBLIQMERCATOR;
projnames["c"]=CASSINI;
projnames["cassini"]=CASSINI; projnames["cassini"]=CASSINI;
projnames["c[ylindrical][( |_)]eq[ua(l|l-)]area"]=CYL_EQA;
projnames["y"]=CYL_EQA; projnames["[c[ylindrical][( |_)]]miller"]=MILLER;
projnames["cyl_equala"]=CYL_EQA; projnames["c[ylindrical][( |_)]stereographic"]=CYL_STERE;
projnames["cylindrical equal-area"]=CYL_EQA;
projnames["cylindrical equalarea"]=CYL_EQA;
projnames["j"]=MILLER;
projnames["cyl_miller"]=MILLER;
projnames["miller"]=MILLER;
projnames["cylindrical miller"]=MILLER;
projnames["cyl_stere"]=CYL_STERE;
projnames["cylindrical stereographic"]=CYL_STERE;
} }
bool gmt_font::FillFontNames() bool gmt_font::FillFontNames()

47
modules/gmt/modgmt_structs.h

@ -6,6 +6,7 @@
#include <vector> #include <vector>
#include "common.h" #include "common.h"
#include "modgmt_colornames.h" #include "modgmt_colornames.h"
#include "modgmt_strcomp.h"
// Centimeters to GMT points scale factor // Centimeters to GMT points scale factor
// 1 inch = 72 pt = 2.54 cm --> 1 cm = 72/2.54 pt // 1 inch = 72 pt = 2.54 cm --> 1 cm = 72/2.54 pt
@ -277,24 +278,58 @@ struct gmt_projection: public gmt_struct
case(OType::C): {ret="-JOb"+o.clon.Value()+"/"+o.clat.Value()+"/"+o.polelon.Value()+"/"+o.polelat.Value()+"/"+ToString(width)+"c"; break;} case(OType::C): {ret="-JOb"+o.clon.Value()+"/"+o.clat.Value()+"/"+o.polelon.Value()+"/"+o.polelat.Value()+"/"+ToString(width)+"c"; break;}
default: return ""; default: return "";
} }
break;
} }
case(CASSINI): {ret="-JC"+c.clon.Value()+"/"+c.clat.Value()+"/"+ToString(width)+"c"; break;} case(CASSINI): {ret="-JC"+c.clon.Value()+"/"+c.clat.Value()+"/"+ToString(width)+"c"; break;}
case(CYL_EQA): {ret="-JY"+y.stpar.Value()+"/"+y.cmer.Value()+"/"+ToString(width)+"c"; break;} case(CYL_EQA): {ret="-JY"+y.cmer.Value()+"/"+y.stpar.Value()+"/"+ToString(width)+"c"; break;}
case(MILLER): {ret="-JJ"+j.cmer.Value()+"/"+ToString(width)+"c"; break;} case(MILLER): {ret="-JJ"+j.cmer.Value()+"/"+ToString(width)+"c"; break;}
case(CYL_STERE): {ret="-JCyl_stere"+cyl_stere.stpar.Value()+"/"+cyl_stere.cmer.Value()+"/"+ToString(width)+"c"; break;} case(CYL_STERE): {ret="-JCyl_stere/"+cyl_stere.stpar.Value()+"/"+cyl_stere.cmer.Value()+"/"+ToString(width)+"c"; break;}
default: return ""; default: return "";
} }
ret+=" "+region.Value(); ret+=" "+region.Value();
return ret; return ret;
} }
bool SetType(const std::string& s) bool SetType(const std::string& s, std::string& err)
{ {
proj=NOTDEF; proj=NOTDEF;
std::string str=s; std::string str=s;
tolower(str); tolower(str);
if(projnames.end()==projnames.find(str)) return false;
proj=projnames[str]; // Handle one symbol cases
return true; if(str.size()==1) switch(str[0])
{
case('c'): {proj=CASSINI; return true;}
case('j'): {proj=MILLER; return true;}
case('m'): {proj=MERCATOR; return true;}
case('o'): {proj=OBLIQMERCATOR; return true;}
case('q'): {proj=CYL_EQU; return true;}
case('t'): {proj=TRANSMERCATOR; return true;}
case('x'): {proj=XY; return true;}
case('y'): {proj=CYL_EQA; return true;}
default: break;
}
// Handle long GMT names
if("cyl_stere"==str) {proj=CYL_STERE; return true;}
// Handle common names
std::string t1;
for(const auto& m: projnames)
{
TemplateComparator cmp(m.first);
bool res=cmp.Compare(str);
if(!res) continue;
if(NOTDEF!=proj) // Ambiguos string
{
err="Ambiguous projection definition: did you mean \""+t1+"\" or \""+cmp.Template2Name()+"\"?";
proj=NOTDEF;
return false;
}
t1=cmp.Template2Name();
proj=m.second;
}
if(NOTDEF!=proj) return true; // All Ok
err="Unknown projection: "+s;
return false;
} }
static void FillProjNames(); static void FillProjNames();

Loading…
Cancel
Save