Browse Source

Gmt module: In struct gmt_projection:

1) Add NOTDEF values to enums.
2) Change type of projections parameters from double to gmt_coord.
3) Correct Value() function to also print region.
4) Setting project type by the name.
Correct list of include files.
ObjPtr
Michael Uleysky 9 years ago
parent
commit
6267df2b4b
  1. 2
      modules/gmt/modgmt.cpp
  2. 43
      modules/gmt/modgmt_objects.cpp
  3. 1
      modules/gmt/modgmt_objects.h
  4. 72
      modules/gmt/modgmt_structs.h

2
modules/gmt/modgmt.cpp

@ -79,6 +79,8 @@ int gmt_module_init(void* p)
free(h); free(f);
if(0!=ret) return ret;
gmt_projection::FillProjNames();
RegisterFunction("GMT_Header",GMT_Header);
RegisterFunction("GMT_Footer",GMT_Footer);
return 0;

43
modules/gmt/modgmt_objects.cpp

@ -6,3 +6,46 @@ template<> const std::string ObjectGMTProjection::type="GMTProjection";
template<> const std::string ObjectGMTColor::type="GMTColor";
template<> const std::string ObjectGMTDash::type="GMTDash";
template<> const std::string ObjectGMTPen::type="GMTPen";
std::map<std::string,gmt_projection::projection> gmt_projection::projnames;
void gmt_projection::FillProjNames()
{
projnames["x"]=XY;
projnames["xy"]=XY;
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["t"]=TRANSMERCATOR;
projnames["tmerc"]=TRANSMERCATOR;
projnames["transverse mercator"]=TRANSMERCATOR;
projnames["o"]=OBLIQMERCATOR;
projnames["omerc"]=OBLIQMERCATOR;
projnames["oblique mercator"]=OBLIQMERCATOR;
projnames["c"]=CASSINI;
projnames["cassini"]=CASSINI;
projnames["y"]=CYL_EQA;
projnames["cyl_equala"]=CYL_EQA;
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;
}
const double gmt_projection::default_width=10.0;

1
modules/gmt/modgmt_objects.h

@ -1,6 +1,7 @@
#ifndef MODGMT_OBJECTS_H
#define MODGMT_OBJECTS_H
#include <cmath>
#include <map>
#include <string.h>
#include <vector>
#include "common.h"

72
modules/gmt/modgmt_structs.h

