Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial polygon overlap in raster stats #27

Closed
engelmannjens opened this issue Apr 21, 2014 · 10 comments
Closed

Partial polygon overlap in raster stats #27

engelmannjens opened this issue Apr 21, 2014 · 10 comments

Comments

@engelmannjens
Copy link

I am using the raster_stats module in python to calculate the mean carbon value for different sets of polygons. Here is the code that I am using:

africa_sat = 'E:/Research_Work/data/processing_data/carbon_satcchi/data/raw_data/africa_carbon_1km.tif'
name_clipshp = 'data/grid_clipped/' + name_hol + '_grid_cl.shp' # create object to point to clipped grid file

africa_stats = raster_stats(name_clipshp, africa_sat,stats=['mean'])

I have approximately 260 grid surface areas that I am employing. The grid areas have between ~10,000 polygons and ~40,000 polygons in them. Here is the error message I get for some of grids:

Traceback (most recent call last):
File "", line 16, in
File "C:\Python27\lib\site-packages\rasterstats\main.py", line 153, in raster_stats
rvds.SetGeoTransform(new_gt)
AttributeError: 'NoneType' object has no attribute 'SetGeoTransform'

I do not get this error message, if the polygon overlaps completely with the raster image (tiff file) or if the polygon does not at all overlap with the polygon. However, if only a part of the polygon overlaps with the raster I get the error that is above.

Here is a link to a raster and shapefile that created the problem for me:

https://www.dropbox.com/sh/c80v8v576imd09f/7pSGN-p9lS

@perrygeo
Copy link
Owner

Thanks for the report - I'll take a look. Could you put the raster .tif file up on drop box (all I see is the .aux.xml and the .tfw)?

@engelmannjens
Copy link
Author

Thanks for taking a look and for an excellent module -- here is the link for the tiff file:

https://www.dropbox.com/s/5idkituwk0jv3cn/africa_carbon_extr.tif

The other information is in the link above.

Thanks!

@perrygeo
Copy link
Owner

This recent update should fix the issue. The problem was that one row of your polygons was exactly touching (but not overlapping) the raster - a case which I had not protected against.

The code has been updated and the corresponding test ('test_no_overlap') has been updated.

@abersh
Copy link

abersh commented Mar 11, 2016

when upload .tif file to geonode "NoneType' object has no attribute 'GetGeoTransform' " how to fix pls anyone

@perrygeo
Copy link
Owner

@abersh You mention geonode and GetGeoTransform (a GDAL call) which are two unrelated software projects. If you have a question about rasterstats, please specify in more detail and open a new ticket. Thanks.

@abersh
Copy link

abersh commented Mar 11, 2016

@perrygeo now i'm using geonode when uploading raster data in geotiff format the system displayes this erorr *"NoneType' object has no attribute 'GetGeoTransform' " *

@perrygeo
Copy link
Owner

Sorry @abersh , this repository is for python-rasterstats issue only. If you have geonode questions, please take them to the appropriate site: https://github.com/GeoNode/geonode/

@abersh
Copy link

abersh commented Mar 11, 2016

@perrygeo thank you !!!

@naifgeo
Copy link

naifgeo commented Apr 2, 2022

This recent update should fix the issue. The problem was that one row of your polygons was exactly touching (but not overlapping) the raster - a case which I had not protected against.

The code has been updated and the corresponding test ('test_no_overlap') has been updated.

Hello Matthew,
Thank you for your excellent lib
if part of the grids are off the raster boundary will it cause a problem?
i'm using this function :
average_dtm = rasterstats.zonal_stats(Grids_shp, dtm_array,
affine = affine, stats = ['mean', 'min', 'max'],
geojson_out = True)
and the result i got is nonType object instead of the value.

@naifgeo
Copy link

naifgeo commented Apr 2, 2022

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants