gdal镜像集成和dockerfile使用

文章目录
  1. 1. gdal介绍
    1. 1.1. gdal命令使用
  2. 2. 官方gdal的dockerfile简介
  • Alpine based
    1. 1. Small: osgeo/gdal:alpine-small-latest
    2. 2. Normal: osgeo/gdal:alpine-normal-latest
  • Ubuntu based
    1. 1. Small: osgeo/gdal:ubuntu-small-latest
    2. 2. Full: osgeo/gdal:ubuntu-full-latest (aliased to osgeo/gdal)
    3. 3. 方法一osgeo/gdal:ubuntu-full基础上安装(unixODBC,mdbtools)
  • gdal介绍

    gdal的一个用c++语言编写的库,用于处理地理信息相关的数据包括转换,识别数据,格式化数据以及解析

    同时提供第三方语言的SDK包括python,java上述需要编译后使用 java是需要使用jni接口调用实现方法在window平台是DLL文件,在linux平台是so文件,最后需要使用和初始化服务。

    gdal命令使用

    1、ogrinfo

    orginfo –version

    ogrinfo –help

    2、ogr2ogr

    • ogr2ogr postgis转shp 并执行SQL

    ogr2ogr -f “ESRI Shapefile” file1.shp PG:”host=’192.168.7.11’ port=’5432’ dbname=’postgres’ user=’postgres’ password=’1111’” -sql “select * from like_fff_xztc” -dialect PostgreSQL

    • ogr2ogr postgis转化为shp文件且指定SQL执行

    ogr2ogr -f “ESRI Shapefile” /app/tmp/result_like_fff_xztc/result_like_fff_xztc.shp PG:”host=’192.168.7.11’ port=’5432’ dbname=’postgres’ user=’postgres’ password=’1111’” -sql “select fid,objectid,bsm,dlmc,qsdwmc,zldwmc,f_xzqhmc,f_year,f_month,partitionno,se_anno_cad_data,tbdlmj,ysdm,dlbm,qsxz,qsdwdm,zldwdm,xzgdlx,zldj,f_xzqhdm,f_diccode,f_fileid,tbbh,shape_length,shape_area,st_transForm(geom,4490) as geom from like_fff_xztc where ST_Intersects(geom,st_transform(st_geomFromText(‘MULTIPOLYGON(((112.973570327973 30.634569982416,112.973501343979 30.6344597898424,112.973423613701 30.6344687491655)))’,4490),4490))” -dialect PostgreSQL –config SHAPE_ENCODING ‘UTF-8’

    • ogr2ogr shp导入shp 命令

    ogr2ogr -f “PostgreSQL” PG:”host=’192.168.7.11’ port=’5432’ dbname=’test’ user=’postgres’ password=’1111’” C:\Users\Administrator\Desktop\ceshi\old\Water_region.shp -progress -nlt PROMOTE_TO_MULTI -lco GEOMETRY_NAME=geom -lco FID=fid -overwrite -nln ‘like_test_update’ -unsetFieldWidth –config SHAPE_ENCODING ‘utf-8’

    • ogr2ogr mdb导入shp命令

    ogr2ogr -f “PostgreSQL” PG:”host=’192.168.7.11’ port=’5432’ dbname=’test_new_app’ user=’postgres’ password=’1111’” /app/laohekou.mdb -progress -nlt PROMOTE_TO_MULTI -lco GEOMETRY_NAME=geom -lco FID=fid -overwrite -nln ‘test_mdb_001’

    • ogr2ogr shp转入postgis

    ogr2ogr -f “PostgreSQL” PG:”host=xxx user=xxx password=xxx dbname=cxxxhina” -nlt GEOMETRY 省级行政区.shp

    3、

    官方gdal的dockerfile简介

    gdal/docker at master · OSGeo/gdal

    Alpine based

    Alpine version:

    • 3.15 for 3.5
    • 3.16 for GDAL 3.6dev

    Small: osgeo/gdal:alpine-small-latest

    • Image size: ~ 59 MB
    • Raster drivers: ultrasmall + built-in + SQLite-based ones + network-based ones
    • Vector drivers: ultrasmall + built-in + most XML-based ones + network-based ones + PostgreSQL
    • Using internal libtiff and libgeotiff
    • External libraries enabled: ultrasmall + libexpat, libpq, libssl
    • No GDAL Python
    • Base PROJ grid package (http://download.osgeo.org/proj/proj-datumgrid-1.8.zip)
    • Overall licensing terms of the GDAL build: permissive (MIT, BSD style, Apache, etc..)

    See alpine-small/Dockerfile

    Normal: osgeo/gdal:alpine-normal-latest

    • Image size: ~ 277 MB
    • Raster drivers: small + netCDF, HDF5, BAG
    • Vector drivers: small + Spatialite, XLS
    • Using internal libtiff and libgeotiff
    • External libraries enabled: small + libgeos, libhdf5, libhdf5, libkea, libnetcdf, libfreexl, libspatialite, libxml2, libpoppler, openexr, libheif, libdeflate, libparquet
    • GDAL Python
    • Base PROJ grid package (http://download.osgeo.org/proj/proj-datumgrid-1.8.zip)
    • Overall licensing terms of the GDAL build: copy-left (GPL) + LGPL + permissive

    See alpine-normal/Dockerfile

    Ubuntu based

    Ubuntu version:

    • 20.04 for GDAL 3.4 and 3.5
    • 22.04 for GDAL 3.6dev

    Small: osgeo/gdal:ubuntu-small-latest

    • Image size: ~ 385 MB
    • Raster drivers: all built-in + JPEG + PNG + JP2OpenJPEG + WEBP +SQLite-based ones + network-based ones
    • Vector drivers: all built-in + XML based ones + SQLite-based ones + network-based ones + PostgreSQL
    • Using internal libtiff and libgeotiff
    • External libraries enabled: libsqlite3, libproj, libcurl, libjpeg, libpng, libwebp, libzstd, libexpat, libxerces-c, libpq, libssl, libgeos, libspatialite
    • GDAL Python (Python 3.8 for Ubuntu 20.04, Python 3.10 for Ubuntu 22.04)
    • Base PROJ grid package (http://download.osgeo.org/proj/proj-datumgrid-1.8.zip)
    • Overall licensing terms of the GDAL build: LGPL + permissive (MIT, BSD style, Apache, etc..)

    See ubuntu-small/Dockerfile

    Full: osgeo/gdal:ubuntu-full-latest (aliased to osgeo/gdal)

    • Image size: ~ 1.48 GB
    • Raster drivers: all based on almost all possible free and open-source dependencies
    • Vector drivers: all based on almost all possible free and open-source dependencies
    • Using internal libtiff and libgeotiff
    • External libraries enabled: small + libnetcdf, libhdf4, libhdf5, libtiledb, libkea, mongocxx 3.4, libspatialite, unixodbc, libxml2, libcfitsio, libmysqlclient, libkml, libpoppler, pdfium, openexr, libheif, libdeflate, libparquet
    • GDAL Python (Python 3.8 for Ubuntu 20.04, Python 3.10 for Ubuntu 22.04)
    • All PROJ grid packages (equivalent of latest of proj-data-X.zip from http://download.osgeo.org/proj/ at time of generation, > 500 MB)
    • Overall licensing terms of the GDAL build: copy-left (GPL) + LGPL + permissive

    点击进入后可以看到介绍,目前分别在两个linux发行版本上进行镜像文件创建,分别是Ubuntu,和alpine

    alpine是精简的服务目前不包括第三方的拓展目前在linux上不支持pgeo(改数据源可以读取mdb和其他格式数据的支持)

    ubuntu是完整版是提供全量的服务,支持pgeo

    介绍

    linux下面读取微软的软件word,Excel,PPT是有平台和驱动,但是像access这种个人数据库需要ODBC这个开源平台来读取这类数据,gdal在linux平台通过ODBC接口来读取access个人数据库,同时对数据解析,我们需要利用这个解析工具来读取数据被我们java读取,或者通过ogr2ogr命令来转换数据

    ODBC

    是linux平台的数据的解析

    ogrinfo 能识别

    odbcinst -j 表示odbc正确安装

    方法一osgeo/gdal:ubuntu-full基础上安装(unixODBC,mdbtools)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35

    FROM osgeo/gdal:ubuntu-full-3.0.4

    RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak
    # RUN echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse \ndeb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse\ndeb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse \ndeb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse \ndeb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse \ndeb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse \ndeb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse \ndeb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse \ndeb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse \ndeb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse\n' > /etc/apt/sources.list

    RUN apt-get update && cat /etc/apt/sources.list && apt-get -y --fix-missing --no-install-recommends install gcc make g++ bison flex gawk unixodbc-dev libgdal-java

    COPY ./unixODBC-2.3.11 /usr/unixODBC-2.3.11
    COPY ./mdbtools-1.0.0 /usr/mdbtools-1.0.0
    RUN chmod -R 777 /usr/unixODBC-2.3.11/ && chmod -R 777 /usr/mdbtools-1.0.0
    RUN cd /usr/unixODBC-2.3.11/ && ./configure --prefix=/usr/unixODBC-2.3.11 --includedir=/usr/include --libdir=/usr/lib --bindir=/usr/bin --sysconfdir=/etc
    RUN cd /usr/unixODBC-2.3.11/ && make
    RUN cd /usr/unixODBC-2.3.11/ && make install

    RUN cd /usr/mdbtools-1.0.0 && ./configure --with-unixodbc=/usr/unixODBC-2.3.11
    RUN cd /usr/mdbtools-1.0.0 && make
    RUN cd /usr/mdbtools-1.0.0 && make install

    # RUN echo "export LD_LIBRARY_PATH_LIKE=/usr/local/lib" >> /etc/profile && source /etc/profile

    COPY ./odbcinst.ini /etc
    ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
    RUN cp /usr/share/java/gdal.jar /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/
    # 指定时区
    ENV TZ=Asia/Shanghai
    # 设定工作目录
    WORKDIR /app
    ADD config /app/config
    ADD ./shp2pg.py /app/py/shp2pg.py
    # 声明端口
    EXPOSE 11002
    ADD uts-stg.jar /app/uts-stg.jar
    CMD ["java", "-Djava.security.egd=file:/dev/./urandom","-Djava.library.path=/usr/lib/jni", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 ", "-jar", "/app/uts-stg.jar"]