tutorial.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. .. _data_imagemosaic_tutorial:
  2. Using the ImageMosaic extension
  3. ===============================
  4. This tutorial will show you how to configure and publish an ImageMosaic store and coverage, followed by some configuration examples.
  5. Configuring a coverage in GeoServer
  6. -----------------------------------
  7. This is a process very similar to creating a featuretype. More specifically, one has to perform the steps highlighted in the sections below:
  8. Create a new store
  9. ~~~~~~~~~~~~~~~~~~
  10. #. Go to :menuselection:`Data Panel --> Stores` and click :guilabel:`Add new Store`.
  11. #. Select :guilabel:`ImageMosaic` under :guilabel:`Raster Data Source`:
  12. .. figure:: images/imagemosaiccreate.png
  13. ImageMosaic in the list of raster data stores
  14. #. In order to create a new mosaic it is necessary to choose a workspace and store name in the :guilabel:`Basic Store Info` section, as well as a URL in the :guilabel:`Connection Parameters` section. Valid URLs include:
  15. * The absolute path to the shapefile index, or a directory containing the shapefile index.
  16. * The absolute path to the configuration file (`*.properties``) or a directory containing the configuration file. If ``datastore.properties`` and ``indexer.properties`` exist, they should be in the same directory as this configuration file.
  17. * The absolute path of a directory where the files you want to mosaic reside. In this case GeoServer automatically creates the needed mosaic files (.dbf, .prj, .properties, .shp and .shx) by inspecting the data present in the given directory and any subdirectories.
  18. #. Click :guilabel:`Save`:
  19. .. figure:: images/imagemosaicconfigure.png
  20. Configuring an ImageMosaic data store
  21. Create a new coverage
  22. ~~~~~~~~~~~~~~~~~~~~~
  23. #. Navigate to :menuselection:`Data Panel --> Layers` and click :guilabel:`Add a new resource`.
  24. #. Choose the name of the store you just created:
  25. .. figure:: images/vito_newlayerchoser.png
  26. Layer Chooser
  27. #. Click the layer you wish to configure and you will be presented with the Coverage Editor:
  28. .. figure:: images/vito_coverageeditor.png
  29. Coverage Editor
  30. #. Make sure there is a value for :guilabel:`Native SRS`, then click the :guilabel:`Submit` button. If the :guilabel:`Native CRS` is ``UNKNOWN``, you must declare the SRS in the :guilabel:`Declared SRS` field.
  31. #. Click :guilabel:`Save`.
  32. #. Use the :guilabel:`Layer Preview` to view the mosaic.
  33. .. warning:: If the created layer appears to be all black, it may be that GeoServer has not found any acceptable granules in the provided index. It is also possible that the shapefile index is empty (no granules were found in the provided directory) or it might be that the granules' paths in the shapefile index are not correct, which could happen if an existing index (using absolute paths) is moved to another place. If the shapefile index paths are not correct, then the DBF file can be opened and fixed with an editor. Alternately, you can delete the index and let GeoServer recreate it from the root directory.
  34. Configuration examples
  35. ----------------------
  36. Below are a few examples of mosaic configurations to demonstrate how we can make use of the ImageMosaic parameters.
  37. DEM/Bathymetry
  38. ~~~~~~~~~~~~~~
  39. Such a mosaic can be used to serve large amounts of data representing altitude or depth and therefore does not specify colors directly (it needs an SLD to generate pictures). In our case, we have a DEM dataset which consists of a set of raw GeoTIFF files.
  40. The first operation is to create the CoverageStore specifying, for example, the path of the shapefile in the :guilabel:`URL` field.
  41. Inside the Coverage Editor Publishing tab, you can specify the :guilabel:`dem` default style in order to represent the visualization style of the mosaic. The following is an example style:
  42. .. code-block:: xml
  43. <?xml version="1.0" encoding="ISO-8859-1"?>
  44. <StyledLayerDescriptor version="1.0.0"
  45. xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
  46. xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  47. xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
  48. <NamedLayer>
  49. <Name>gtopo</Name>
  50. <UserStyle>
  51. <Name>dem</Name>
  52. <Title>Simple DEM style</Title>
  53. <Abstract>Classic elevation color progression</Abstract>
  54. <FeatureTypeStyle>
  55. <Rule>
  56. <RasterSymbolizer>
  57. <Opacity>1.0</Opacity>
  58. <ColorMap>
  59. <ColorMapEntry color="#000000" quantity="-9999" label="nodata" opacity="1.0" />
  60. <ColorMapEntry color="#AAFFAA" quantity="0" label="values" />
  61. <ColorMapEntry color="#00FF00" quantity="1000" label="values" />
  62. <ColorMapEntry color="#FFFF00" quantity="1200" label="values" />
  63. <ColorMapEntry color="#FF7F00" quantity="1400" label="values" />
  64. <ColorMapEntry color="#BF7F3F" quantity="1600" label="values" />
  65. <ColorMapEntry color="#000000" quantity="2000" label="values" />
  66. </ColorMap>
  67. </RasterSymbolizer>
  68. </Rule>
  69. </FeatureTypeStyle>
  70. </UserStyle>
  71. </NamedLayer>
  72. </StyledLayerDescriptor>
  73. In this way you have a clear distinction between the different intervals of the dataset that compose the mosaic, like the background and the "nodata" area.
  74. .. figure:: images/vito_config_1.png
  75. .. note:: The "nodata" on the sample mosaic is -9999. The default background value is for mosaics is 0.0.
  76. The result is the following:
  77. .. figure:: images/vito_1.png
  78. Basic configuration
  79. By setting the other configuration parameters appropriately, it is possible to improve both the appearance of the mosaic as well as its performance. For instance, we could:
  80. * Make the "nodata" areas transparent and coherent with the real data. To achieve this we need to change the opacity of the "nodata" ColorMapEntry in the ``dem`` style to ``0.0`` and set the ``BackgroundValues`` parameter to ``-9999`` so that empty areas will be filled with this value. The result is as follows:
  81. .. figure:: images/vito_2.png
  82. Advanced configuration
  83. * Allow multithreaded granules loading. By setting the ``AllowMultiThreading`` parameter to ``true``, GeoServer will load the granules in parallel using multiple threads with a increase in performance on some architectures.
  84. The configuration parameters are as follows:
  85. .. list-table::
  86. :widths: 25 75
  87. :header-rows: 1
  88. :stub-columns: 1
  89. * - Parameter
  90. - Value
  91. * - MaxAllowedTiles
  92. - 2147483647
  93. * - BackgroundValues
  94. - -9999
  95. * - OutputTransparentColor
  96. - "no color"
  97. * - InputTransparentColor
  98. - "no color"
  99. * - AllowMultiThreading
  100. - True
  101. * - USE_JAI_IMAGEREAD
  102. - True
  103. * - SUGGESTED_TILE_SIZE
  104. - 512,512
  105. Aerial imagery
  106. ~~~~~~~~~~~~~~
  107. In this example we are going to create a mosaic that will serve aerial imagery, specifically RGB GeoTIFFs. Because this is visual data, in the Coverage Editor you can use the basic ``raster`` style, which is just a stub SLD to instruct the GeoServer raster renderer to not do anything particular in terms of color management:
  108. .. code-block:: xml
  109. <?xml version="1.0" encoding="ISO-8859-1"?>
  110. <StyledLayerDescriptor version="1.0.0"
  111. xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
  112. xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  113. xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
  114. <NamedLayer>
  115. <Name>raster</Name>
  116. <UserStyle>
  117. <Name>raster</Name>
  118. <Title>Raster</Title>
  119. <Abstract>A sample style for rasters, good for displaying imagery </Abstract>
  120. <FeatureTypeStyle>
  121. <FeatureTypeName>Feature</FeatureTypeName>
  122. <Rule>
  123. <RasterSymbolizer>
  124. <Opacity>1.0</Opacity>
  125. </RasterSymbolizer>
  126. </Rule>
  127. </FeatureTypeStyle>
  128. </UserStyle>
  129. </NamedLayer>
  130. </StyledLayerDescriptor>
  131. The result is the following:
  132. .. figure:: images/prato_1.png
  133. Basic configuration
  134. .. note:: Those ugly black areas are the result of applying the default mosaic parameters to a mosaic that does not entirely cover its bounding box. The areas within the BBOX that are not covered with data will default to a value of 0 on each band. Since this mosaic is RGB we can simply set the ``OutputTransparentColor`` to ``0,0,0`` in order to get transparent fills for the BBOX.
  135. The various parameters can be set as follows:
  136. .. list-table::
  137. :widths: 25 75
  138. :header-rows: 1
  139. :stub-columns: 1
  140. * - Parameter
  141. - Value
  142. * - MaxAllowedTiles
  143. - 2147483647
  144. * - BackgroundValues
  145. - (default)
  146. * - OutputTransparentColor
  147. - #000000
  148. * - InputTransparentColor
  149. - "no color"
  150. * - AllowMultiThreading
  151. - True
  152. * - USE_JAI_IMAGEREAD
  153. - True
  154. * - SUGGESTED_TILE_SIZE
  155. - 512,512
  156. The result is the following:
  157. .. figure:: images/prato_2.png
  158. Advanced configuration
  159. Scanned maps
  160. ~~~~~~~~~~~~
  161. In this case we want to show how to serve scanned maps (mostly B&W images) via a GeoServer mosaic.
  162. In the Coverage Editor you can use the basic ``raster`` since there is no need to use any of the advanced RasterSymbolizer capabilities.
  163. The result is the following.
  164. .. figure:: images/iacovella_1.png
  165. Basic configuration
  166. This mosaic, formed by two single granules, shows a typical case where the "nodata" collar areas of the granules overlap, as shown in the picture above.
  167. In this case we can use the ``InputTransparentColor`` parameter to make the collar areas disappear during the superimposition process — in this case, by using an ``InputTransparentColor`` of ``#FFFFFF``.
  168. The final configuration parameters are the following:
  169. .. list-table::
  170. :widths: 25 75
  171. :header-rows: 1
  172. :stub-columns: 1
  173. * - Parameter
  174. - Value
  175. * - MaxAllowedTiles
  176. - 2147483647
  177. * - BackgroundValues
  178. - (default)
  179. * - OutputTransparentColor
  180. - "no color"
  181. * - InputTransparentColor
  182. - #FFFFFF
  183. * - AllowMultiThreading
  184. - True
  185. * - USE_JAI_IMAGEREAD
  186. - True
  187. * - SUGGESTED_TILE_SIZE
  188. - 512,512
  189. This is the result:
  190. .. figure:: images/iacovella_2.png
  191. Advanced configuration
  192. Dynamic imagery
  193. ~~~~~~~~~~~~~~~
  194. A mosaic need not be static. It can contain granules which change, are added or deleted. In this example, we will create a mosaic that changes over time.
  195. #. Create a mosaic in the standard way. (The specific configuration isn't important.)
  196. .. figure:: images/tutorial_dynamic1.png
  197. This mosaic contains 5 granules. Note that ``InputTransparentColor`` is set to ``#FFFFFF`` here.
  198. To add new granules, the index that was created when the mosaic was originally created needs to be regenerated. There are two ways to do this:
  199. * Manually through the file system
  200. * Through the :ref:`rest` interface
  201. To update an ImageMosaic through the file system:
  202. #. Update the contents of the mosaic by copying the new files into place. (Subdirectories are acceptable.)
  203. #. Delete the index files. These files are contained in the top level directory containing the mosaic files and include (but are not limited to) the following:
  204. * :file:`<mosaic_name>.dbf`
  205. * :file:`<mosaic_name>.fix`
  206. * :file:`<mosaic_name>.prj`
  207. * :file:`<mosaic_name>.properties`
  208. * :file:`<mosaic_name>.shp`
  209. * :file:`<mosaic_name>.shx`
  210. #. *(Optional but recommended)* Edit the layer definition in GeoServer, making to sure to update the bounding box information (if changed).
  211. #. Save the layer. The index will be recreated.
  212. .. figure:: images/tutorial_dynamic2.png
  213. This mosaic contains 9 granules
  214. .. note:: Please see the REST section for information on :ref:`rest_imagemosaic`.
  215. .. _multi-crs-mosaic:
  216. Multi-resolution imagery with reprojection
  217. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  218. As a general rule, we want to have the highest resolution granules shown "on top", with the lower-resolution granules filling in the gaps as necessary.
  219. In this example, we will serve up overlapping granules that have varying resolutions. In addition, we will mix resolutions, such that the higher resolution granule is reprojected to match the resolution of the lower resolution granules.
  220. #. In the Coverage Editor, use the basic ``raster`` style.
  221. #. Create the mosaic in GeoServer.
  222. #. One important configuration setting is the :guilabel:`SORTING` parameter of the layer. In order to see the highest resolution imagery on top (the typical case), it must be set to :kbd:`resolution A`. (For the case of lowest resolution on top, use :kbd:`resolution D` .)
  223. #. Make any other configuration changes.
  224. #. Also, in order to allow for multiple CRSs in a single mosaic, an :file:`indexer.properties` file will need to be created. Use the following ::
  225. GranuleAcceptors=org.geotools.gce.imagemosaic.acceptors.HeterogeneousCRSAcceptorFactory
  226. GranuleHandler=org.geotools.gce.imagemosaic.granulehandler.ReprojectingGranuleHandlerFactory
  227. HeterogeneousCRS=true
  228. MosaicCRS=EPSG\:4326
  229. PropertyCollectors=CRSExtractorSPI(crs),ResolutionExtractorSPI(resolution)
  230. Schema=*the_geom:Polygon,location:String,crs:String,resolution:String
  231. The MosaicCRS property is not mandatory, but it's a good idea to set a predictable target CRS that all granule footprints can be reprojected into,
  232. otherwise the mosaic machinery will use the CRS of the first indexed granule.
  233. #. Save this file in the root of the mosaic directory (along with the index files). The result is the following:
  234. .. figure:: images/tutorial_reproj_artifact.png
  235. Closeup of granule overlap (high resolution granule on right)
  236. #. To remove the reprojection artifact (shown in the above as a black area) edit the layer configuration to set ``InputTransparentColor`` to ``#000000``.
  237. .. figure:: images/tutorial_reproj_noartifact.png
  238. Closeup of granule overlap (high resolution granule on right)
  239. Referring to a datastore configured in GeoServer
  240. ------------------------------------------------
  241. It is possible to make the mosaic refer to an existing data store. The **``datastore.properties``** file in this case will
  242. contain only one or two properties, referring to the store to be used via the ``StoreName`` property.
  243. For simple cases, e.g., a PostGIS store, the following will be sufficient::
  244. StoreName=workspace:storename
  245. For Oracle or H2, it's best to also specify the SPI in order to inform the mosaic that it needs to work around
  246. specific limitations of the storage (e.g., forced uppercase attribute usage, limitation in attribute name length and the like)::
  247. StoreName=workspace:storename
  248. SPI=org.geotools.data.oracle.OracleNGDataStoreFactory
  249. The above will be sufficient in case the image mosaic can create the index table and perform normal indexing, using
  250. the directory name as the table name.
  251. In case a specific table name needs to be used, add an **``indexer.properties``** specifying the ``TypeName`` property,
  252. e.g.:
  253. TypeName=myMosaicTypeName
  254. In case the index "table" already exists instead, then a **``indexer.properties``** file will be required, with the following contents::
  255. UseExistingSchema=true
  256. TypeName=nameOfTheFeatureTypeContainingTheIndex
  257. AbsolutePath=true
  258. The above assumes ``location`` attribute provides absolute paths to the mosaic granules, instead of paths relative to
  259. the mosaic configuration files directory.