import netCDF4
import numpy as np
import arcpy
arcpy.env.workspace = './shps/'
arcpy.env.overwriteOutput = True
ds = netCDF4.Dataset('./Wave_2.nc')
nodes_x = ds.variables['nodes_x'][:]
nodes_y = ds.variables['nodes_y'][:]
time_str = ds.variables['time_str'][:]
Hs = ds.variables['Hs'][:]
Hs = np.where(Hs == np.nan, np.nanmean(Hs), Hs)
Dir = ds.variables['Dir'][:]
Dir = np.where(Dir == np.nan, np.nanmean(Dir), Dir)
Per = ds.variables['Per'][:]
Per = np.where(Per == np.nan, np.nanmean(Per), Per)
for i in range(time_str.shape[0]):
time_str_i = ''.join(time_str[i].astype(np.str))
arcpy.CreateFeatureclass_management(arcpy.env.workspace, '{}.shp'.format(i), 'POINT',
spatial_reference=arcpy.SpatialReference(4326))
arcpy.AddField_management('{}.shp'.format(i), 'Hs', 'DOUBLE', field_precision=9, field_scale=7)
arcpy.AddField_management('{}.shp'.format(i), 'time_str', 'TEXT', field_length=20)
arcpy.AddField_management('{}.shp'.format(i), 'Dir', 'DOUBLE', field_precision=8, field_scale=3)
arcpy.AddField_management('{}.shp'.format(i), 'Per', 'DOUBLE', field_precision=8, field_scale=6)
cursor = arcpy.InsertCursor('{}.shp'.format(i))
for j in range(nodes_x.shape[0]):
lon = nodes_x[j]
lat = nodes_y[j]
# arcpy不支持np.float32的数据类型
Hsp = float(Hs[i, j])
Dirp = float(Dir[i, j])
Perp = float(Per[i, j])
row = cursor.newRow()
row.setValue('Hs', Hsp)
row.setValue('Dir', Dirp)
row.setValue('Per', Perp)
row.setValue('time_str', time_str_i)
row.shape = arcpy.Point(float(lon), float(lat))
cursor.insertRow(row)
del cursor
print('{}:{}.shp has been created!'.format(time_str_i, i))
print('ok!')
Arcpy创建shp文件
最新推荐文章于 2024-07-12 20:48:19 发布
本文介绍如何使用Python(结合netCDF4库)从海洋波浪数据文件中读取节点坐标、波高、方向和周期,并将数据逐时间步转化为GIS形状文件,以时间命名。每个文件包含时空特征的点数据,展示了数据处理和地理空间整合的过程。
摘要由CSDN通过智能技术生成