When using a MapServer layer with a TILEINDEX and TILEITEM defined... will MapServer clip the source raster to the dimensions of the identified tileindex item(s), or simply use it as a reference to locate the underlying raster file and output the file in its entirety?

My wish is to take a source index file and clip it to state boundaries so only those source files within that state will be accessed and their output will be clipped to the state boundaries for those files whose dimensions overlap the boundary


The latter alternative is right, tileindex items are used as reference for locating the underlying raster files.

If you want that raster imagery is shown only within the state boundaries you have two alternatives for configuring that with your mapfile - layer https://mapserver.org/uk/mapfile/layer.html.

1) Create a very big polygon that has your state area as a hole and make a vector layer from that. Place it below your raster layer in the mapfile which means that it will be rendered later, so it will painted on top of the raster tileindex layer. Finally make the raster layer to require that the state boundary layer must also be rendered by adding REQUIRES "[boundary_layer]" into your mapfile. I am remembering that the syntax takes the plain layer name without square brackets and they are used just as placeholders in the documentation.

2) Use mask layer. By the documentation it seems that for the mask you must make a vector layer from the state polygon itself, not from the difference of the rest of the World and the state polygon as above. There is a usage example in https://mapserver.org/development/rfc/ms-rfc-79.html#rfc79.

 NAME "parcels"
 DATA "the_geom from parcels where clientid='%token%'"
   COLOR 0 0 0

 NAME "meteo"
 DATA "raster.tif"
 MASK "parcels"

Modify the example to use your state polygon as the mask layer and have a try. Please inform if it works because I have never tried it myself.

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.