PostGIS创建Gis空间数据库,shp数据入库
2023-11-07 16:29 古兆洋 阅读(508) 评论(0) 编辑 收藏 举报转自:https://blog.csdn.net/An1090239782/article/details/123509645
postgresql 创建gis空间数据库,shp数据入库
https://blog.csdn.net/gis_zzu/article/details/91045052
https://www.jianshu.com/p/2c4f714c62b5
PostgreSQL创建空间数据库
1 postgresql创建空间数据库
1.1 创建普通数据库
1 CREATE DATABASE gisdbname;
1.2 数据库添加空间扩展
1 CREATE EXTENSION postgis; 2 CREATE EXTENSION postgis_topology; 3 CREATE EXTENSION fuzzystrmatch; 4 CREATE EXTENSION postgis_tiger_geocoder; 5 CREATE EXTENSION address_standardizer;
2 导入shp文件到数据库
2.1 shp数据准备
注意:postGIS导入shp数据路径不能含有中文,如果含有中文会报错,而且自己要知道自己的数据的坐标系
2.2 打开PostGIS 2.0 Shapefile and DBF Loader Exporter
弹出如下图:
2.3 连接数据库
2.4 选择要入库的shp文件
2.5 修改SRID的值,双击SRID的值,设置导入数据的坐标系
3 PostgreSQL创建空间数据库练习
3.1 创建数据库
3.2 添加postgis扩展,使之成为支持空间类型的空间数据库
1 create extension postgis
3.3 字段设置为geometry类型
3.4 插入空间数据
1 insert into test(id,shape) values(1,point(12.32232442,43.2324535)::geometry);
3.5 查询空间数据
1 insert into test(id,shape) values(1,point(12.32232442,43.2324535)::geometry);
4 Postgres空间数据库创建
4.1 扩展PG的空间数据库功能
1 -- Enable PostGIS (includes raster) 2 CREATE EXTENSION postgis; 3 -- Enable Topology 4 CREATE EXTENSION postgis_topology; 5 -- Enable PostGIS Advanced 3D 6 -- and other geoprocessing algorithms 7 -- sfcgal not available with all distributions 8 CREATE EXTENSION postgis_sfcgal; 9 -- fuzzy matching needed for Tiger 10 CREATE EXTENSION fuzzystrmatch; 11 -- rule based standardizer 12 CREATE EXTENSION address_standardizer; 13 -- example rule data set 14 CREATE EXTENSION address_standardizer_data_us; 15 -- Enable US Tiger Geocoder 16 CREATE EXTENSION postgis_tiger_geocoder;
5 Postgres根据字段数据创建空间字段
1 --添加空间字段 2 SELECT AddGeometryColumn ('GIS', '四至', 4326, 'POLYGON', 2); 3 4 --根据其他字段更新空间字段数据 5 update "GIS" b 6 set "四至"=ST_GeomFromText ('POLYGON((' || to_char(a."东经起",'999.9999') || to_char(a."北纬起",'999.9999') || ',' || to_char(a."东经止",'999.9999') || to_char(a."北纬起",'999.9999') || ',' || to_char(a."东经止",'999.9999') || to_char(a."北纬止",'999.9999') ||',' || to_char(a."东经起",'999.9999') || to_char(a."北纬止",'999.9999') || ',' || to_char(a."东经起",'999.9999') || to_char(a."北纬起",'999.9999') || '))',4326) 7 from "GIS" a 8 where b."ID"=a."ID" 9 10 --创建索引 11 CREATE INDEX shape_index_sz1 12 ON "GIS" 13 USING gist 14 (四至); 15 16 --查询与指定范围相交的多边形 17 SELECT * FROM "GIS" where 18 ST_Intersects( 19 ST_GeomFromText('POLYGON((86 44.1667,87.3333 44.1667,87.3333 45.1667,86 45.1667,86 44.1667))'), ST_GeomFromText(ST_AsText("四至")))
————————————————
版权声明:本文为CSDN博主「爱是与世界平行」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/An1090239782/article/details/123509645