使用zmap plus ascii网格格式读取和写入地图网格数据的python库

zmapio的Python项目详细描述


要安装:

$ pip install zmapio

zmapio的基本用法

importmatplotlib.pyplotaspltimportnumpyasnpfromzmapioimportZMAPGrid
%matplotlibinline

读取zmap文件:

z_file=ZMAPGrid('./examples/NSLCU.dat')

访问评论标题:

forcinz_file.comments:print(c)
Landmark Zmap grid file name:   .DATANSLCU.dat
Created/converted by Oasis Montaj, Geosoft Inc.

绘制网格数据:

z_file.plot()
https://raw.githubusercontent.com/abduhbm/zmapio/master/_static/output_9_1.png

行和列的计数:

z_file.no_cols,z_file.no_rows
(435, 208)

Z值形状:

z_file.z_values.shape
(208, 435)

导出到csv文件:

z_file.to_csv('./output/output.csv')
head ./output/output.csv
-630000.0,2621000.0,-16481.9570313
-630000.0,2618000.0,-16283.9033203
-630000.0,2615000.0,-16081.5751953
-630000.0,2612000.0,-15856.7861328
-630000.0,2609000.0,-15583.7167969
-630000.0,2606000.0,-15255.734375
-630000.0,2603000.0,-14869.3769531
-630000.0,2600000.0,-14426.1513672
-630000.0,2597000.0,-13915.8769531
-630000.0,2594000.0,-13340.4677734

导出到WKT文件:

z_file.to_wkt('./output/output.wkt')

导出到geojson文件:

z_file.to_geojson('./output/output.json')

导出到熊猫数据帧:

df=z_file.to_dataframe()
df.Z.describe()
count    90480.000000
mean     -5244.434235
std       4692.845490
min     -16691.371094
25%     -10250.590088
50%      -4003.433105
75%      -1320.896881
max       2084.417969
Name: Z, dtype: float64

以每行3个节点的格式编写新的zmap文件:

z_file.write('./output/test.zmap',nodes_per_line=3)
head ./output/test.zmap
! Landmark Zmap grid file name:   .DATANSLCU.dat
! Created/converted by Oasis Montaj, Geosoft Inc.
@.DATANSLCU.dat, GRID, 3
20, 1e+30, , 7, 1
208, 435, -630000.0, 672000.0, 2000000.0, 2621000.0
0.0, 0.0, 0.0
@
      -16481.9570313      -16283.9033203      -16081.5751953
      -15856.7861328      -15583.7167969      -15255.7343750
      -14869.3769531      -14426.1513672      -13915.8769531

从字符串创建zmap对象:

z_text="""
!
! File created by DMBTools2.GridFileFormats.ZmapPlusFile
!
@GRID FILE, GRID, 4
20, -9999.0000000, , 7, 1
6, 4, 0, 200, 0, 300
0.0, 0.0, 0.0
@
       -9999.0000000       -9999.0000000           3.0000000          32.0000000
          88.0000000          13.0000000
       -9999.0000000          20.0000000           8.0000000          42.0000000
          75.0000000           5.0000000
           5.0000000         100.0000000          35.0000000          50.0000000
          27.0000000           1.0000000
           2.0000000          36.0000000          10.0000000           6.0000000
           9.0000000       -9999.0000000
"""z_t=ZMAPGrid(z_text)z_t.plot()
https://raw.githubusercontent.com/abduhbm/zmapio/master/_static/output_28_1.png

使用matplotlib添加ColorBar和ColorMap:

z_obj=ZMAPGrid('./examples/NStopo.dat')fig=plt.figure(figsize=(12,6))z_obj.plot(cmap='jet')plt.colorbar()
https://raw.githubusercontent.com/abduhbm/zmapio/master/_static/output_30_1.png

从具有形状的2d numpy数组创建新的zmap对象(无列, 没有行:

z_val=z_obj.z_values.swapaxes(0,1)print('Z-values shape: ',z_val.shape)new_zgrid=ZMAPGrid(z_values=z_val,min_x=-630000.0000,max_x=672000.0000,min_y=2000000.0000,max_y=2621000.0000)
Z-values shape:  (435, 208)
new_zgrid.plot(cmap='gist_earth')
https://raw.githubusercontent.com/abduhbm/zmapio/master/_static/output_33_1.png

自定义写入zmap文件:

new_zgrid.comments=['this is','a test']new_zgrid.nodes_per_line=4new_zgrid.field_width=15new_zgrid.decimal_places=3new_zgrid.name='test'new_zgrid.write('./output/new_z.dat')
head ./output/new_z.dat
!this is
!a test
@test, GRID, 4
15, 1e+30, , 3, 1
208, 435, -630000.0, 672000.0, 2000000.0, 2621000.0
0.0, 0.0, 0.0
@
        -67.214        -67.570        -67.147        -69.081
        -73.181        -74.308        -72.766        -72.034
        -70.514        -68.555        -66.195        -62.776

参考文献

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在安卓 studio中使用调用jaxws web服务的jar文件   java双时间模拟时钟不打印两个不同的时间   java Jackson反序列化处理不带字段的生成值   多线程在java同步中读锁的目的是什么   为什么java中有这么多获取日期时间的方法?   java从listview中的TextView获取数据   java是否可以定义如何对枚举进行(反)序列化以在枚举内持久化?   Java:异常处理我的catch()有问题   VMWare java SDK:可用的PerfMetricID何时不报告数据?   exec在Java中执行命令而不重定向输出   java使用SpringXML配置实现观察者模式?   java在竹笔平板电脑中使用JPen