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