(二)选择postgis作为sharpmap的数据源

本文对比了Shapfile文件格式的局限性,并介绍了如何使用PostGIS来管理和查询空间数据,包括支持GIST空间索引及OGC标准的GIS对象和函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Shapfile文件为ESRI公司的文件存储格式,并且得到了业界广泛的支持。Shapfile格式是一种简单的,用非拓朴关系的形式存储几何位置和地理特征的属性信息的格式。虽然GeoServer采用Shapfile文件可以快速的创建网上地图服务,但它的缺点确很明显:

  1、Shapefile只支持一个图层,在实际中没有意义。

  2、直接保用SHP文件不安全,Shapfile文件很容易被病毒或其他原因误删除。

  3、GeoServer中用Shapfile文件作数据源的效率是很低的。

  4、Shapfile中的汉字GeoServer不能解析,会出现乱码。

  5、数据库可以方便的对地理信息进行查询。

 用PostGIS管理空间数据

         PostGIS支持GIST空间索引(附录1)、规范窗体,能很大的提高处理效率。

         OGC格式只提供二维的几何体,且相关联的SRID从未深入的用于输入输出请求,PostGIS支持OpenGIS组织"Simple Features for SQL"规范指定的所有GIS对象和函数,并进行了扩展,格式是EWKB、EWKT,其中增加了对3DZ,3DM和4D 坐标系的支持(当然三维、四维数据的OGC标准还未完全制定),深入引进了SRID信息。

  空间数据表结构:PostGIS中存在两个必需的元数据表格, SPATIAL_REF_SYS(空间参考表格) 和 GEOMETRY_COLUMNS(几何体属性列),两个表用于存储空间数据库使用的坐标系统数字ID和文本描述。

  PostGIS的shp2pgsql命令可以将Shapfile直接导入到数据库中也可以导出为SQL文件,推荐先导出为SQL文件再将此文件在SQL运行窗口中执行可将数据导入数据库。代码如下:


Shapfile到SQL语句:

  shp2pgsql    路径\shp数据文件名 新建的数据表名 > 路径\SQL文件名.sql

Shapfile直接入库:

  shp2pgsql -c 路径\shp数据文件名 新建的数据表名 数据库名|psql -d 数据库名


举例说明:

  如将一Shapfile文件“c:\road.shp”导入到数据表“road”中,数据库为“sjzmap”。

  1、运行“命令提示符”。

  2、切换至PostgreSQL数据库安装目录中的bin目录下。

  3、执行此目录下的shp2pgsql命令:“shp2pgsql c:\road.shp road > c:\road.sql”。

  4、如将此文件直接导入数据库(不推荐):“shp2pgsql -c c:\road.shp road sjzmap | psql -d sjzmap”。

      5、使用pgAdmin3 选择数据库,再导入表。

注:

-d

Drops the database table before creating a new table with the data in the Shape file.

-a

Appends data from the Shape file into the database table. Note that to use this option to load multiple files, the files must have the same attributes and same data types.

-c

Creates a new table and populates it from the Shape file. This is the default mode.

-p

Only produces the table creation SQL code, without adding any actual data. This can be used if you need to completely separate the table creation and data loading steps.

-D

Use the PostgreSQL "dump" format for the output data. This can be combined with -a, -c and -d. It is much faster to load than the default "insert" SQL format. Use this for very large data sets.

-s <SRID>

Creates and populates the geometry tables with the specified SRID.

-k

Keep identifiers' case (column, schema and attributes). Note that attributes in Shapefile are all UPPERCASE.

-i

Coerce all integers to standard 32-bit integers, do not create 64-bit bigints, even if the DBF header signature appears to warrant it.

-I

Create a GiST index on the geometry column.

-w

Output WKT format, for use with older (0.x) versions of PostGIS. Note that this will introduce coordinate drifts and will drop M values from shapefiles.

-W <encoding>

Specify encoding of the input data (dbf file). When used, all attributes of the dbf are converted from the specified encoding to UTF8. The resulting SQL output will contain a SET CLIENT_ENCODING to UTF8 command, so that the backend will be able to reconvert from UTF8 to whatever encoding the database is configured to use internally.

转载于:https://www.cnblogs.com/goodyao/archive/2008/08/14/1268006.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值