PostGIS安装与SHP数据入库(两种方法)

postgis:


解决无空间数据库模版方法:http://blog.sina.com.cn/s/blog_a453947f0102vuid.html
postgis导入数据、geoserver与udig加载数据:http://www.myexception.cn/open-source/1809904.html
SHP图层 导入PostgreSQL
首先安装postgis_2_2_pg95.exe:设定创建空间数据库(重要),一路Next,会安装一个postgis_22_sample实例(先安装PostgreSQL,后运行Stack
Bulider进行上述安装) 


方法1:
1)新建数据库(如myT),选择以postgis_22_sample/template_postgis为模板(新建空间数据库)

2)利用PostGIS Shapefile and DBF Loader导入shp数据(Options下设为GBK,否则中文导不进去;shp路径应简单且为全英文,否则报错;设定SRID,否则 uDig 不显示,一定要确定好坐标系对应的SRID的值,并且在Geoserver发布时“定义SRS”部分选择相同的坐标系



方法2:
使用cmd命令(PostgreSQL自带转换工具shp2pgsql)
1)

cd\,d:,cd D:\Program Files\PostgreSQL\9.5\bin
shp2pgsql -W GBK -s 2436 C:\Users\zoezoe\Desktop\newMap\雨量计\雨量监测器最新.shp
rainStation>
rainStation.sql
shp2pgsql -W GBK -s 2436 C:\Users\zoezoe\Desktop\newMap\原图层\主干路.shp
zhuganlu>
zhuganlu.sql

说明:

-W GBK 对中文进行编码
-s 2436 否则 uDig 不显示

2)将生成的sql文件内容粘贴至SQL编辑器运行即可


备注:
1)如若创建不了以postgis_22_sample为模板的空间数据库,则可以:
新建普通数据库,运行如下sql语句即可变为空间数据库,然后进行shp图层的导入工作:
CREATE EXTENSION postgis;
— Enable Topology
CREATE EXTENSION postgis_topology;
— fuzzy matching needed for Tiger
CREATE EXTENSION fuzzystrmatch;
— Enable US Tiger Geocoder
CREATE EXTENSION postgis_tiger_geocoder;
2)如若没有template_post模版,则可以:
SQL Shell(psql):连接到template1数据库后,执行
template1=#create database template_postgis with template=template1;
template1=#update pg_database set datistemplate=TRUE where datname=’template_postgis’;
template1=#\c template_postgis
template_postgis=#create language plpgsql;
template_postgis=#\i /opt/locale/share/postgis/lwpostgis.sql;
template_postgis=#\i /opt/locale/share/postgis/spatial_ref_sys.sql;
template_postgis=#GRANT ALL ON geometry_columns TO PUBLIC;
template_postgis=#GRANT ALL ON spatial_ref_sys TO PUBLIC;
template_postgis=#VACUUM FREEZE;
template_postgis=#\q
uDig中展示PostGIS数据(postgis与udig版本要相对应,shp数据要有坐标系)
Import——Other——Data——PostGIS

GeoServer发布PostGIS数据



uDig中展示PostGIS数据(postgis与udig版本要相对应,shp数据要有坐标系)

转载自:https://blog.csdn.net/u010534192/article/details/53422786

You may also like...