Proj.4 API 中文参考
ProjAPI
https://github.com/OSGeo/proj.4/wiki/ProjAPI
Tom Kralidis在2015年5月27日编辑此页·修订4
简介#
执行pj_init()
选择并初始化一个由它的参数决定参数的制图投影坐标系。argc
是argv
数组中的元素个数,argv
数组每个元素是单个投影的关键字参数(+proj arguments)。该列表中必须包含proj=投影
、地球半径
或椭圆参数
。如果初始化的投影是有效的,返回一个projPJ
结构体的地址,失败返回NULL。
pj_init_plus()
函数的工作方式与pj_init()
类似,但将投影参数定义在单个字符串内,且每个参数带有一个+
前缀。例如:+proj=utm +zone=11 +ellps=WGS84
。
pj_init()
的返回值用作投影正算(forward)或者投影逆算(inverse)中的proj
参数。投影计算中的参数结构体projUV
中的U
代表经度
或者x
,V
代表维度
或者y
,经度和维度都是以弧度单位的。如果操作失败,projUV
中的两个值都设置为HUGE_VAL
(在math.h中定义http://blog.csdn.net/poechant/article/details/7235594)。
注意:所有投影都有正算(forward)模式,但却不是都有逆算(inverse)模式。如果投影没有逆算模式,那么projPJ
中成员inv
将设置为NULL
。
pj_transform
函数用于转换两个坐标系统之间的点。除了投影坐标与地理坐标之间的转换,也可以进行基准面(datum)之间的转换。不同于pj_fwd()
和pj_inv()
,这里也允许坐标系定义参数projPJ*
是地理坐标(使用+proj=latlong
定义)。x
、y
、z
数组用于传入计算值,传出计算结果。该函数成功返回0
,失败返回错误号(查看inpj_errno
)。
由projection(projPJ)
关联的内存,可能需要使用pj_free()
释放。
示例#
The following program reads latitude and longitude values in decimal degress, performs Mercator projection with a Clarke 1866 ellipsoid and a 33° latitude of true scale and prints the projected cartesian values in meters:
下面程序读取十进制的经度和维度值,进行克拉克1866椭球正确范围33°维度的墨卡托投影计算,并打印米单位的笛卡尔坐标值。
北美大地基准维基百科
示例#
The following program reads latitude and longitude values in decimal degress, performs Mercator projection with a Clarke 1866 ellipsoid and a 33° latitude of true scale and prints the projected cartesian values in meters:
下面程序读取十进制的经度和维度值,进行克拉克1866椭球正确范围33°维度的墨卡托投影计算,并打印米单位的笛卡尔坐标值。
#include <proj_api.h> main(int argc, char **argv) { projPJ pj_merc, pj_latlong; double x, y; if (!(pj_merc = pj_init_plus("+proj=merc +ellps=clrk66 +lat_ts=33")) ) exit(1); if (!(pj_latlong = pj_init_plus("+proj=latlong +ellps=clrk66")) ) exit(1); while (scanf("%lf %lf", &x, &y) == 2) { x *= DEG_TO_RAD; y *= DEG_TO_RAD; p = pj_transform(pj_latlong, pj_merc, 1, 1, &x, &y, NULL ); printf("%.2f\t%.2f\n", x, y); } exit(0); }
在此程序中,输入-16 20.25将得到结果-1495284.21 1920596.79.
API函数#
基本API#
int pj_transform( projPJ srcdefn, projPJ dstdefn, long point_count, int point_offset, double *x, double *y, double *z );
转换点x/y/z
,从源坐标系统到目标坐标系统(更多信息).
projPJ pj_init_plus(const char *definition);
从字符串definition创建一个projPJ坐标系统对象(更多信息).
void pj_free( projPJ pj );
释放与pj
关联的所有资源.
高级函数#
int pj_is_latlong( projPJ pj );
返回TRUE表示是地理坐标系统(proj=latlong).
int pj_is_geocent( projPJ pj );
返回TRUE表示是地心坐标系统(proj=geocent).
char *pj_get_def( projPJ pj, int options);
返回PROJ.4初始化字符串,用于pj_init_plus()
可产生此坐标系统。但会尽可能多的扩大定义(例如添加:+init= 和 +datum= definitions).
projPJ pj_latlong_from_proj( projPJ pj_in );
返回一个新的坐标系定义。就是pj_in
内部的地理坐标(lat/long)系统.
环境函数#
void pj_set_finder( const char *(*new_finder)(const char *) );
Install a custom function for finding init and grid shift files.
安装用于查找init
和grid shift
(网格转换)文件的自定义函数。
void pj_set_searchpath ( int count, const char **path );
Set a list of directories to search for init and grid shift files.
设置一个目录列表去搜索init
和grid shift
文件。
void pj_deallocate_grids( void );
Frees all resources associated with loaded and cached datum shift grids.
释放加载和缓存的基准转换网格
关联的所有资源。
char *pj_strerrno( int );
Returns the error text associated with the passed in error code.
返回错误代码关联的错误文本。
int *pj_get_errno_ref( void );
Returns a pointer to the global pj_errno error variable.
返回全局的pj_errno
错误变量地址。
const char *pj_get_release( void );
Returns an internal string describing the release version.
返回描述发行版本的内部字符串。
废弃(过时)函数#
XY pj_fwd( LP lp, PJ *P );
LP pj_inv( XY xy, PJ *P );
projPJ pj_init(int argc, char **argv);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
2015-08-26 SNMP常用数据操作