在JupyterHub for K8s的SuperMap iObjects Python簡單教程,演示在JupyterHub的Notebook基本操做。函數
在Notebook中依次輸入下面的內容,按shift+enter便可運行。測試
import iobjectspy as smo from iobjectspy import (aggregate_points, Unit) import os import sys
# 設置示例數據路徑 example_data_dir = '/home/jovyan/data/smdata/' # 設置結果輸出路徑 out_dir = os.path.join(example_data_dir, 'out') print("Output dir: ", out_dir) if not os.path.exists(out_dir): os.makedirs(out_dir) print("Makedir: ", out_dir) else: print("Existed dir: ", out_dir)
Output dir: /home/jovyan/data/smdata/out Existed dir: /home/jovyan/data/smdata/out
os.path.exists("/home/jovyan/data/smdata/out")
True
!ls -l ~/data/smdata/out
total 98 -rw-r--r-- 1 jovyan root 2396 Jul 8 09:18 out_aggregate_point.udb -rw-r--r-- 1 jovyan root 67584 Jul 8 09:18 out_aggregate_point.udd -rw-r--r-- 1 jovyan root 0 Jul 8 09:16 out_import_data_county_p.udb -rw-r--r-- 1 jovyan root 29696 Jul 8 09:16 out_import_data_county_p.udd
def progress_func(step_event): sys.stdout.write('%s,%s %%\n' % (step_event.title, step_event.message)) def aggregate_points_test(): """ 對點數據集 Town_P 進行點密度聚類,密度聚類的聚類點數目閾值爲4, 聚類半徑爲3 公里""" result = aggregate_points(os.path.join(example_data_dir, 'example_data.udb/Town_P'), 4, 3, Unit.KILOMETER, out_data=os.path.join(out_dir, 'out_aggregate_point.udb'), progress=progress_func) if result is not None: if isinstance(result, str): print('點密度聚類成功,結果面數據集爲 ' + result) else: print('點密度聚類成功,結果面數據集爲 ' + result.name) else: print('點密度聚類失敗')
aggregate_points_test()
按shift+enter便可運行。spa
稍微等待,能夠看到相應的輸出。.net
而後到目錄下去檢查輸出文件。code