GIScript是一个开放的地理空间心处理与分析Python框架,GIS内核采用SuperMap UGC封装,集成多种开源软件,也可以使用其它的商业软件引擎。
by wangerqi@supermap.com, 2016-05-03。
GIScript的安装包括**系统库的设置**、**UGC Runtime设置**和**Python库**的设置,通过编写一个启动脚本,可以在给定环境下载入相应的运行库的路径。
cd /home/supermap/GISpark
git clone https://github.com/supergis/GIScriptLib.git
由于GIScript的几个编译库版本较新,在默认使用系统老版本库时部分函数找不到会引起调用失败,因此需要将这几个的系统调用指向到GIScript编译使用的的新版本。在Ubuntu上,具体操作包括:
cd ~/anaconda3/envs/GISpark/lib
mv libstdc++.so libstdc++.so.x
mv libstdc++.so.6 libstdc++.so.6.x
mv libsqlite3.so.0 libsqlite3.so.0.x
mv libsqlite3.so libsqlite3.so.x
mv libgomp.so.1.0.0 libgomp.so.1.0.0.x
mv libgomp.so.1 libgomp.so.1.x
mv libgomp.so libgomp.so.x
GIScript的Python封装库,默认存放在系统目录:/usr/lib/python3/dist-packages/PyUGC
使用Anaconda时,存在相应的env的目录下,如:[/home/supermap/Anaconda3]/envs/GISpark/lib/python3.5/site-packages
ln -s -f /home/supermap/GISpark/GIScriptLib/lib-giscript-x86-linux64/lib ~/anaconda3/envs/GISpark/lib/python3.5/site-packages/PyUGC
cd /home/supermap/GISpark/GIScriptLib
cp -r lib-giscript-x86-linux64/lib ~/anaconda3/envs/GISpark/lib/python3.5/site-packages/PyUGC
echo "Config GIScript2016..."
# 使用GIScript2015的开发工程目录,配置示例:
# export SUPERMAP_HOME=/home/supermap/GIScript/GIScript2015/Linux64-gcc4.9
# 使用GIScriptLib运行时动态库,配置如下:
export SUPERMAP_HOME=/home/supermap/GISpark/GIScriptLib/lib-giscript-x86-linux64
export LD_LIBRARY_PATH=$SUPERMAP_HOME/Bin:$LD_LIBRARY_PATH
echo "Config: LD_LIBRARY_PATH="$LD_LIBRARY_PATH
echo "Activate conda enviroment GISpark ..."
source activate GISpark
echo "Config GIScript 2016 for Jupyter ..."
export SUPERMAP_HOME=/home/supermap/GISpark/GIScriptLib/lib-giscript-x86-linux64
export LD_LIBRARY_PATH=$SUPERMAP_HOME/bin:/usr/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATH
echo "Config: LD_LIBRARY_PATH="$LD_LIBRARY_PATH
echo "Start Jupyter notebook"
jupyter notebook
sudo chmod +x start.sh
./start.sh
默认配置下,将会自动打开浏览器,就可以开始使用Jupyter Notebook并调用GIScript的库了。
如果通过服务器使用,需要使用`jupyter notebook --generate-config`创建配置文件,然后进去修改参数,这里不再详述。
In [1]:
from PyUGC import *
from PyUGC.Stream import UGC
from PyUGC.Base import OGDC
from PyUGC import Engine
from PyUGC import FileParser
from PyUGC import DataExchange
import datasource
In [9]:
#help(UGC)
#help(OGDC)
#help(datasource)
In [2]:
import os
basepath = os.path.join(os.getcwd(),"../data")
print("Data path: ", basepath)
file1 = basepath + u"/Shape/countries.shp"
print("Data file: ", file1)
file2 = basepath + u"/Raster/astronaut(CMYK)_32.tif"
print("Data file: ", file2)
file3 = basepath + u"/Grid/grid_Int32.grd"
print("Data file: ", file3)
datapath_out = basepath + u"/GIScript_Test.udb"
print("Output UDB: ",datapath_out)
In [3]:
def Import_Test():
print("Export to UDB: ",datapath_out)
ds = datasource.CreateDatasource(UGC.UDB,datapath_out)
datasource.ImportVector(file1,ds)
datasource.ImportRaster(file2,ds)
datasource.ImportGrid(file3,ds)
ds.Close()
del ds
print("Finished.")
In [4]:
try:
Import_Test()
except Exception as ex:
print(ex)
In [49]:
!ls -l -h ../data/GIScript_Test.*
In [46]:
!rm ../data/GIScript_Test.*
In [41]:
!ls -l -h ../data/GIScript_Test.*
In [ ]: