首页 > 编程语言 >【GIS开发】osgEarth依赖库PROJ(Python)

【GIS开发】osgEarth依赖库PROJ(Python)

时间:2022-10-11 22:39:21浏览次数:79  
标签:crs GIS Python pyproj 编译 PROJ https sqlite3


文章目录

PROJ(Cartographic Projections and Coordinate Transformations Library),
地图投影的程序库,遵循X/MIT开源协议,用于坐标转换和坐标参考系统转换。

1、OSGeo/PROJ(C++)

​https://proj.org/​​​​https://github.com/OSGeo/PROJ​​​​https://download.osgeo.org/proj​

PROJ - Cartographic Projections and Coordinate Transformations Library

PROJ 是一款通用坐标转换软件,可将地理空间坐标从一个坐标参考系 (CRS) 转换为另一个坐标参考系 (CRS)。这包括制图投影和大地测量变换。PROJ 在X/MIT 开源许可下发布

PROJ 包括命令行应用程序,用于轻松转换来自文本文件或直接来自用户输入的坐标。除了命令行实用程序之外,PROJ 还公开了一个 应用程序编程接口,简称 API。API 允许开发人员在他们自己的软件中使用 PROJ 的功能,而无需自己实现类似的功能。

PROJ 最初只是作为一个制图应用程序,让用户可以使用许多不同的制图投影将大地坐标转换为投影坐标。多年来,随着需求变得明显,对基准转换的支持也慢慢进入 PROJ。今天,PROJ 支持一百多种不同的地图投影,并且可以使用除了最晦涩的大地测量技术之外的所有方法来转换基准面之间的坐标。

【GIS开发】osgEarth依赖库PROJ(Python)_gis


PROJ库的编译依赖库需求如下:

  • C99 compiler
  • C++11 compiler
  • CMake >= 3.9
  • SQLite3 >= 3.11: headers and library for target architecture, and sqlite3 executable for build architecture.
  • libtiff >= 4.0 (optional but recommended)
  • curl >= 7.29.0 (optional but recommended)

1.1 编译sqlite3

​https://sqlite.org/download.html​​ 这里静态编译SQLite库的64位版本。

【GIS开发】osgEarth依赖库PROJ(Python)_proj_02


将下载好的两个文件sqlite-amalgamation-3380100.zip、和sqlite-dll-win64-x64-3380100.zip解压到SQLite文件夹内,如下所示:

sqlite-amalgamation-3380100: shell.c 、sqlite3.c、sqlite3.h、sqlite3ext.h

sqlite-dll-win64-x64-3380100.zip:sqlite3.def、sqlite3.dll

【GIS开发】osgEarth依赖库PROJ(Python)_地球_03


【GIS开发】osgEarth依赖库PROJ(Python)_proj_04


打开VS2017,新建一个静态库工程,如下:

【GIS开发】osgEarth依赖库PROJ(Python)_地球_05


将下载的sqlite3的相关,添加到工程里,然后设置“不使用预编译头”,编译工程如下:

【GIS开发】osgEarth依赖库PROJ(Python)_瓦片_06


C/C++ --> 预处理器 --> 预处理器定义:添加预定义处理如下:

_USRDLL
SQLITE_ENABLE_RTREE
SQLITE_ENABLE_COLUMN_METADATA
SQLITE_ENABLE_FTS5
SQLITE_ENABLE_UNLOCK_NOTIFY

设置模块定义文件,链接器 --> 输入 --> 模块定义文件:

sqlite3.def

修改模块定义文件,在它内容最后面添加:sqlite3_unlock_notify
然后配置类型改为静态库lib。

1.2 编译libtiff

​http://download.osgeo.org/libtiff/​

【GIS开发】osgEarth依赖库PROJ(Python)_gis_07


【GIS开发】osgEarth依赖库PROJ(Python)_python_08

1.3 编译openssl

​https://www.openssl.org/​​​​https://github.com/openssl/openssl​

​http://slproweb.com/products/Win32OpenSSL.html​

【GIS开发】osgEarth依赖库PROJ(Python)_proj_09


