0

Using GeoServer Rest API, I have uploaded a 4 band Geotiff image in a coverage store. But I can't seem to find the right request to create a CoverageView from this geotiff, choosing which band this CoverageView will have, although I can do it from GeoServer interface.

Could anyone point me in the right direction ?

Like in this post, I created a coverage store and uploaded my geotiff. To create the coverage view, I send this query, using httr package in R :

r = POST(
     url = "http://localhost:8080/geoserver/rest/workspaces/my_workspace/coveragestores/my_coverage_store/coverages",
     config = authenticate(id, password),
     add_headers(.headers = c("Content-Type" = "text/xml")),
     body = body)

and the xml body :

<coverage>
    <name>my_coverage_store</name>
    <nativeName>my_coverage_store</nativeName>
    <metadata>
        <entry key=\"COVERAGE_VIEW\">
        </entry>
    </metadata>
</coverage>

And with content(r) I get this error :

"java.lang.String cannot be cast to org.geoserver.catalog.CoverageView"

Alternatively, another answer for my problem would be to define a sld or css style where I can choose which band to display and specify that no alpha band should be used. So far I wasn't able to do that since in the openlayers preview of my layer using JPEG is OK, but with PNG the 4th band is set as an alpha band.

4
  • Once you have set it up in the GUI, you can then request it from the REST API to find out what you need to set in the file you send next time
    – Ian Turton
    Mar 10 '21 at 9:08
  • Thanks for your answer. I've been trying get infos as json from created coverage view, and then send it in the body of a new query, but I must not be doing it right, since I get messages like Unsupported value type for form field 'metadata'. Sorry I don't know much about this !
    – Julie
    Mar 10 '21 at 10:43
  • please edit your question with the commands you are using and the data you are sending
    – Ian Turton
    Mar 10 '21 at 10:56
  • Thanks for your help, hope it's a little bit more clear now !
    – Julie
    Mar 12 '21 at 9:39
1

The XML body of the request didn't have enough info, I managed to create a coverage view with the same request :

r = POST(
 url = "http://localhost:8080/geoserver/rest/workspaces/my_workspace/coveragestores/my_coverage_store/coverages",
 config = authenticate(id, password),
 add_headers(.headers = c("Content-Type" = "text/xml")),
 body = body)

But with this XML body :

<coverage>
<name>coverageViewName</name>
<nativeName>coverageViewName</nativeName>
<title>coverageViewName</title>
<metadata>
    <entry key="COVERAGE_VIEW">
        <coverageView>
            <coverageBands>
                <coverageBand>
                    <inputCoverageBands class="singleton-list">
                        <inputCoverageBand>
                            <coverageName>coverageViewName</coverageName>
                            <band>0</band>
                        </inputCoverageBand>
                    </inputCoverageBands>
                    <definition>coverageViewName@0</definition>
                    <index>0</index>
                    <compositionType>BAND_SELECT</compositionType>
                </coverageBand>
                <coverageBand>
                    <inputCoverageBands class="singleton-list">
                        <inputCoverageBand>
                            <coverageName>coverageViewName</coverageName>
                            <band>1</band>
                        </inputCoverageBand>
                    </inputCoverageBands>
                    <definition>coverageViewName@1</definition>
                    <index>1</index>
                    <compositionType>BAND_SELECT</compositionType>
                </coverageBand>
                <coverageBand>
                    <inputCoverageBands class="singleton-list">
                        <inputCoverageBand>
                            <coverageName>coverageViewName</coverageName>
                            <band>2</band>
                        </inputCoverageBand>
                    </inputCoverageBands>
                    <definition>coverageViewName@2</definition>
                    <index>2</index>
                    <compositionType>BAND_SELECT</compositionType>
                </coverageBand>
                <coverageBand>
                    <inputCoverageBands class="singleton-list">
                        <inputCoverageBand>
                            <coverageName>coverageViewName</coverageName>
                            <band>3</band>
                        </inputCoverageBand>
                    </inputCoverageBands>
                    <definition>coverageViewName@3</definition>
                    <index>3</index>
                    <compositionType>BAND_SELECT</compositionType>
                </coverageBand>
            </coverageBands>
            <name>coverageViewName</name>
            <envelopeCompositionType>INTERSECTION</envelopeCompositionType>
            <selectedResolution>BEST</selectedResolution>
            <selectedResolutionIndex>-1</selectedResolutionIndex>
        </coverageView>
    </entry>
</metadata>

The coverage store and coverage view must have the same name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.