polygoniseRaster is not working

178 views
Skip to first unread message

Sam Alaee

unread,
Feb 7, 2017, 2:57:25 PM2/7/17
to RSGISLib Support
I tried to segment my image by segutils.runShepherdSegmentation() and then I got 2 KEA files. Then I tried to view them by tuiview and it worked fine. 
In OTB, for segmentation, we can produce vector (shapefile), but here the output of segmentation is 2 KEA files, so I tried to use polygoniseRaster() to get a shape file but apparently it is not working.

This is my code:
from rsgislib import vectorutils

# Create variables for input and output datasets
inputImg = 'C:/input/Small_clumps_elim_final.kea'
outShp
= 'C:/output/5band_shape.shp'

vectorutils.polygoniseRaster(inputImg, outShp, imgBandNo=1,
                             maskImg=inputImg, imgMaskBandNo=1)

and I get the following error:

Using mask
Traceback (most recent call last):
  File "C:/shape_generator.py", line 8, in <module>
    maskImg=inputImg, imgMaskBandNo=1)
  File "C:\Anaconda3\lib\site-packages\rsgislib\vectorutils\__init__.py", line 176, in polygoniseRaster
    gdal.Polygonize(imgBand, imgMaskBand, outLayer, dstFieldIdx, [], callback=gdal.TermProgress )
  File "C:\Anaconda3\lib\site-packages\osgeo\gdal.py", line 2679, in Polygonize
Polygonising...
    return _gdal.Polygonize(*args, **kwargs)
RuntimeError: Object given is not a Python function

I'm running this script on Windows 64bit  and Anaconda (Python 3.4).

Daniel Clewley

unread,
Feb 7, 2017, 3:13:40 PM2/7/17
to Sam Alaee, RSGISLib Support
Hi Sam,

The error looks like it is coming from GDAL. If you run gdal_polygonize.py (http://www.gdal.org/gdal_polygonize.html) instead of the RSGISLib function does this produce an error?

Do you know if the same script works under Linux / OS X? As Pete mentioned the Windows build is a beta release so there could be problems which as specific to Windows.

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.

Sam Alaee

unread,
Feb 7, 2017, 3:21:30 PM2/7/17
to RSGISLib Support, ghasse...@gmail.com
Hi Dan,

The thing is that I am able to use gdal_polygonize.py directly when I want to work with GeoTiff and reading each rasterbands. In that case, I use something like this:

gdal.Polygonize(temp_band, None, dst_layer, -1, [], callback=None)

which the callback is assigned to None. I think the problem in RSGISLib is that the call back is callback=gdal.TermProgress which I don't know what it is.

Daniel Clewley

unread,
Feb 8, 2017, 8:10:14 AM2/8/17
to Sam Alaee, RSGISLib Support
Hi Sam,

I suspect using TermProgress is something which works fine on Linux and OS X but not windows - have made a note to look into.

Thanks,

Dan

Julien FAURE

unread,
May 25, 2018, 4:56:51 AM5/25/18
to RSGISLib Support
Hi, 
I'd like to highlight this subject because i tried to vectorize the result of my segmentation, but i have the same problem than Sam. 
I can see correctly the result of my segmentation using Tuiview, but i can-t vectorize the .kea file generated.
I tried using vectorutils.polygoniseRaster and also using gdal_polygonise. The error occurs in both cases.
My system is based on Win10 64 bits, anaconda 3.5.1.

Is there any solution?
Thanks
Regards, 
Julien
Reply all
Reply to author
Forward
0 new messages