来自NE的sqlite文件采用FDO-OGR格式,而不是本机空间几何。如果您愿意做一些体力劳动,这是一种转换为spatialite数据库的方法:
首先创建一个新的空的spacealite数据库(我称其为“ nev.sqlite”),然后在一个单独的终端会话中,打开带有spacealite的原始natural_earth_vector.sqlite。(我使用了较新的版本4.1。不确定是否可以与较旧的版本一起使用)。使用sqlite attach
函数连接到新的nev.sqlite表,并在新数据库中创建所需表的副本。
所以:
micha@Wheezy:~$ spatialite natural_earth_vector.sqlite
SpatiaLite version ..: 3.0.0-beta Supported Extensions:
- 'VirtualShape' [direct Shapefile access]
- 'VirtualDbf' [direct DBF access]
- 'VirtualXL' [direct XLS access]
- 'VirtualText' [direct CSV/TXT access]
- 'VirtualNetwork' [Dijkstra shortest path]
- 'RTree' [Spatial Index - R*Tree]
- 'MbrCache' [Spatial Index - MBR cache]
- 'VirtualSpatialIndex' [R*Tree metahandler]
- 'VirtualFDO' [FDO-OGR interoperability]
- 'SpatiaLite' [Spatial SQL - OGC]
PROJ.4 version ......: Rel. 4.7.1, 23 September 2009
GEOS version ........: 3.3.3-CAPI-1.7.4
SQLite version ......: 3.7.13
================ FDO-OGR Spatial Metadata detected ===============
.....
created VirtualFDO table 'fdo_ne_110m_geography_regions_points'
created VirtualFDO table 'fdo_ne_110m_geography_regions_polys'
created VirtualFDO table 'fdo_ne_110m_glaciated_areas'
created VirtualFDO table 'fdo_ne_110m_lakes'
created VirtualFDO table 'fdo_ne_110m_land'
created VirtualFDO table 'fdo_ne_110m_ocean'
created VirtualFDO table 'fdo_ne_110m_rivers_lake_centerlines'
Accessing these fdo_XX tables you can take full advantage of
FDO-OGR auto-wrapping facility
This allows you to access any specific FDO-OGR Geometry as if it
where native SpatiaLite ones in a completely transparent way
==================================================================
Enter ".help" for instructions
spatialite> attach "nev.sqlite" AS nev;
spatialite>
spatialite> CREATE TABLE nev.countries AS SELECT * from fdo_ne_10m_admin_0_countries;
spatialite> CREATE TABLE nev.populated_places AS SELECT * FROM fdo_ne_10m_populated_places;
spatialite> CREATE TABLE nev.railroads AS SELECT * FROM fdo_ne_10m_railroads;
spatialite> .q
*** FDO-OGR auto-wrapping shutdown done ***
所有行“创建的VirtualFDO ...”都表明Spatialite将数据识别为FDO格式,并为每个表创建了虚拟表,并将GEOMETRY转换为spaceiteite格式。我attach
进入新的“ nev”数据库,并为该CREATE TABLE ... AS SELECT * FROM ...
语句感兴趣的每一层创建新表。
现在,我重新切换到新的 spacespaceite数据库。并RecoverGeometryColumn()
在每个表上运行以获取具有所有元数据等的正确的spacealite数据库。请注意,FDO格式允许混合使用MULTI和SINGLE几何类型,因此我首先检查每个表包含哪些几何类型,并确保所有特征均正确。相同。我CastToMulti()
在必要的地方使用,就像这样:
micha@Wheezy:~/GIS/World/naturalearthdata.com$ spatialite nev.sqlite
SpatiaLite version ..: 4.1.1 Supported Extensions:
- 'VirtualShape' [direct Shapefile access]
- 'VirtualDbf' [direct DBF access]
- 'VirtualXL' [direct XLS access]
- 'VirtualText' [direct CSV/TXT access]
- 'VirtualNetwork' [Dijkstra shortest path]
- 'RTree' [Spatial Index - R*Tree]
- 'MbrCache' [Spatial Index - MBR cache]
- 'VirtualSpatialIndex' [R*Tree metahandler]
- 'VirtualFDO' [FDO-OGR interoperability]
- 'SpatiaLite' [Spatial SQL - OGC]
PROJ.4 version ......: Rel. 4.7.1, 23 September 2009
GEOS version ........: 3.3.3-CAPI-1.7.4
SQLite version ......: 3.7.13
Enter ".help" for instructions
SQLite version 3.7.13 2012-06-11 02:05:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
spatialite> .tables
SpatialIndex geometry_columns_auth spatialite_history
countries populated_places sql_statements_log
geom_cols_ref_sys railroads views_geometry_columns
geometry_columns spatial_ref_sys virts_geometry_columns
spatialite>
spatialite> SELECT GeometryType(GEOMETRY) FROM countries;
POLYGON
POLYGON
MULTIPOLYGON
MULTIPOLYGON
POLYGON
MULTIPOLYGON
POLYGON
MULTIPOLYGON
MULTIPOLYGON
.....
几何是混合的,因此将所有内容都设置为MULTI,然后执行RecoverGeometryColumn():
spatialite> UPDATE countries SET GEOMETRY=CastToMulti(GEOMETRY);
spatialite> SELECT RecoverGeometryColumn('countries','GEOMETRY',4326,'MULTIPOLYGON',2);
1
spatialite>
依此类推,为您需要的每个表。现在,这些表在QGIS中可用。