利用ogr2ogr从PostGIS中导出/导入Tab/Dxf/Geojson等格式数据
ogr2ogr Demo Command
先查看下当前gdal支持的全部格式,部分gdal版本可能不支持PostGIS。
如出现PostgreSQL
表名支持。
#全部支持的格式
ogrinfo --formats | sort
#AVCBin -vector- (rov): Arc/Info Binary Coverage
#AVCE00 -vector- (rov): Arc/Info E00 (ASCII) Coverage
#BAG -raster,multidimensional raster,vector- (rw+v): Bathymetry Attributed Grid
#CAD -raster,vector- (rovs): AutoCAD Driver
#Carto -vector- (rw+): Carto
#CSV -vector- (rw+v): Comma Separated Value (.csv)
#CSW -vector- (ro): OGC CSW (Catalog Service for the Web)
#DGN -vector- (rw+v): Microstation DGN
#DXF -vector- (rw+v): AutoCAD DXF
#EDIGEO -vector- (rov): French EDIGEO exchange format
#EEDA -vector- (ro): Earth Engine Data API
#Elasticsearch -vector- (rw+): Elastic Search
#ESRI Shapefile -vector- (rw+v): ESRI Shapefile
#ESRIJSON -vector- (rov): ESRIJSON
#FITS -raster,vector- (rw+): Flexible Image Transport System
#FlatGeobuf -vector- (rw+v): FlatGeobuf
#Geoconcept -vector- (rw+v): Geoconcept
……
进入ogr2ogr目录/测试,应当配置环境变量
#你的gdal目录
cd "C:\Program Files\GDAL"
导出
导出数据 geojson
./ogr2ogr.exe -f "GeoJSON" ~your-pathresult.geojson PG:"host=localhost dbname=yourdbName user=yourpostgres password=yourpwd port=yourport" "your_tablename(geom)"
导出数据 tab
./ogr2ogr.exe -f "MapInfo File" ~your-pathresult.tab PG:"host=localhost dbname=yourdbName user=yourpostgres password=yourpwd port=yourport" "your_tablename(geom)"
导出数据 SQLite
./ogr2ogr.exe -f "SQLite" ~your-pathresult.db PG:"host=localhost dbname=yourdbName user=yourpostgres password=yourpwd port=yourport" "your_tablename(geom)"
导出数据 DXF
./ogr2ogr.exe -f "DXF" ~your-pathresult.dxf PG:"host=localhost dbname=yourdbName user=yourpostgres password=yourpwd port=yourport" "your_tablename(geom)"
导入
geojson 导入数据 -插入
./ogr2ogr.exe -f "yourpostgresQL" PG:"host=localhost dbname=yourdbName user=yourpostgres password=yourpwd port=yourport" ~your-pathresult.json -nln target_table -append
geojson 导入数据 -新、覆盖
./ogr2ogr.exe -f "yourpostgresQL" PG:"host=localhost dbname=yourdbName user=yourpostgres password=yourpwd port=yourport" ~your-pathresult.json -nln target_table -overwrite