Clipping a raster (grib2), end up with zeros on left edge when cropping with mask


Shane Mill - NOAA Affiliate
 

Hi everyone,

I am currently clipping a grib2 file, and am ending up with zeros on the left edge of the raster. I'm not an expert with GIS so maybe this is a common problem but was curious if anyone else has experienced this before?
I think the issue is where the mask function is used with the cropping. 

In the picture below, the blue edge shows the zeros.
And for context, here is the driving code that is performing the action:




Sean Gillies
 

Hi Shane,

It looks like your feature geometries extend beyond the extent of your raster, yes? In that case, crop can create an extra row or column of pixels, which will be empty. This seems like a bug to me, or undefined behavior, at least. I suggest passing crop=False in your situation.

On Thu, May 23, 2019 at 8:52 AM Shane Mill - NOAA Affiliate via Groups.Io <shane.mill=noaa.gov@groups.io> wrote:

Hi everyone,

I am currently clipping a grib2 file, and am ending up with zeros on the left edge of the raster. I'm not an expert with GIS so maybe this is a common problem but was curious if anyone else has experienced this before?
I think the issue is where the mask function is used with the cropping. 

In the picture below, the blue edge shows the zeros.
And for context, here is the driving code that is performing the action:





--
Sean Gillies


Shane Mill - NOAA Affiliate
 

Hey Sean,

As always, thanks for the feedback. So to follow up, it turns out that I had to add "filled=False". In my particular situation, the user drags a bounding box over the original raster and is returned with the subsetted raster. With 'filled=False' in out_image, out_transform = mask(src, geoms, filled=False, crop=True), i get the desired result.

Thanks!
Shane Mill

On Fri, May 24, 2019 at 10:00 AM Sean Gillies <sean.gillies@...> wrote:
Hi Shane,

It looks like your feature geometries extend beyond the extent of your raster, yes? In that case, crop can create an extra row or column of pixels, which will be empty. This seems like a bug to me, or undefined behavior, at least. I suggest passing crop=False in your situation.

On Thu, May 23, 2019 at 8:52 AM Shane Mill - NOAA Affiliate via Groups.Io <shane.mill=noaa.gov@groups.io> wrote:
Hi everyone,

I am currently clipping a grib2 file, and am ending up with zeros on the left edge of the raster. I'm not an expert with GIS so maybe this is a common problem but was curious if anyone else has experienced this before?
I think the issue is where the mask function is used with the cropping. 

In the picture below, the blue edge shows the zeros.
And for context, here is the driving code that is performing the action:





--
Sean Gillies



--
Shane Mill

Meteorological Application Developer, AceInfo Solutions

Meteorological Development Laboratory (NWS)

Phone: 301-427-9452