@ -1,6 +1,9 @@
#ifndef MODGMT_STRUCT_H
#define MODGMT_STRUCT_H
#include <cinttypes>
#include <cmath>
#include <map>
#include "common.h"
// Coordinate
struct gmt_coord
@ -129,15 +132,16 @@ struct gmt_region
struct gmt_projection
{
// OBLIQMERCATOR types
enum class OType {A,B,C};
enum class OType {NOTDEF,A,B,C};
// No UTM (-Ju)
enum projection {XY,CYL_EQU,MERCATOR,TRANSMERCATOR,OBLIQMERCATOR,CASSINI,CYL_EQA,MILLER,CYL_STERE};
enum projection {NOTDEF,XY,CYL_EQU,MERCATOR,TRANSMERCATOR,OBLIQMERCATOR,CASSINI,CYL_EQA,MILLER,CYL_STERE};
// Real size in cm of drawing area
double rwidth,rheight;
struct gmt_region region;
projection proj;
double width; // parameter of projection
static const double default_width;
union // other projection parameters
{
@ -145,56 +149,74 @@ struct gmt_projection
struct {double height;} x;
// Cylindrical projections
// CYL_EQU (Cylindrical Equidistant -Jq)
struct {double stpar,cmer;} q;
struct {struct gmt_coord stpar,cmer;} q;
// MERCATOR (-Jm)
struct {double stpar,cmer;} m;
struct {struct gmt_coord stpar,cmer;} m;
// TRANSMERCATOR (-Jt)
struct {double cmer,orlat,scale;} t;
struct {struct gmt_coord cmer,orlat; double scale;} t;
// OBLIQMERCATOR (-Jo)
struct
{
OType type;
double clon,clat;
struct gmt_coord clon,clat;
union
{
double azimuth; // A
struct {double eqlon,eqlat;}; // B
struct {double polelon,polelat;}; // C
struct gmt_coord azimuth; // A
struct {struct gmt_coord eqlon,eqlat;}; // B
struct {struct gmt_coord polelon,polelat;}; // C
};
} o;
// CASSINI (-Jc)
struct {double clon,clat;} c;
struct {struct gmt_coord clon,clat;} c;
// CYL_EQA (Cylindrical equal-area -Jy)
struct {double stpar,cmer;} y;
struct {struct gmt_coord stpar,cmer;} y;
// MILLER (-Jj)
struct {double cmer;} j;
struct {struct gmt_coord cmer;} j;
// CYL_STERE (Cylindrical stereographic -Jcyl_stere)
struct {double stpar,cmer;} cyl_stere;
struct {struct gmt_coord stpar,cmer;} cyl_stere;
};
std::string Value() const
{
std::string ret;
switch(proj)
{
case(XY): return "-JX"+std::to_string(width)+"c/"+std::to_string(x.height)+"c";
case(CYL_EQU): return "-JQ"+std::to_string(q.cmer)+"/"+std::to_string(q.stpar)+"/"+std::to_string(width)+"c";
case(MERCATOR): return "-JM"+std::to_string(m.cmer)+"/"+std::to_string(m.stpar)+"/"+std::to_string(width)+"c";
case(TRANSMERCATOR): return "-JT"+std::to_string(t.cmer)+"/"+std::to_string(t.orlat)+"/"+std::to_string(width)+"c --PROJ_SCALE_FACTOR="+std::to_string(t.scale);
case(XY): {ret="-JX"+std::to_string(width)+"c/"+std::to_string(x.height)+"c"; break;}
case(CYL_EQU): {ret="-JQ"+q.cmer.Value()+"/"+q.stpar.Value()+"/"+std::to_string(width)+"c"; break;}
case(MERCATOR): {ret="-JM"+m.cmer.Value()+"/"+m.stpar.Value()+"/"+std::to_string(width)+"c"; break;}
case(TRANSMERCATOR): {ret="-JT"+t.cmer.Value()+"/"+t.orlat.Value()+"/"+std::to_string(width)+"c --PROJ_SCALE_FACTOR="+std::to_string(t.scale); break;}
case(OBLIQMERCATOR):
{
switch(o.type)
{
case(OType::A): return "-JOa"+std::to_string(o.clon)+"/"+std::to_string(o.clat)+"/"+std::to_string(o.azimuth)+"/"+std::to_string(width)+"c";
case(OType::B): return "-JOb"+std::to_string(o.clon)+"/"+std::to_string(o.clat)+"/"+std::to_string(o.eqlon)+"/"+std::to_string(o.eqlat)+"/"+std::to_string(width)+"c";
case(OType::C): return "-JOb"+std::to_string(o.clon)+"/"+std::to_string(o.clat)+"/"+std::to_string(o.polelon)+"/"+std::to_string(o.polelat)+"/"+std::to_string(width)+"c";
case(OType::A): {ret="-JOa"+o.clon.Value()+"/"+o.clat.Value()+"/"+o.azimuth.Value()+"/"+std::to_string(width)+"c"; break;}
case(OType::B): {ret="-JOb"+o.clon.Value()+"/"+o.clat.Value()+"/"+o.eqlon.Value()+"/"+o.eqlat.Value()+"/"+std::to_string(width)+"c"; break;}
case(OType::C): {ret="-JOb"+o.clon.Value()+"/"+o.clat.Value()+"/"+o.polelon.Value()+"/"+o.polelat.Value()+"/"+std::to_string(width)+"c"; break;}
default: return "";
}
}
case(CASSINI): return "-JC"+std::to_string(c.clon)+"/"+std::to_string(c.clat)+"/"+std::to_string(width)+"c";
case(CYL_EQA): return "-JY"+std::to_string(y.stpar)+"/"+std::to_string(y.cmer)+"/"+std::to_string(width)+"c";
case(MILLER): return "-JJ"+std::to_string(j.cmer)+"/"+std::to_string(width)+"c";
case(CYL_STERE): return "-JCyl_stere"+std::to_string(cyl_stere.stpar)+"/"+std::to_string(cyl_stere.cmer)+"/"+std::to_string(width)+"c";
case(CASSINI): {ret="-JC"+c.clon.Value()+"/"+c.clat.Value()+"/"+std::to_string(width)+"c"; break;}
case(CYL_EQA): {ret="-JY"+y.stpar.Value()+"/"+y.cmer.Value()+"/"+std::to_string(width)+"c"; break;}
case(MILLER): {ret="-JJ"+j.cmer.Value()+"/"+std::to_string(width)+"c"; break;}
case(CYL_STERE): {ret="-JCyl_stere"+cyl_stere.stpar.Value()+"/"+cyl_stere.cmer.Value()+"/"+std::to_string(width)+"c"; break;}
default: return "";
}
return "";
ret+=" "+region.Value();
return ret;
}
bool SetType(const std::string& s)
{
proj=NOTDEF;
std::string str=s;
tolower(str);
if(projnames.end()==projnames.find(s)) return false;
proj=projnames[s];
return true;
}
static void FillProjNames();
private:
static std::map<std::string,projection> projnames;
};

Loading…
Cancel
Save