gdal.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. .. _data_gdal:
  2. GDAL Image Formats
  3. ==================
  4. GeoServer can leverage the `ImageI/O-Ext <https://github.com/geosolutions-it/imageio-ext/wiki>`__ GDAL libraries to read selected coverage formats. `GDAL <http://www.gdal.org>`__ is able to read many formats, but for the moment GeoServer supports only a few general interest formats and those that can be legally redistributed and operated in an open source server.
  5. The following image formats can be read by GeoServer using GDAL:
  6. * `DTED <https://www.gdal.org/frmt_dted.html>`__: Military Elevation Data (:file:`.dt0`, :file:`.dt1`, :file:`.dt2`)
  7. * `EHdr <https://gdal.org/drivers/raster/ehdr.html>`__: ESRI :file:`.hdr` Labelled:
  8. * `ENVI <https://gdal.org/drivers/raster/envi.html>`__: ENVI :file:`.hdr` Labelled Raster
  9. * `HFA <https://www.gdal.org/frmt_hfa.html>`__: Erdas Imagine (:file:`.img`)
  10. * `JP2MrSID <https://www.gdal.org/frmt_jp2mrsid.html>`__: JPEG2000 (:file:`.jp2`, :file:`.j2k`)
  11. * `MrSID <https://www.gdal.org/frmt_mrsid.html>`__: Multi-resolution Seamless Image Database
  12. * `NITF <https://www.gdal.org/frmt_nitf.html>`__: National Imagery Transmission Format
  13. * `ECW <https://www.gdal.org/frmt_ecw.html>`__: ERDAS Compressed Wavelets (:file:`.ecw)`:
  14. * `JP2ECW <https://www.gdal.org/frmt_jp2ecw.html>`__: JPEG2000 (:file:`.jp2`, :file:`.j2k`)
  15. * `AIG <https://gdal.org/drivers/raster/aig.html>`__: Arc/Info Binary Grid
  16. * `JP2KAK <https://www.gdal.org/frmt_jp2kak.html>`__: JPEG2000 (:file:`.jp2`, :file:`.j2k`)
  17. Installing GDAL extension
  18. -------------------------
  19. From GeoServer version 2.2.x, GDAL must be installed as an extension. To install it:
  20. #. Visit the :website:`website download <download>` page, locate your release, and download: :download_extension:`gdal`
  21. .. warning:: Ensure to match plugin (example |release| above) version to the version of the GeoServer instance.
  22. * The download link for :guilabel:`GDAL` will be in the :guilabel:`Extensions` section under :guilabel:`Coverage Format`.
  23. .. figure:: images/downloadextension.png
  24. :align: center
  25. * Extract the files in this archive to the :file:`WEB-INF/lib` directory of your GeoServer installation. On Windows You may be prompted for confirmation to overwrite existing files, confirm the replacement of the files
  26. .. figure:: images/overwrite.png
  27. :align: center
  28. Moreover, in order for GeoServer to leverage these libraries, the GDAL (binary) libraries must be installed through your host system's OS. Once they are installed, GeoServer will be able to recognize GDAL data types. See below for more information.
  29. Installing GDAL native libraries
  30. ++++++++++++++++++++++++++++++++
  31. Starting with GeoServer 2.21.x the imageio-ext plugin is tested with GDAL version 3.x (tested in particular with 3.2.x and 3.4.x).
  32. The imageio-ext plugin is tested with the GDAL 3.2 SWIG bindings, included in the extension download as :file:`gdal-3.2.0.jar`.
  33. In case of version mismatch
  34. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  35. We recommend matching the version :file:`gdal` jar to the version of gdal available in your environment:
  36. .. code-block:: console
  37. gdalinfo --version
  38. ::
  39. GDAL 3.4.1, released 2021/12/27
  40. If you are using a version of GDAL that does not match the one expected by GeoServer, you can go and replace the :file:`gdal-3.2.0.jar` file with the equivalent java binding jar (typically named either :file:`gdal-<version>.jar`) included with your GDAL version:
  41. * If your GDAL version does not include a bindings jar, it was probably not compiled with the java bindings and will not work with GeoServer.
  42. * You may also search for the correct :file:`gdal` jar here: https://search.maven.org/artifact/org.gdal/gdal
  43. Windows packages and setup
  44. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  45. For Windows, `gisinternals.com <http://www.gisinternals.com/release.php>`_ provides complete packages,
  46. with Java bindings support, in the ``release-<version>-GDAL-<version>-mapserver-<version>.zip`` packages (the GDAL binary downloads at the time of writing do not include Java support).
  47. Unpack the :file:`zip` file in a suitable location, and then set the following variables before starting up GeoServer:
  48. .. code-block:: bat
  49. set PATH=%PATH%;C:\<unzipped_package>\bin;C:\<unzipped_package>\bin\gdal\java
  50. set GDAL_DRIVER_PATH=C:\<unzipped_package>\bin\gdal\plugins
  51. set GDAL_DATA=C:\<unzipped_package>\bin\gdal-data
  52. There are a few optional drivers that you can find in file:`C:\<unzipped_package>\bin\gdal\plugins-extra`
  53. and :file:`C:\<unzipped_package>\bin\gdal\plugins-optional`. Include these paths in ```GDAL_DRIVER_PATH`` enables the additional formats.
  54. .. warning:: Before adding the extra formats please make sure that you are within your rights
  55. to use them in a server environment (some packages are specifically forbidden from
  56. free usage on the server side and require a commercial licence, e.g., ECW).
  57. .. note:: Depending on the version of the underlying operating system you will have to pick up the right one. You can google around for the one you need. Also make sure you download the 32 bit
  58. version if you are using a 32 bit version of Windows or the 64 bit version (has a "-x64" suffix in the name of the zip file) if you are running a 64 bit version of Windows.
  59. Again, pick the one that matches your infrastructure.
  60. Note on running GeoServer as a Service on Windows
  61. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  62. Deploying the GDAL ImageI/O-Ext native libraries in a location referred by the ``PATH`` environment variable (like, as an instance, the JDK/bin folder) will not allow the GeoServer service to use GDAL. As a result, during the service startup, GeoServer log will likely report the following message::
  63. it.geosolutions.imageio.gdalframework.GDALUtilities loadGDAL
  64. WARNING: Native library load failed.java.lang.UnsatisfiedLinkError: no gdaljni in java.library.path
  65. Taking a look at the ``jsl74.ini`` configuration file available inside the GeoServer installation , there is this useful entry:
  66. .. code-block:: ini
  67. ;The java command line
  68. ;The entry method below using a parameter list still works but the command line variant is more convenient.
  69. ;Everything separated by whitespace on a java command line is broken down into a parameter here.
  70. ;You don't need to care about quotes
  71. ;around strings containing spaces here. e.g.
  72. cmdline = -cp "..\src" com.roeschter.jsl.TelnetEcho
  73. To allow the GDAL native DLLs to be loaded:
  74. #. Edit the command line to include ``-Djava.library.path`` with the location of your GDAL libraries.
  75. Linux packages and setup
  76. ^^^^^^^^^^^^^^^^^^^^^^^^
  77. For common LTS Linux distribution there are packages for GDAL and the associated Java bindings,
  78. e.g., on Ubuntu and derivatives you can install them using::
  79. sudo apt-get install gdal-bin libgdal-java
  80. The libraries as installed above are already in the search path, so no extra setup is normally needed.
  81. In case setting up the ``GDAL_DATA`` is required to handle certain projections, it's normally found
  82. in ``/usr/share/gdal/<version>``, so you can execute the following prior to start GeoServer, e.g::
  83. export GDAL_DATA=/usr/share/gdal/<version>
  84. In case you decide to build from sources instead, remember to run ``configure`` with ``--with-java``,
  85. and after the main build and install, get into the ``swig/java`` and run a build and install there.
  86. For more information about building GDAL see:
  87. * `General build information <https://trac.osgeo.org/gdal/wiki/BuildHints>`__
  88. * `Specific info to build GDAL Java bindings <https://trac.osgeo.org/gdal/wiki/GdalOgrInJavaBuildInstructionsUnix>`__
  89. After the build and installation, export the following variables to make GeoServer use the GDAL custom build::
  90. export LD_LIBRARY_PATH=/<path_to_gdal_install>/lib
  91. export GDAL_DATA=/<path_to_gdal_install>/share/gdal
  92. Testing the installation
  93. ------------------------
  94. Once these steps have been completed, restart GeoServer.
  95. Navigate to :menuselection:`About > Server Status` page, and change to the :guilabel:`Modules` tab, and click :guilabel:`ImageI/O-Ext GDAL Coverage Extension` link for status information.
  96. .. figure:: images/gdal-extension-status.png
  97. ImageI/O GDAL Coverage Extension Module Status
  98. This information can be used to verify that the extension is active, the version of GDAL used, and the version of the SWIG bindings used.
  99. If all the steps have been performed correctly, new data formats will be in the :guilabel:`Raster Data Sources` list when creating a new data store in the :guilabel:`Stores` section as shown here below.
  100. .. figure:: images/newsource.png
  101. :align: center
  102. *GDAL image formats in the list of raster data stores*
  103. If new formats do not appear in the GUI and you see the following message in the log file::
  104. *it.geosolutions.imageio.gdalframework.GDALUtilities loadGDAL
  105. WARNING: Native library load failed.java.lang.UnsatisfiedLinkError: no gdaljni in java.library.path*
  106. WARNING: Native library load failed.java.lang.UnsatisfiedLinkError: no gdalalljni in java.library.path*
  107. This means that the extension was installed, bu twas not able to access your gdal library for some reason.
  108. Configuring a DTED data store
  109. -----------------------------
  110. .. figure:: images/gdaldtedconfigure.png
  111. :align: center
  112. *Configuring a DTED data store*
  113. Configuring a EHdr data store
  114. -----------------------------
  115. .. figure:: images/gdalehdrconfigure.png
  116. :align: center
  117. *Configuring a EHdr data store*
  118. Configuring a ERDASImg data store
  119. ---------------------------------
  120. .. figure:: images/gdalerdasimgconfigure.png
  121. :align: center
  122. *Configuring a ERDASImg data store*
  123. Configuring a JP2MrSID data store
  124. ---------------------------------
  125. .. figure:: images/gdaljp2mrsidconfigure.png
  126. :align: center
  127. *Configuring a JP2MrSID data store*
  128. Configuring a NITF data store
  129. -----------------------------
  130. .. figure:: images/gdalnitfconfigure.png
  131. :align: center
  132. *Configuring a NITF data store*
  133. Supporting vector footprints
  134. ----------------------------
  135. Starting with version 2.9.0, GeoServer supports vector footprints.
  136. A footprint is a shape used as a mask to hide those pixels that are outside of the mask, hence making that part of the parent image transparent.
  137. The currently supported footprint formats are WKB, WKT and Shapefile.
  138. By convention, the footprint file should be located in the same directory as the raster data that the footprint applies to.
  139. .. note:: In the examples of this section and related subsections, we will always use .wkt as extension, representing a WKT footprint, although both .wkb and .shp are supported too.
  140. For example, supposing you have a MrSID file located at
  141. :file:`/mnt/storage/data/landsat/N-32-40_2000.sid`
  142. to be masked, you just need to place a WKT file on the same folder, as
  143. :file:`/mnt/storage/data/landsat/N-32-40_2000.wkt`
  144. Note that the footprint needs to have same path and name of the original data file, with .wkt extension.
  145. This is how the sample footprint geometry looks:
  146. .. figure:: images/masking.png
  147. :align: center
  148. *A sample geometry stored as WKT, rendered on OpenJump*
  149. Once footprint file has been added, you need to change the FootprintBehavior parameter from None (the default value) to Transparent, from the layer configuration.
  150. .. figure:: images/footprintbehavior.png
  151. :align: center
  152. *Setting the FootprintBehavior parameter*
  153. The next image depicts 2 layer previews for the same layer: the left one has no footprint, the right one has a footprint available and FootprintBehavior set to transparent.
  154. .. figure:: images/gdalmasks.png
  155. :align: center
  156. *No Footprint VS FootprintBehavior = Transparent*
  157. External Footprints data directory
  158. ++++++++++++++++++++++++++++++++++
  159. As noted above, the footprint file should be placed in the same directory as the raster file. However in some cases this may not be possible. For example, the folder
  160. containing the raster data may be read only.
  161. As an alternative, footprint files can be located in a common directory, the **footprints data directory**. The subdirectories and file names under that directory must match
  162. the original raster path and file names. The footprints data directory is specified as a Java System Property or an Environment Variable, by setting the `FOOTPRINTS_DATA_DIR`
  163. property/variable to the directory to be used as base folder.
  164. Example
  165. ^^^^^^^
  166. Suppose you have 3 raster files with the following paths:
  167. * :file:`/data/raster/charts/nitf/italy_2015.ntf`
  168. * :file:`/data/raster/satellite/ecw/orthofoto_2014.ecw`
  169. * :file:`/data/raster/satellite/landsat/mrsid/N-32-40_2000.sid`
  170. They can be represented by this tree:
  171. .. code-block:: text
  172. /data
  173. \---raster
  174. +---charts
  175. | \---nitf
  176. | italy_2015.ntf
  177. |
  178. \---satellite
  179. +---ecw
  180. | orthofoto_2014.ecw
  181. |
  182. \---landsat
  183. \---mrsid
  184. N-32-40_2000.sid
  185. In order to support external footprints you should
  186. #. Create a :file:`/footprints` (as an example) directory on disk
  187. #. Set the :file:`FOOTPRINTS_DATA_DIR=/footprints` variable/property.
  188. #. Replicate the rasters folder hierarchy inside the specified folder, using the full paths.
  189. #. Put the 3 WKT files in the proper locations:
  190. * :file:`/footprints/data/raster/charts/nitf/italy_2015.wkt`
  191. * :file:`/footprints/data/raster/satellite/ecw/orthofoto_2014.wkt`
  192. * :file:`/footprints/data/raster/satellite/landsat/mrsid/N-32-40_2000.wkt`
  193. Which can be represented by this tree:
  194. .. code-block:: text
  195. /footprints
  196. \---data
  197. \---raster
  198. +---charts
  199. | \---nitf
  200. | italy_2015.wkt
  201. |
  202. \---satellite
  203. +---ecw
  204. | orthofoto_2014.wkt
  205. |
  206. \---landsat
  207. \---mrsid
  208. N-32-40_2000.wkt
  209. Such that, in the end, you will have the following folders hierarchy tree:
  210. .. code-block:: text
  211. +---data
  212. | \---raster
  213. | +---charts
  214. | | \---nitf
  215. | | italy_2015.ntf
  216. | |
  217. | \---satellite
  218. | +---ecw
  219. | | orthofoto_2014.ecw
  220. | |
  221. | \---landsat
  222. | \---mrsid
  223. | N-32-40_2000.sid
  224. |
  225. \---footprints
  226. \---data
  227. \---raster
  228. +---charts
  229. | \---nitf
  230. | italy_2015.wkt
  231. |
  232. \---satellite
  233. +---ecw
  234. | orthofoto_2014.wkt
  235. |
  236. \---landsat
  237. \---mrsid
  238. N-32-40_2000.wkt
  239. Note the parallel mirrored folder hierarchy, with the only differences being a :file:`/footprints` prefix at the beginning of the path,
  240. and the change in suffix.