openssl源码编译需要perl环境,配置比较麻烦。这里直接采用网上编译好的文件(http://slproweb.com/products/Win32OpenSSL.html),如下图所示:

【GIS开发】osgEarth依赖库PROJ(Python)_瓦片_10


下载安装之后,文件夹如下:

【GIS开发】osgEarth依赖库PROJ(Python)_proj_11

1.4 编译curl

​https://curl.se/download.html​​​​https://github.com/curl/curl​

【GIS开发】osgEarth依赖库PROJ(Python)_python_12

1.5 编译PROJ9

官网地址:

​http://download.osgeo.org/proj/​​ 从官网上下载PROJ最新代码:proj-9.0.0.tar

【GIS开发】osgEarth依赖库PROJ(Python)_proj_13


解压文件proj-9.0.0.tar后,可以看见cmake的脚本文件CMakeLists.txt,如下图:

【GIS开发】osgEarth依赖库PROJ(Python)_proj_14


于是我们使用cmake构建PROJ库的VS2017的工程文件,进而编译代码。

【GIS开发】osgEarth依赖库PROJ(Python)_python_15

2、pyproj(python库)

【GIS开发】osgEarth依赖库PROJ(Python)_proj_16

2.1 概述

Python interface to PROJ (cartographic projections and coordinate transformations library).

【GIS开发】osgEarth依赖库PROJ(Python)_瓦片_17

  • Minimum supported PROJ version is 8.0
  • Minimum supported Python version is 3.8

2.2 安装

​https://github.com/pyproj4/pyproj​

【GIS开发】osgEarth依赖库PROJ(Python)_proj_18

pip install

【GIS开发】osgEarth依赖库PROJ(Python)_地球_19


有时候通过pip官方直接安装第三方库会失败,使用国内镜像相对稳定些。

pipy国内镜像目前有:

http://pypi.douban.com/  豆瓣
http://pypi.hustunique.com/ 华中理工大学
http://pypi.sdutlinux.org/ 山东理工大学
http://pypi.mirrors.ustc.edu.cn/ 中国科学技术大学

阿里云:

pip install

豆瓣:

pip install

【GIS开发】osgEarth依赖库PROJ(Python)_地球_20

pip list

【GIS开发】osgEarth依赖库PROJ(Python)_gis_21

2.3 代码测试

  • Initializing CRS
from pyproj import CRS
crs = CRS.from_epsg(4326)
crs = CRS.from_string("epsg:4326")
crs = CRS.from_proj4("+proj=latlon")
crs = CRS.from_user_input(4326)

【GIS开发】osgEarth依赖库PROJ(Python)_地球_22

  • Transformations from CRS to CRS
from pyproj import CRS
crs_4326 = CRS.from_epsg(4326)
crs_26917 = CRS.from_epsg(26917)
print(crs_26917)

from pyproj import Transformer
transformer = Transformer.from_crs(crs_4326, crs_26917)
transformer = Transformer.from_crs(4326, 26917)
transformer = Transformer.from_crs("EPSG:4326", "EPSG:26917")
print(transformer)

【GIS开发】osgEarth依赖库PROJ(Python)_地球_23

  • Geodesic line length
from pyproj import Geod
lats = [-72.9, -71.9, -74.9, -74.3, -77.5, -77.4, -71.7, -65.9, -65.7,
-66.6, -66.9, -69.8, -70.0, -71.0, -77.3, -77.9, -74.7]
lons = [-74, -102, -102, -131, -163, 163, 172, 140, 113,
88, 59, 25, -4, -14, -33, -46, -61]
geod = Geod(ellps="WGS84")
total_length = geod.line_length(lons, lats)
print(f"{total_length:.3f}")

【GIS开发】osgEarth依赖库PROJ(Python)_python_24

  • Geodesic area
from pyproj import Geod
geod = Geod('+a=6378137 +f=0.0033528106647475126')
lats = [-72.9, -71.9, -74.9, -74.3, -77.5, -77.4, -71.7, -65.9, -65.7,
-66.6, -66.9, -69.8, -70.0, -71.0, -77.3, -77.9, -74.7]
lons = [-74, -102, -102, -131, -163, 163, 172, 140, 113,
88, 59, 25, -4, -14, -33, -46, -61]
poly_area, poly_perimeter = geod.polygon_area_perimeter(lons, lats)
print(f"{poly_area:.3f} {poly_perimeter:.3f}")

【GIS开发】osgEarth依赖库PROJ(Python)_地球_25

from pyproj import Proj
p = Proj(proj='utm',zone=10,ellps='WGS84', preserve_units=False)
x,y = p(-120.108, 34.36116666)
# lonlat to xy
print('x=%9.3f y=%11.3f' % (x,y))
# xy to lonlat
print('lon=%8.3f lat=%5.3f' % p(x,y,inverse=True))

lons = (-119.72,-118.40,-122.38)
lats = (36.77, 33.93, 37.62 )
x,y = p(lons, lats)
print('x: %9.3f %9.3f %9.3f' % x)
print('y: %9.3f %9.3f %9.3f' % y)

lons, lats = p(x, y, inverse=True) # inverse transform
print('lons: %8.3f %8.3f %8.3f' % lons)
print('lats: %8.3f %8.3f %8.3f' % lats)

p2 = Proj('+proj=utm +zone=10 +ellps=WGS84', preserve_units=False)
x,y = p2(-120.108, 34.36116666)
print('x=%9.3f y=%11.3f' % (x,y))

p = Proj("epsg:32667", preserve_units=False)
print('x=%12.3f y=%12.3f (meters)' % p(-114.057222, 51.045))

【GIS开发】osgEarth依赖库PROJ(Python)_gis_26

后记

如果你觉得该方法或代码有一点点用处,可以给作者点个赞;╮( ̄▽ ̄)╭
如果你感觉方法或代码不咋地//(ㄒoㄒ)//,就在评论处留言,作者继续改进。o_O???
谢谢各位童鞋们啦( ´ ▽´ )ノ ( ´ ▽´)っ!!!


标签:crs,GIS,Python,pyproj,编译,PROJ,https,sqlite3
From: https://blog.51cto.com/u_15800063/5748201

相关文章

  • Python 多进程 multiprocessing 使用示例
    multiprocessing文档:​​https://docs.python.org/zh-cn/3.10/library/multiprocessing.html​​​Process、Lock、Semaphore、Queue、Pipe、Pool:​​https://cuiqingcai.......
  • 【机器学习】Python常见用法汇总
    【机器学习】Python常见用法汇总作者简介:在校大学生一枚,华为云享专家,阿里云星级博主,腾云先锋(TDP)成员,云曦智划项目总负责人,全国高等学校计算机教学与产业实践资源建设专家委......
  • ArcGIS蜂巢六边形
    统计区域内的数量时,区域可以使用六边形。ArcMap10.4版本开始,提供了制作六边形的工具——生成细分曲面。本案例中,生成了黑龙江省范围内的细分曲面。Shape中的类型选择六边形......
  • Python 远程部署利器 Fabric2 模块
    fabric 官网英文文档:​​http://www.fabfile.org/​​《Python自动化运维技术与最佳实践》如何用Fabric实现无密码输入提示的远程自动部署:fabric实现远程操作和部署:简介F......
  • 一文了解 Python 中的对象比较方法 is 和 == 及其本质
    1Python中的对象ID我们在学习基础的时候没听说Python有C或C++中的指针啊,Python中指针是什么?先把指针这个概念放一放,一提到指针可能初学C和C++的人都害怕(本人......
  • 【GIS开发】OpenLayers入门学习(JavaScript库)
    1、简介官网地址:https://openlayers.org/源码地址:https://github.com/openlayers/openlayersOpenLayers是一个高性能、功能丰富的库,用于在Web上创建交互式地图。它......
  • python装饰器初级
    global与nonlocal1.global的作用:可以在局部空间里直接就该全局名称工具中的数据代码展示:name='moon'#设置了一个全局变量deffucn():name='god'#......
  • (Python)email 邮件发送
    """1.发送邮件的几个步骤:1)与邮件服务器建立会话连接2)指定用户的登录3)发送邮件2.一个标准邮件包含:1)邮件头:标题;收件人、发送人、抄送cc、密送bcc......
  • 【python】ERA5逐小时降水数据计算逐日降水
    自用简单方法参考代码:ERA5:Howtocalculatedailytotalprecipitation-CopernicusKnowledgeBase-ECMWFConfluenceWiki1、先从官网(ERA5-Landhour......
  • Python之斐波那契数列的实现
    1.斐波那契数列的概念斐波那契数列(Fibonaccisequence),又称黄金分割数列,因数学家莱昂纳多·斐波那契(LeonardoFibonacci)以兔子繁殖为例子而引入,故又称为“兔子数列”,指的是这......