📄 pj_transform.cpp
字号:
if( Set_Geocentric_Parameters( a, b ) != 0 )
{
pj_errno = PJD_ERR_GEOCENTRIC;
return pj_errno;
}
for( i = 0; i < point_count; i++ )
{
long io = i * point_offset;
if( x[io] == HUGE_VAL )
continue;
Convert_Geocentric_To_Geodetic( x[io], y[io], z[io],
y+io, x+io, z+io );
}
return 0;
}
/************************************************************************/
/* pj_compare_datums() */
/* */
/* Returns TRUE if the two datums are identical, otherwise */
/* FALSE. */
/************************************************************************/
int pj_compare_datums( PJ *srcdefn, PJ *dstdefn )
{
if( srcdefn->datum_type != dstdefn->datum_type )
{
return 0;
}
else if( srcdefn->a != dstdefn->a
|| ABS(srcdefn->es - dstdefn->es) > 0.000000000050 )
{
/* the tolerence for es is to ensure that GRS80 and WGS84 are
considered identical */
return 0;
}
else if( srcdefn->datum_type == PJD_3PARAM )
{
return (srcdefn->datum_params[0] == dstdefn->datum_params[0]
&& srcdefn->datum_params[1] == dstdefn->datum_params[1]
&& srcdefn->datum_params[2] == dstdefn->datum_params[2]);
}
else if( srcdefn->datum_type == PJD_7PARAM )
{
return (srcdefn->datum_params[0] == dstdefn->datum_params[0]
&& srcdefn->datum_params[1] == dstdefn->datum_params[1]
&& srcdefn->datum_params[2] == dstdefn->datum_params[2]
&& srcdefn->datum_params[3] == dstdefn->datum_params[3]
&& srcdefn->datum_params[4] == dstdefn->datum_params[4]
&& srcdefn->datum_params[5] == dstdefn->datum_params[5]
&& srcdefn->datum_params[6] == dstdefn->datum_params[6]);
}
else if( srcdefn->datum_type == PJD_GRIDSHIFT )
{
return strcmp( pj_param(srcdefn->params,"snadgrids").s,
pj_param(dstdefn->params,"snadgrids").s ) == 0;
}
else
return 1;
}
/************************************************************************/
/* pj_geocentic_to_wgs84() */
/************************************************************************/
int pj_geocentric_to_wgs84( PJ *defn,
long point_count, int point_offset,
double *x, double *y, double *z )
{
int i;
pj_errno = 0;
if( defn->datum_type == PJD_3PARAM )
{
for( i = 0; i < point_count; i++ )
{
long io = i * point_offset;
if( x[io] == HUGE_VAL )
continue;
x[io] = x[io] + defn->datum_params[0];
y[io] = y[io] + defn->datum_params[1];
z[io] = z[io] + defn->datum_params[2];
}
}
else if( defn->datum_type == PJD_7PARAM )
{
for( i = 0; i < point_count; i++ )
{
long io = i * point_offset;
double x_out, y_out, z_out;
if( x[io] == HUGE_VAL )
continue;
x_out = M_BF*( x[io] - Rz_BF*y[io] + Ry_BF*z[io]) + Dx_BF;
y_out = M_BF*( Rz_BF*x[io] + y[io] - Rx_BF*z[io]) + Dy_BF;
z_out = M_BF*(-Ry_BF*x[io] + Rx_BF*y[io] + z[io]) + Dz_BF;
x[io] = x_out;
y[io] = y_out;
z[io] = z_out;
}
}
return 0;
}
/************************************************************************/
/* pj_geocentic_from_wgs84() */
/************************************************************************/
int pj_geocentric_from_wgs84( PJ *defn,
long point_count, int point_offset,
double *x, double *y, double *z )
{
int i;
pj_errno = 0;
if( defn->datum_type == PJD_3PARAM )
{
for( i = 0; i < point_count; i++ )
{
long io = i * point_offset;
if( x[io] == HUGE_VAL )
continue;
x[io] = x[io] - defn->datum_params[0];
y[io] = y[io] - defn->datum_params[1];
z[io] = z[io] - defn->datum_params[2];
}
}
else if( defn->datum_type == PJD_7PARAM )
{
for( i = 0; i < point_count; i++ )
{
long io = i * point_offset;
double x_tmp, y_tmp, z_tmp;
if( x[io] == HUGE_VAL )
continue;
x_tmp = (x[io] - Dx_BF) / M_BF;
y_tmp = (y[io] - Dy_BF) / M_BF;
z_tmp = (z[io] - Dz_BF) / M_BF;
x[io] = x_tmp + Rz_BF*y_tmp - Ry_BF*z_tmp;
y[io] = -Rz_BF*x_tmp + y_tmp + Rx_BF*z_tmp;
z[io] = Ry_BF*x_tmp - Rx_BF*y_tmp + z_tmp;
}
}
return 0;
}
/************************************************************************/
/* pj_datum_transform() */
/************************************************************************/
int pj_datum_transform( PJ *srcdefn, PJ *dstdefn,
long point_count, int point_offset,
double *x, double *y, double *z )
{
double src_a, src_es, dst_a, dst_es;
int z_is_temp = FALSE;
pj_errno = 0;
/* -------------------------------------------------------------------- */
/* Short cut if the datums are identical. */
/* -------------------------------------------------------------------- */
if( pj_compare_datums( srcdefn, dstdefn ) )
return 0;
src_a = srcdefn->a;
src_es = srcdefn->es;
dst_a = dstdefn->a;
dst_es = dstdefn->es;
/* -------------------------------------------------------------------- */
/* Create a temporary Z array if one is not provided. */
/* -------------------------------------------------------------------- */
if( z == NULL )
{
int bytes = sizeof(double) * point_count * point_offset;
z = (double *) pj_malloc(bytes);
memset( z, 0, bytes );
z_is_temp = TRUE;
}
#define CHECK_RETURN {if( pj_errno != 0 ) { if( z_is_temp ) pj_dalloc(z); return pj_errno; }}
/* -------------------------------------------------------------------- */
/* If this datum requires grid shifts, then apply it to geodetic */
/* coordinates. */
/* -------------------------------------------------------------------- */
if( srcdefn->datum_type == PJD_GRIDSHIFT )
{
pj_apply_gridshift( pj_param(srcdefn->params,"snadgrids").s, 0,
point_count, point_offset, x, y, z );
CHECK_RETURN;
src_a = SRS_WGS84_SEMIMAJOR;
src_es = 0.006694379990;
}
if( dstdefn->datum_type == PJD_GRIDSHIFT )
{
dst_a = SRS_WGS84_SEMIMAJOR;
dst_es = 0.006694379990;
}
/* ==================================================================== */
/* Do we need to go through geocentric coordinates? */
/* ==================================================================== */
if( src_es != dst_es || src_a != dst_a
|| srcdefn->datum_type == PJD_3PARAM
|| srcdefn->datum_type == PJD_7PARAM
|| dstdefn->datum_type == PJD_3PARAM
|| dstdefn->datum_type == PJD_7PARAM)
{
/* -------------------------------------------------------------------- */
/* Convert to geocentric coordinates. */
/* -------------------------------------------------------------------- */
pj_geodetic_to_geocentric( src_a, src_es,
point_count, point_offset, x, y, z );
CHECK_RETURN;
/* -------------------------------------------------------------------- */
/* Convert between datums. */
/* -------------------------------------------------------------------- */
if( srcdefn->datum_type == PJD_3PARAM
|| srcdefn->datum_type == PJD_7PARAM )
{
pj_geocentric_to_wgs84( srcdefn, point_count, point_offset,x,y,z);
CHECK_RETURN;
}
if( dstdefn->datum_type == PJD_3PARAM
|| dstdefn->datum_type == PJD_7PARAM )
{
pj_geocentric_from_wgs84( dstdefn, point_count,point_offset,x,y,z);
CHECK_RETURN;
}
/* -------------------------------------------------------------------- */
/* Convert back to geodetic coordinates. */
/* -------------------------------------------------------------------- */
pj_geocentric_to_geodetic( dst_a, dst_es,
point_count, point_offset, x, y, z );
CHECK_RETURN;
}
/* -------------------------------------------------------------------- */
/* Apply grid shift to destination if required. */
/* -------------------------------------------------------------------- */
if( dstdefn->datum_type == PJD_GRIDSHIFT )
{
pj_apply_gridshift( pj_param(dstdefn->params,"snadgrids").s, 1,
point_count, point_offset, x, y, z );
CHECK_RETURN;
}
if( z_is_temp )
pj_dalloc( z );
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -