_zonalstats.error: Could not open

44 views
Skip to first unread message

Llion Preston

unread,
Oct 3, 2016, 11:08:44 AM10/3/16
to RSGISLib Support, Llion....@armajaro.com
Hi,

Receiving the error below when trying to use the pixelStats2SHP tool. I've used the tool before but can't seem to be able to get it to work so may very well be a syntax error (apologies if so). I have also tried updating my conda environment and using the new au-osgeo-lnx-env.

import rsgislib
from rsgislib import zonalstats
from rsgislib import rastergis

# calculate pixel stats to txt
inputimage = 'NDVI_19052015.tif'
inputvector = 'corn_aoi.shp'
outputvector = 'corn_stats1.shp'

zonalattributes = zonalstats.ZonalAttributes(minThreshold=0, maxThreshold=2, calcCount=False,\
calcMin=False, calcMax=False, calcMean=True, calcStdDev=True, calcMode=False, calcSum=False)

zonalstats.pixelStats2SHP(inputimage, inputvector, outputvector, zonalattributes, True, True, True, zonalstats.METHOD_POLYCONTAINSPIXELCENTER)

-
-
python ./zonal_stats.py Calculating: mean, stdDev, for pixels with values between 0 and 2.
and pixelcount for all pixels in polygon.
Could not open
Traceback (most recent call last):
  File "./zonal_stats.py", line 13, in <module>
    zonalstats.pixelStats2SHP(inputimage, inputvector, outputvector, zonalattributes, True, True, True, zonalstats.METHOD_POLYCONTAINSPIXELCENTER)
_zonalstats.error: Could not open


Daniel Clewley

unread,
Oct 3, 2016, 3:26:08 PM10/3/16
to Llion Preston, RSGISLib Support, Llion....@armajaro.com
Hi Llion,

This error sounds like it isn’t finding the input image or vector. Try adding the following lines before running the zonalstats.pixelStats2SHP to check the files exist:

import os
import sys

if not os.path.isfile(inputimage):
    print(“Could not find input image”)
    sys.exit(1)
if not os.path.isfile(inputvector):
    print(“Could not find input vector”)
    sys.exit(1)

Thanks,

Dan

--
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.

Llion Preston

unread,
Oct 4, 2016, 4:17:59 AM10/4/16
to RSGISLib Support, llion....@gmail.com, Llion....@armajaro.com
Hi Dan,

Thanks for your help, it was a silly file naming mistake - looks like a useful bit of code to stop future silly mistakes of that kind. Unfortunately now getting the following error:

(au-osgeo-lnx) lpreston@wvcs-ubu01:~/Desktop/aoi_stats$ python ./zonal_stats.py Calculating: mean, stdDev, for pixels with values between 0 and 2.

and pixelcount for all pixels in polygon.
Could not open
Traceback (most recent call last):
  File "./zonal_stats.py", line 22, in <module>

    zonalstats.pixelStats2SHP(inputimage, inputvector, outputvector, zonalattributes, True, True, True, zonalstats.METHOD_POLYCONTAINSPIXELCENTER)
_zonalstats.error: Could not open

Thanks,
Llion

Pete Bunting [pfb]

unread,
Oct 4, 2016, 10:20:34 AM10/4/16
to Llion Preston, RSGISLib Support, Llion....@armajaro.com
Hi Llion, 

Have you checked the output file path? Sounds like a similar error as before. 

Cheers, 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”


--------------------------------------------------------------------
Un o’r 4 prifysgol uchaf yn y DU a’r gorau 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

Llion Preston

unread,
Oct 4, 2016, 11:39:00 AM10/4/16
to RSGISLib Support, llion....@gmail.com, Llion....@armajaro.com, p...@aber.ac.uk
Hi Pete,

You were right, I hadn't fully specified the file path to the output vector. Thanks again for your help

Llion
To post to this group, send email to rsgisli...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages