📄 proj4_base.cpp
字号:
{
ADD_FLOAT(SG_T("lat_1") , _TL("Latitude 1") , 33.0);
ADD_FLOAT(SG_T("lat_2") , _TL("Latitude 2") , 45.0);
}
if( ISID("leac" ) ) // Lambert Equal Area Conic
{
ADD_FLOAT(SG_T("lat_1") , _TL("Latitude 1") , 45.0);
ADD_BOOLE(SG_T("south") , _TL("South") , false);
}
if( ISID("rpoly" ) ) // Rectangular Polyconic
{
ADD_FLOAT(SG_T("lat_ts"), _TL("True Scale Latitude"), 45.0);
}
if( ISID("mpoly" ) ) // Modified Polyconic
{
ADD_FLOAT(SG_T("lat_1") , _TL("Latitude 1") , 33.0);
ADD_FLOAT(SG_T("lat_2") , _TL("Latitude 2") , 45.0);
ADD_BOOLE(SG_T("lotsa") , _TL("Lotsa") , true);
}
if( ISID("bonne" ) ) // Bonne
{
ADD_FLOAT(SG_T("lat_1") , _TL("Latitude 1") , 45.0);
}
//-----------------------------------------------------
// Azimuthal Projections...
if( ISID("stere" ) ) // Stereographic
{
ADD_FLOAT(SG_T("lat_ts"), _TL("True Scale Latitude"), 45.0);
}
if( ISID("ups" ) ) // Universal Polar Stereographic
{
ADD_BOOLE(SG_T("south") , _TL("South") , true);
}
if( ISID("airy" ) ) // Airy
{
ADD_FLOAT(SG_T("lat_b") , _TL("Latitude B") , 45.0);
ADD_BOOLE(SG_T("no_cut"), _TL("No Cut" ) , true);
}
if( ISID("nsper" ) ) // Near-sided perspective
{
ADD_FLOAT(SG_T("h") , _TL("Height of view point"), 1.0);
}
if( ISID("aeqd" ) ) // Azimuthal Equidistant
{
ADD_BOOLE(SG_T("guam") , _TL("guam") , true);
}
if( ISID("hammer" ) ) // Hammer & Eckert-Greifendorff
{
ADD_FLOAT(SG_T("W") , _TL("W") , 0.5);
ADD_FLOAT(SG_T("M") , _TL("M") , 1.0);
}
if( ISID("wintri" ) ) // Winkel Tripel
{
ADD_FLOAT(SG_T("lat_1") , _TL("Latitude 1") , 40.0);
}
//-----------------------------------------------------
// Miscellaneous Projections...
if( ISID("ocea" ) // Oblique Cylindrical Equal Area
|| ISID("tpeqd" ) ) // Two Point Equidistant
{
ADD_FLOAT(SG_T("lat_1") , _TL("Latitude 1") , 40.0);
ADD_FLOAT(SG_T("lon_1") , _TL("Longitude 1") ,-20.0);
ADD_FLOAT(SG_T("lat_2") , _TL("Latitude 2") , 50.0);
ADD_FLOAT(SG_T("lon_2") , _TL("Longitude 2" ) , 20.0);
}
if( ISID("lsat" ) ) // Space oblique for LANDSAT
{
ADD_INTEG(SG_T("lsat") , _TL("Landsat") , 1.0);
ADD_INTEG(SG_T("path") , _TL("Path") , 1.0);
}
if( ISID("labrd" ) ) // Laborde
{
ADD_FLOAT(SG_T("azi") , _TL("Azimuth" ) , 19.0);
ADD_FLOAT(SG_T("k_0") , _TL("k_0") , 0.9995);
}
if( ISID("lagrng" ) ) // Lagrange
{
ADD_FLOAT(SG_T("lat_1") , _TL("Latitude 1") , 0.0);
ADD_FLOAT(SG_T("W") , _TL("W") , 2.0);
}
if( ISID("chamb" ) ) // Chamberlin Trimetric
{
ADD_FLOAT(SG_T("lat_1") , _TL("Latitude 1") , 30.0);
ADD_FLOAT(SG_T("lon_1") , _TL("Longitude 1" ) ,-20.0);
ADD_FLOAT(SG_T("lat_2") , _TL("Latitude 2") , 40.0);
ADD_FLOAT(SG_T("lon_2") , _TL("Longitude 2") , 00.0);
ADD_FLOAT(SG_T("lat_3") , _TL("Latitude 3") , 50.0);
ADD_FLOAT(SG_T("lon_3") , _TL("Longitude 3" ) , 20.0);
}
if( ISID("oea" ) ) // Oblated Equal Area
{
ADD_FLOAT(SG_T("m") , _TL("m") , 1.0);
ADD_FLOAT(SG_T("n") , _TL("n") , 1.0);
ADD_FLOAT(SG_T("theta") , _TL("theta") , 45.0);
}
if( ISID("tpers" ) ) // Tilted perspective
{
ADD_FLOAT(SG_T("tilt") , _TL("Tilt") , 45.0);
ADD_FLOAT(SG_T("azi") , _TL("Azimuth") , 45.0);
ADD_FLOAT(SG_T("h") , _TL("h") , 1000.0);
}
if( ISID("ob_tran" ) ) // General Oblique Transformation
{
ADD_FLOAT(SG_T("o_lat_p") , _TL("Latitude Pole") , 40.0);
ADD_FLOAT(SG_T("o_lon_p") , _TL("Longitude Pole") , 40.0);
}
return( true );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CPROJ4_Base::On_Execute(void)
{
bool bResult;
//-----------------------------------------------------
bResult = false;
m_Projection = NULL;
//-----------------------------------------------------
if( bInitialized && Set_Transformation(true) )
{
bResult = On_Execute_Conversion();
}
//-----------------------------------------------------
if( m_Projection )
{
pj_free(m_Projection);
}
return( bResult );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#define ADD_PARG(sKey, sVal) s.Printf(CSG_String(sKey), sVal);\
pargv = (char **)SG_Realloc(pargv, (pargc + 1) * sizeof(char *));\
pargv[pargc] = (char *)SG_Malloc((s.Length() + 1) * sizeof(char ));\
memcpy(pargv[pargc], s.c_str(), s.Length() + 1);\
pargc++;
//---------------------------------------------------------
bool CPROJ4_Base::Set_Transformation(bool bHistory)
{
bool bResult;
char **pargv;
int pargc, i;
CSG_String s;
//-----------------------------------------------------
bResult = true;
pargc = 0;
pargv = NULL;
m_Reverse = false;
m_Inverse = Parameters("DIRECTION")->asInt() == 1;
//-----------------------------------------------------
ADD_PARG("proj=%s" , pj_list[Parameters("PROJ_TYPE")->asInt()].id);
//-----------------------------------------------------
switch( Parameters("ELLIPSOID")->asInt() )
{
case 0: // Predefined
ADD_PARG("ellps=%s" , pj_ellps[Parameters("ELLPS_PREDEF")->asInt()].id);
break;
case 1: // Semiminor axis
ADD_PARG("a=%f" , Parameters("ELLPS_A" )->asDouble());
ADD_PARG("b=%f" , Parameters("ELLPS_B" )->asDouble());
break;
case 2: // Flattening
ADD_PARG("a=%f" , Parameters("ELLPS_A" )->asDouble());
ADD_PARG("f=%f" , Parameters("ELLPS_F" )->asDouble());
break;
case 3: // Reciprocal Flattening
ADD_PARG("a=%f" , Parameters("ELLPS_A" )->asDouble());
ADD_PARG("rf=%f", Parameters("ELLPS_RF")->asDouble());
break;
case 4: // Eccentricity
ADD_PARG("a=%f" , Parameters("ELLPS_A" )->asDouble());
ADD_PARG("e=%f" , Parameters("ELLPS_E" )->asDouble());
break;
case 5: // Eccentricity Squared
ADD_PARG("a=%f" , Parameters("ELLPS_A" )->asDouble());
ADD_PARG("es=%f", Parameters("ELLPS_ES")->asDouble());
break;
}
//-----------------------------------------------------
ADD_PARG("units=%s" , pj_units[Parameters("UNIT")->asInt()].id);
ADD_PARG("lon_0=%f" , Parameters("LON_0")->asDouble());
ADD_PARG("lat_0=%f" , Parameters("LAT_0")->asDouble());
ADD_PARG("x_0=%f" , Parameters("X_0" )->asDouble());
ADD_PARG("y_0=%f" , Parameters("Y_0" )->asDouble());
//-----------------------------------------------------
if( !Get_ExtraParms(pargc, &pargv, pj_list[Parameters("PROJ_TYPE")->asInt()].id) )
{
bResult = false;
}
else if( (m_Projection = pj_init(pargc, pargv)) == NULL )
{
Message_Add (_TL("Projection initialization failure\ncause: "));
Message_Add (CSG_String(pj_strerrno(pj_errno)));
Error_Set (CSG_String(pj_strerrno(pj_errno)));
bResult = false;
}
else if( m_Inverse && !m_Projection->inv )
{
Message_Add (_TL("Inverse transformation not available for selected projection type."));
Error_Set (_TL("Inverse transformation not available for selected projection type."));
bResult = false;
}
//-----------------------------------------------------
for(i=0; i<pargc; i++)
{
SG_Free(pargv[i]);
}
SG_Free(pargv);
return( bResult );
}
//---------------------------------------------------------
bool CPROJ4_Base::Get_ExtraParms(int &pargc, char ***p_pargv, char *id)
{
char **pargv;
int i;
CSG_String s, sFormat;
CSG_Parameters *pParms;
CSG_Parameter *pParm;
if( (pParms = Get_Parameters(id)) != NULL && pParms->Get_Count() > 0 )
{
if( Dlg_Parameters(id) )
{
pargv = *p_pargv;
for(i=0; i<pParms->Get_Count(); i++)
{
pParm = pParms->Get_Parameter(i);
switch( pParm->Get_Type() )
{
case PARAMETER_TYPE_Bool:
if( pParm->asBool() )
{
ADD_PARG("%s", pParm->Get_Identifier());
}
break;
case PARAMETER_TYPE_Int:
sFormat.Printf(SG_T("%s=%%d"), pParm->Get_Identifier());
ADD_PARG(sFormat.c_str(), pParm->asInt());
break;
case PARAMETER_TYPE_Double:
sFormat.Printf(SG_T("%s=%%f"), pParm->Get_Identifier());
ADD_PARG(sFormat.c_str(), pParm->asDouble());
break;
}
}
*p_pargv = pargv;
}
else
{
return( false );
}
}
return( true );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CPROJ4_Base::Set_Transformation_Inverse(void)
{
if( m_Projection && m_Projection->inv )
{
m_Reverse = true;
return( true );
}
Message_Add (_TL("Inverse transformation not available for selected projection type."));
Error_Set (_TL("Inverse transformation not available for selected projection type."));
return( false );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CPROJ4_Base::Get_Converted(TSG_Point &Point)
{
return( Get_Converted(Point.x, Point.y) );
}
bool CPROJ4_Base::Get_Converted(double &x, double &y)
{
bool bInverse;
projUV c;
if( m_Projection )
{
bInverse = m_Inverse ? !m_Reverse : m_Reverse;
if( !bInverse )
{
c.u = x * DEG_TO_RAD;
c.v = y * DEG_TO_RAD;
c = pj_fwd(c, m_Projection);
if( c.u != HUGE_VAL && c.v != HUGE_VAL )
{
x = c.u;
y = c.v;
return( true );
}
}
else
{
c.u = x;
c.v = y;
c = pj_inv(c, m_Projection);
if( c.u != HUGE_VAL && c.v != HUGE_VAL )
{
x = c.u * RAD_TO_DEG;
y = c.v * RAD_TO_DEG;
return( true );
}
}
}
return( false );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -