mosaic.rst 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. .. _tutorial_imagemosaic_cog_landsat8:
  2. ImageMosaic example with Modis COG datasets
  3. ===========================================
  4. Introduction
  5. ------------
  6. This tutorial provide some hints on configuring an ImageMosaic on top of some MODIS Vegetation Index datasets available at `NASA EarthData <https://earthdata.nasa.gov/collaborate/cloud-optimized-geotiffs>`_
  7. ImageMosaic Configuration files
  8. -------------------------------
  9. We need a couple of configuration files to have an ImageMosaic properly set. Configuration is based on these key points:
  10. * The ImageMosaic will be initially created empty without any data. Data will be harvested as a second step.
  11. * A Time dimension will be used, based on the date contained in the file's name.
  12. More details on ImageMosaic configuration are available on the dedicated documentation section: :ref:`data_imagemosaic_config`
  13. Based on the above key points, we can setup the following configuration files:
  14. indexer.properties:
  15. """""""""""""""""""
  16. This contains the main configuration to index the datasets composing the ImageMosaic.
  17. .. literalinclude:: src/modisvi/indexer.properties
  18. Relevant parts:
  19. * Cog flag specifying that the ImageMosaic is a Mosaic of COG Datasets
  20. * PropertyCollectors, TimeAttribute and Schema are used to define the ImageMosaic index columns and how to populate them
  21. * CanBeEmpty allows to define an empty ImageMosaic. It will be populated afterwards
  22. * Name is the name for this mosaic
  23. timeregex.properties:
  24. """""""""""""""""""""
  25. The previous indexer refers to a time dimension and the related time column in the index's schema that will get populated by extracting the time value from the filename (the 8 digits, representing YEAR, MONTH, DAY) using the regex specified in the timeregex.properties file. An example of sample file for this collection as stored on the S3 bucket is 2018.01.01.tif so the time regex will reflect that. Note the 3 groups of digits and the 'format' of the date.
  26. .. literalinclude:: src/modisvi/timeregex.properties
  27. datastore.properties:
  28. """""""""""""""""""""
  29. Due to the amount of available datasets, storing the ImageMosaic index on a DBMS is recommended, i.e. a PostGIS DB. See :ref:`mosaic_datastore_properties` section of the ImageMosaic documentation for more info.
  30. Make sure that a DB with the name reported in the datastore is available
  31. .. literalinclude:: src/modisvi/datastore.properties
  32. Once the 3 files have been setup, create a zip archive with them and let's name it modisvi.zip. (Note that the files need to be in the root of the zip files, not into a subdirectory)
  33. You are now ready to use REST calls to start the ImageMosaic creation.
  34. ImageMosaic REST operations
  35. """""""""""""""""""""""""""
  36. On the next steps we assume:
  37. * An existing GeoServer instance is running on port 8080 of localhost.
  38. * A workspace named "test" exists on that GeoServer.
  39. * REST credentials are user=admin password=geoserver.
  40. * A default aws region is defined on JAVA System Property, using the flag `-Diio.https.aws.region=us-west-2`.
  41. Make sure to update the incoming URLs accordingly, based on your actual installation.
  42. **Create an empty ImageMosaic without configuring it**
  43. .. admonition:: curl request
  44. ::
  45. curl -u admin:geoserver -XPUT --write-out %{http_code} -H "Content-type:application/zip" --data-binary @modisvi.zip http://localhost:8080/geoserver/rest/workspaces/test/coveragestores/modisvi/file.imagemosaic?configure=none
  46. *Response*
  47. ::
  48. 201 OK
  49. **Providing sample prototyping granules**
  50. Next step is providing a prototype dataset for the coverage to be supported.
  51. .. admonition:: curl request
  52. ::
  53. curl -u admin:geoserver -XPOST -H "Content-type: text/plain" --write-out %{http_code} -d "https://modis-vi-nasa.s3-us-west-2.amazonaws.com/MOD13A1.006/2018.01.01.tif" "http://localhost:8080/geoserver/rest/workspaces/test/coveragestores/modisvi/remote.imagemosaic"
  54. *Response*
  55. ::
  56. 202 Accepted
  57. **Initializing the store (Listing available coverages)**
  58. Once a prototype has been provided we need to initialize the store by querying it for the available coverages.
  59. .. admonition:: curl request
  60. ::
  61. curl -v -u admin:geoserver -XGET http://localhost:8080/geoserver/rest/workspaces/test/coveragestores/modisvi/coverages.xml?list=all
  62. *Response*
  63. .. code-block:: xml
  64. <List>
  65. <coverageName>modisvi</coverageName>
  66. </list>
  67. **Configuring the coverage**
  68. Once we get the list of available coverages, we need to configure a coverage by sending the config through REST.
  69. .. admonition:: curl request
  70. ::
  71. curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d @"coverage.xml" "http://localhost:8080/geoserver/rest/workspaces/test/coveragestores/modisvi/coverages"
  72. where coverage.xml has this content:
  73. .. code-block:: xml
  74. <coverage>
  75. <name>modisvi</name>
  76. <nativeName>modisvi</nativeName>
  77. <enabled>true</enabled>
  78. <metadata>
  79. <entry key="time">
  80. <dimensionInfo>
  81. <enabled>true</enabled>
  82. <presentation>LIST</presentation>
  83. <units>ISO8601</units>
  84. <defaultValue>
  85. <strategy>MAXIMUM</strategy>
  86. </defaultValue>
  87. </dimensionInfo>
  88. </entry>
  89. </metadata>
  90. </coverage>
  91. **Adding more granules**
  92. Now that we have a coverageStore ready and a coverage layer configured we can start adding more granules.
  93. .. admonition:: curl request
  94. ::
  95. curl -u admin:geoserver -XPOST -H "Content-type: text/plain" --write-out %{http_code} -d "https://modis-vi-nasa.s3-us-west-2.amazonaws.com/MOD13A1.006/2018.01.17.tif" "http://localhost:8080/geoserver/rest/workspaces/test/coveragestores/modisvi/remote.imagemosaic"
  96. **Setting Style**
  97. That MODIS data has 2 bands representing (Normalized Difference Vegetation Index) (NDVI) and Enhanced Vegetation Index (EVI).
  98. Let's add this ndvi.sld style to apply a proper colormap to the NDVI band (copy this content to a file named ndvi.sld to be used by the next REST call):
  99. .. code-block:: xml
  100. <StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0">
  101. <NamedLayer>
  102. <Name>Default Styler</Name>
  103. <UserStyle>
  104. <Name>ndvi</Name>
  105. <Title>ndvi</Title>
  106. <FeatureTypeStyle>
  107. <Name>name</Name>
  108. <Rule>
  109. <RasterSymbolizer>
  110. <ChannelSelection>
  111. <GrayChannel>
  112. <SourceChannelName>1</SourceChannelName>
  113. </GrayChannel>
  114. </ChannelSelection>
  115. <ColorMap>
  116. <ColorMapEntry color="#000000" quantity="-1"/>
  117. <ColorMapEntry color="#0000ff" quantity="-0.75"/>
  118. <ColorMapEntry color="#ff00ff" quantity="-0.25"/>
  119. <ColorMapEntry color="#ff0000" quantity="0"/>
  120. <ColorMapEntry color="#ffff00" quantity="0.5"/>
  121. <ColorMapEntry color="#00ff00" quantity="1"/>
  122. </ColorMap>
  123. <ContrastEnhancement/>
  124. </RasterSymbolizer>
  125. </Rule>
  126. </FeatureTypeStyle>
  127. </UserStyle>
  128. </NamedLayer>
  129. </StyledLayerDescriptor>
  130. .. admonition:: curl request to create the style
  131. ::
  132. curl -v -u admin:geoserver -XPOST -H "Content-type: application/vnd.ogc.sld+xml" -d @ndvi.sld http://localhost:8080/geoserver/rest/styles
  133. .. admonition:: curl request to set the style as default style of the layer
  134. ::
  135. curl -v -u admin:geoserver -XPUT -H "Content-type: text/xml" -d "<layer><defaultStyle><name>ndvi</name></defaultStyle></layer>" http://localhost:8080/geoserver/rest/layers/modisvi.xml
  136. Final preview
  137. """""""""""""
  138. This is how a layer preview will looks like:
  139. .. figure:: images/ndvi.png
  140. NDVI COG dataset