博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
postgis的shp2pgsql使用
阅读量:6931 次
发布时间:2019-06-27

本文共 3236 字,大约阅读时间需要 10 分钟。

hot3.png

先来段python代码:

import osfrom cStringIO import StringIOfrom proj import db_opershape_base_dir = r'C:\Users\user_aaa\Desktop\compress\\'des_file_dir = 'D:\shp_sql\\'gis_frame = '4326'gis_char = 'CP874'shp_file = ''file_name_dic = {}for files in os.walk(shape_base_dir): #os.walk返回一个元组:files[0]——根目录 #files[1]——根目录包含的次级目录 #files[2]——包含的文件 file_name_set = {} if len(files[2]) > 0: #print files[0].split('\\')     print files[2]     for file_p in files[2]:         file_name_set[file_p[0:-4]] = ''     for file_p in file_name_set.keys():         if file_p in file_name_dic.keys():             #-a  追加 -c 新建             #-D  dump方式,处理大数据             #-s  坐标             #-w  字符集             shp_file = '"'+files[0]+'"'+'\\'+file_p             le_dir+'"'+files[0].split('\\')[-1]+file_p+'"'+'.sql')         else :             file_name_dic[file_p] = ''             shp_file = '"'+files[0]+'"'+'\\'+file_p             os.system('shp2pgsql -c -D -s '+gis_frame+' -W '+gis_char+' '+shp_file+' org_'+file_p+' >'+des_file_dir+'"'+files[0].split('\\')[-1]+file_p+'"'+'.sql')

再来postgis文档中,对shp2pgsql的解释:

(c|a|d|p) These are mutually exclusive options:

    -c Creates a new table and populates it from the shapefile. This is the default mode.
    -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.
    -d Drops the database table before creating a new table with the data in the Shape file.
    -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.
-? Display help screen.
-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.
-N <policy> NULL geometries handling policy (insert*,skip,abort)
-n -n Only import DBF file. If your data has no corresponding shapefile, it will automatically switch to this mode and load just
the dbf. So setting this flag is only needed if you have a full shapefile set, and you only want the attribute data and no
geometry.
-G Use geography type instead of geometry (requires lon/lat data) in WGS84 long lat (SRID=4326)

转载于:https://my.oschina.net/weiwubunengxiao/blog/181687

你可能感兴趣的文章
IOS--UINavigationBar修改背景色
查看>>
独辟蹊径系列 带着大家玩Android
查看>>
js art.dialog删除
查看>>
thinkphp模板中使用函数的方法
查看>>
Spring MVC学习(七)-------SpringMVC数据类型转换
查看>>
Android应用与开发环境
查看>>
找了个生男生女清宫图,感觉挺准的
查看>>
solrcloud 监控
查看>>
Kictstart Pxe 自动安装Linux系统
查看>>
Dilanova:时尚PPT模板下载-7度吧
查看>>
Mac 解决SSH登录服务器终端乱码
查看>>
Objective-C Json 使用
查看>>
Android7.0调用系统相机或相册时报错android.os.FileUriExposedException
查看>>
git add
查看>>
Java基础学习总结(24)——Java单元测试之JUnit4详解
查看>>
选择核心路由器时需要注意的七大性能指标
查看>>
数据结构(一)——数据结构简介
查看>>
小梅科普:微信公众平台深度开发第二季(JAVA版)
查看>>
STP理论01-背景及概念
查看>>
STP故障02-镜像问题
查看>>