利用shell命令合并分县土地利用数据为一个shape File

为了制图服务的需求,需要将分县的土地利用arcinfo coverage数据合并为一个shape File。
用ogrinfo查看一个县的数据简要信息:
ogrinfo -so id04632323 PAL
Had to open data source read-only.
INFO: Open of `id04632323'
using driver `AVCBin' successful.

Layer name: PAL
Geometry: Polygon
Feature Count: 4065
Extent: (-831725.500000, 2525475.000000) - (-704241.375000, 2614980.250000)
Layer SRS WKT:
PROJCS["unnamed",
GEOGCS["Unknown datum based upon the Krassowsky 1940 ellipsoid",
DATUM["Not_specified_based_on_Krassowsky_1940_ellipsoid",
SPHEROID["Krassowsky 1940",6378245,298.3,
AUTHORITY["EPSG","7024"]],
AUTHORITY["EPSG","6024"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4024"]],
PROJECTION["Albers_Conic_Equal_Area"],
PARAMETER["standard_parallel_1",25],
PARAMETER["standard_parallel_2",47],
PARAMETER["latitude_of_center",12],
PARAMETER["longitude_of_center",110],
PARAMETER["false_easting",0],
PARAMETER["false_northing",0],
UNIT["METERS",1]]
ArcIds: IntegerList (0.0)
AREA: Real (12.3)
PERIMETER: Real (12.3)
ID04632323#: Integer (5.0)
ID04632323-ID: Integer (5.0)

用QGIS打开后,可以发现其ID04632323-ID字段是土地利用的分类代码。而要将这些分县的数据合并,则需要利用ogr2ogr来合并生成。
主要问题:
1. 需要重命名字段,如将这个分类代码重命名为一个共用的名称,比如code。
2. 目录名和分类代码字段名相关,但需要进行大小写转换。
3. 还需要将每个县的目录名称保存到对应的数据库中。

在bash中,大小写转换可以用这个函数,将变量$i转换为大写:
${i^^}

ogr2ogr可以用sql选项来提取不同的字段并重命名:
select AREA as area,PERIMETER AS perimeter,ID04632323-ID as code from PAL
但在测试中,发现其不认这种写法,需要将其用单引号来括起来:
select AREA as area,PERIMETER AS perimeter,‘ID04632323-ID’ as code from PAL

而目录名称也可以通过变量的方式传递到sql中来。

最终命令脚本,要注意其中的引号和转义:
for i in id*;do
ogr2ogr -update -append -sql "select AREA as area,PERIMETER AS perimeter,'${i^^}-ID' as code,\"$i\" as county FROM PAL" landuse.shp $i;
done

Compile & install GRASS 6.4 on ubuntu intrepid

首先,需要自己重新编译GDAL,目前UBUNTU源里的GDAL有BUG。
然后,从svn中下载grass 6.4:

svn co https://svn.osgeo.org/grass/grass/branches/develbranch_6 grass-6.4
cd grass-6.4/debian
svn://svn.debian.org/pkg-grass/packages/grass/branches/6.4/debian debiangis
mv debiangis/* .

目前,这个DEB控制还有点小问题,需要自己作些修改:

nano grass.conf

把路径修改为:

/usr/lib/grass64/lib

然后修改grass-preview-doc.links,修改为:

usr/share/doc/grass-preview-doc/html usr/lib/grass64/docs/html

还需要连接一个so库:

locate _gdi_.so

我的机器上有两个地址,一个是python 2.4,一个是python 2.5,我选择了python 2.5的地址,然后作了个连接:

sudo ln -s /usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_gdi_.so /usr/loca/lib/libgdi.so

然后就可以编译了:

debuild binary

然后就可以安装了,你若不想安装,可以使用我已经编译好的,(添加我自己的源):

http://ubuntu.westgis.ac.cn/ubuntu

然后sudo aptitude install grass-preview就可以了。

如要安装文档:

sudo aptitude install grass-preview-doc
sudo mkdir /usr/lib/grass64/docs
sudo ln -s /usr/share/doc/grass-preview-doc/html /usr/lib/grass64/docs/

gdal.sh自动更新安装

为了gdal更新的方便,写了一个简单的shell脚本:

cd /root/gdal/
cvs update
./configure –with-hdf4 –with-netcdf –with-pg=/usr/local/pgsql/bin/pg_config –with-geos –with-libtiff=internal –with-static-proj4 –with-grass=/usr/local/grass-5.7.cvs
make clean
make
make install