1、下载gdal
https://www.gisinternals.com/archive.php 打开官方下载地址。
我下载的是3.8.5版本,MSVC2022,x64,release-1930-x64-gdal-3-8-5-mapserver-8-0-1,区别不大,自身系统比较低的下载低版本。
进入3.8.5的下载列表,我选择的第一个,编译后的二进制压缩包
解压压缩包,cmd进入命令行C:\Users\HIGHGO\Desktop\GIS\release-1930-x64-gdal-3-8-5-mapserver-8-0-1\bin\gdal\apps
查看支持格式.
ogr2ogr --formats
1.2、配置环境变量
添加PATH,3个
G:\release-1930-x64-gdal-3-8-5-mapserver-8-0-1\bin
G:\release-1930-x64-gdal-3-8-5-mapserver-8-0-1\bin\gdal\apps
G:\release-1930-x64-gdal-3-8-5-mapserver-8-0-1\bin\gdal-data
添加GDAL_DATA
G:\release-1930-x64-gdal-3-8-5-mapserver-8-0-1\bin\gdal-data
添加PROJ_LIB
G:\release-1930-x64-gdal-3-8-5-mapserver-8-0-1\bin\proj9\share
2、导入shp
#导入shp-linux
ogr2ogr -f "PostgreSQL" PG:"host='127.0.0.1' dbname='xxxxxx' user='xxxxx' password='xxxxx@123' port=5432" /opt/110m_physical/ne_110m_ocean.shp
#导入shp-win
ogr2ogr -f "PostgreSQL" PG:"host='xxxxxx' dbname='postgres' user='postgres' password='postgres' port=5432" C:\Users\HIGHGO\Desktop\GIS\data\NewYork\110m_physical\ne_110m_ocean.shp
3、导入xlsx
#导入xls-linux
ogr2ogr -f "PostgreSQL" PG:"host='127.0.0.1' dbname='highgo' user='sysdba' password='Test@123' port=5866" /opt/dltbxz_tqmj.xlsx
#导入xls-win
ogr2ogr -f "PostgreSQL" PG:"host='192.168.110.217' dbname='postgres' user='postgres' password='postgres' port=5432" C:\Users\HIGHGO\Desktop\GIS\data\dltbxz_tqmj.xlsx
4、导入gdb
#导入gdb-win
ogr2ogr -f "PostgreSQL" PG:"host='192.168.110.217' dbname='postgres' user='postgres' password='postgres' port=5432" C:\Users\HIGHGO\Desktop\GIS\data\test_highgo.gdb -nln chinasheng -overwrite chinasheng -progress -lco GEOMETRY_NAME=geom --config PG_USE_COPY YES
5、java调用(非最优方法)
注明:本方法只是快速使用,尽量不改变jdk目录结构,如果使用框架或更深入,请采用其他方法。
把gdal.jar和gdalalljni.dll拷贝到项目的lib下,然后配置maven
<dependency>
<gro