使用OGR将Shapefile指转换成SQLite数据库文件

使用OGR将Shapefile指转换成SQLite数据库文件


发布日期: 1970-01-01 更新日期: 2016-10-27 编辑:zhangxiang 浏览次数: 6551

标签:

摘要: 最近进行全国1:10万外业手图的制作。因为是使用Mapnik进行制作 ,需要先将基础数据切成1:10万的Shapefile。这样导致结果生成大量的小文件,而且每个Shape文件还是由多个文件组成,就想将其转换成别的格式,方便存储与使用。 比较了一下,还是使用 ...

最近进行全国1:10万外业手图的制作。因为是使用Mapnik进行制作 ,需要先将基础数据切成1:10万的Shapefile。这样导致结果生成大量的小文件,而且每个Shape文件还是由多个文件组成,就想将其转换成别的格式,方便存储与使用。

比较了一下,还是使用 SQLite 文件比较方便。另外因为在进行标注的时候,直接使用 Shapefile 进行中文标注也存在乱码的问题,而使用 SQLite则不需要额外的处理。

下面是 ogr2ogr 转换成SQLite的用法,还是非常方便的。

Shapefile 转换成 SQLite:

ogr2ogr -f 'SQLite' out.db input.shp

注意上面的引号,这个在官方网站的说明中没有,但是在 Debian Wheezy中使用时需要,这可能是版本的问题。

另外,官网说可以使用 SPATIALITE=YES 关键词 ,但在Wheezy也不行。这个指明了是在版本 GDAL/OGR 1.10 之后可用。不过只是用来作为数据源提供作图的数据,用不到这个特性,所以没多细看。

使用上面的命令可以将单个的 Shapefile 转换成 SQLite 数据库文件,如果每个都这样转换的话,文件还是很多。幸好还有-append选项:

ogr2ogr -append out.db input2.shp

下面附上实际转换使用的 Shell 脚本。要转换的数据还是比较多的,大部分作图的时候也用不到。不过还是先存储起来比较好。

sptname=out.spt
rm -rf $sptname
ogr2ogr -f 'SQLite' $sptname atnlk_arc.shp
ogr2ogr -append $sptname atnlk_point.shp
ogr2ogr -append $sptname bount_arc.shp
ogr2ogr -append $sptname bount_label.shp
ogr2ogr -append $sptname bount_polygon.shp
ogr2ogr -append $sptname ggdln_arc.shp
ogr2ogr -append $sptname hydlk_arc.shp
ogr2ogr -append $sptname hydlk_point.shp
ogr2ogr -append $sptname hydnt_arc.shp
ogr2ogr -append $sptname hydnt_label.shp
ogr2ogr -append $sptname hydnt_polygon.shp
ogr2ogr -append $sptname hydnt_region_lake.shp
ogr2ogr -append $sptname hydnt_route_hyd.shp
ogr2ogr -append $sptname marsh2k.shp
ogr2ogr -append $sptname othnt_arc.shp
ogr2ogr -append $sptname othnt_label.shp
ogr2ogr -append $sptname othnt_polygon.shp
ogr2ogr -append $sptname othnt_region_cnty.shp
ogr2ogr -append $sptname othnt_region_dist.shp
ogr2ogr -append $sptname othnt_region_prov.shp
ogr2ogr -append $sptname railk_arc.shp
ogr2ogr -append $sptname railk_label.shp
ogr2ogr -append $sptname railk_point.shp
ogr2ogr -append $sptname railk_route_rai.shp
ogr2ogr -append $sptname respt_point.shp
ogr2ogr -append $sptname respy_arc.shp
ogr2ogr -append $sptname respy_label.shp
ogr2ogr -append $sptname respy_polygon.shp
ogr2ogr -append $sptname respy_region_popu.shp
ogr2ogr -append $sptname roalk_arc.shp
ogr2ogr -append $sptname roalk_point.shp
ogr2ogr -append $sptname roalk_route_hig.shp
ogr2ogr -append $sptname roalk_route_nat.shp
ogr2ogr -append $sptname terlk_arc.shp
ogr2ogr -append $sptname terlk_point.shp
ogr2ogr -append $sptname ternt_arc.shp
ogr2ogr -append $sptname ternt_label.shp
ogr2ogr -append $sptname ternt_polygon.shp

关注公众号
获取免费资源

随机推荐


Copyright © Since 2014. 开源地理空间基金会中文分会 吉ICP备05002032号

Powered by TorCMS

OSGeo 中国中心 邮件列表

问题讨论 : 要订阅或者退订列表,请点击 订阅

发言 : 请写信给: osgeo-china@lists.osgeo.org