10_栅格数据裁剪-iObjects Python with JupyterHub for K8s

10_栅格数据裁剪-iObjects Python with JupyterHub for K8s

使用Python对影像数据集进行裁剪操作,并输出为tif格式的文件,保存到指定的目录。
 
 
导入引用库:
from iobjectspy import (clip_raster,
                        Rectangle)

import os
import sys
设置输出路径:
# 设置示例数据路径
example_data_dir = '/home/jovyan/data/smdata/'

# 设置结果输出路径
out_dir = os.path.join(example_data_dir, 'out')
数据操作函数:
if not os.path.exists(out_dir):
    os.makedirs(out_dir)


def progress_func(step_event):
    sys.stdout.write('%s,%s %d %%\n' % (step_event.title, step_event.message, step_event.percent))


def clip_image_test():
    """裁剪影像数据集"""

    clip_region = Rectangle(875.5, 861.2, 1172.6, 520.9)
    result = clip_raster(os.path.join(example_data_dir, 'example_data.udb/seaport'), clip_region, True, False,
                         out_data=os.path.join(out_dir, 'out_clip_raster.tif'), progress=progress_func)

    if result is not None:
        print('裁剪影像数据成功,结果存储在 ' + result)
    else:
        print('裁剪影像数据失败')
执行影像裁剪操作:
if __name__ == '__main__':
    # 裁剪影像数据
    clip_image_test()
输出信息:
java -cp /opt/conda/lib/python3.6/site-packages/iobjectspy/_jsuperpy/jars/com.supermap.jsuperpy-9.1.1.jar com.supermap.jsuperpy.ApplicationExample 127.0.0.1 40153
[iObjectsPy]: Connection gateway-service successful, Python callback port bind 44913

裁剪影像数据成功,结果存储在 /home/jovyan/data/smdata/out/out_clip_raster.tif

转载于:https://my.oschina.net/u/2306127/blog/3100646

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值