subset an image with vector boundary (not extent)

29 views
Skip to first unread message

Girish Kumar

unread,
Jan 4, 2017, 2:36:16 AM1/4/17
to RSGISLib Support
Dear all,

           Is it possible to subset an image to the boundary of a vector instead of vector extent(assume that the vector has a single polygon feature). I have tried the rsgislib.imageutils.subset function, but the output image is the subset with vector extent. Kindly give your suggestion

With Warm Regards
Girish

Pete Bunting [pfb]

unread,
Jan 4, 2017, 6:31:22 PM1/4/17
to Girish Kumar, RSGISLib Support
Hi Girish,

You have a couple of options:

1. rsgislib.imageutils.subset2polys() - cuts out an image for each polygon within the shapefile (masking to the polygon shape). However, you might end up with multiple output images and you only provide the output base name so can be more tricky within a longer script where your output will be used in the next stage of processing.

2. using rsgislib.imageutils.subset subset the image to the extent of the shapefile and then mask that file. You can create a raster mask using the rsgislib.vectorutils.rasterise2Image function (the input image is the subsetted image) and apply it with rsgislib.imageutils.maskImage.

I would probably go with the second option as a valid area mask image quite often comes in useful.

Best wishes,

Pete

****************************************************
* Dr Pete Bunting
* Reader in Remote Sensing
* Earth Observation and Ecosystem Dynamics Group
* Department of Geography and Earth Sciences
* Aberystwyth University
* Aberystwyth
* Ceredigion
* SY23 3DB
* UK
*
* Ph: +44 (0) 1970 622615
* Mob: +44 (0) 7917 842743
* Email: p...@aber.ac.uk
* ORCID: http://orcid.org/0000-0002-7435-0148
****************************************************
"Please consider the environment before printing this email or any documents attached”
> --
> You received this message because you are subscribed to the Google Groups "RSGISLib Support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rsgislib-suppo...@googlegroups.com.
> To post to this group, send email to rsgislib...@googlegroups.com.
> Visit this group at https://groups.google.com/group/rsgislib-support.
> For more options, visit https://groups.google.com/d/optout.



--------------------------------------------------------------------
Un o’r 4 prifysgol uchaf yn y DU a’r orau yng Nghymru am fodlonrwydd myfyrwyr.
(Arolwg Cenedlaethol y Myfyrwyr 2016)
www.aber.ac.uk

Top 4 UK university and best in Wales for student satisfaction
(National Student Survey 2016)
www.aber.ac.uk

Girish Kumar

unread,
Jan 4, 2017, 10:51:23 PM1/4/17
to RSGISLib Support, giris...@gmail.com, p...@aber.ac.uk
Dear Pete,

          Thank you for your quick reply and suggestions. I have used the gdalwarp function to accomplish it.

gdalwarp -cutline path/to/boundary.shp -crop_to_cutline -dstnodata "0.0" inputraster.tif outputraster.tif

I will try your suggestions also.

Thanks and Regards
Girish
Reply all
Reply to author
Forward
0 new messages