1

I'm new in python. I have a class which opens SXF format, and i want the last string

 self.sxf_ds = gdal.OpenEx(self.sxf_path)

to be opened with flag 'GDAL_OF_VERBOSE_ERROR' but the nOpenFlags is integer not the string. Where i can find the NUMBER of this flag??. In gdal.py for openEx function there is a comment: "OpenEx(char const * utf8_path, unsigned int nOpenFlags=0, char ** allowed_drivers=None, char ** open_options=None, char ** sibling_files=None) -> Dataset"

In gdal help only definition is written: nOpenFlags a combination of GDAL_OF_ flags that may be combined through logical or operator.

  • Driver kind:GDAL_OF_RASTER for raster drivers, GDAL_OF_VECTOR for vector drivers. If none of the value is specified, both kinds are implied.GDAL_OF_RASTER for raster drivers, GDAL_OF_VECTOR for vector drivers. If none of the value is specified, both kinds are implied.
  • Access mode: GDAL_OF_READONLY (exclusive)or GDAL_OF_UPDATE.
  • Shared mode: GDAL_OF_SHARED. If set, it allows the sharing of GDALDataset handles for a dataset with other callers that have set GDAL_OF_SHARED. In particular, GDALOpenEx() will first consult its list of currently open and shared GDALDataset's, and if the GetDescription() name for one exactly matches the pszFilename passed to GDALOpenEx() it will be referenced and returned, if GDALOpenEx() is called from the same thread.
  • Verbose error: GDAL_OF_VERBOSE_ERROR. If set, a failed attempt to open the file will lead to an error message to be reported.

here is a link to gdal docs.

If i write self.sxf_ds = gdal.OpenEx(self.sxf_path,'GDAL_OF_VERBOSE_ERROR') i'm getting an obvious error: TypeError: in method 'OpenEx', argument 2 of type 'unsigned int'. I suppose i need something like that self.sxf_ds = gdal.OpenEx(self.sxf_path,1)or self.sxf_ds = gdal.OpenEx(self.sxf_path,2)

class sxf2dxf(object):
    """docstring for sxf2dxf"""

    def __init__(self, sxf_path, rsc_path, dxf_style_path, dxf_out_path):
        self.sxf_path = sxf_path
        self.rsc_path = rsc_path
        self.dxf_style_path = dxf_style_path
        self.dxf_out_path = dxf_out_path

        self.cls = RSC.parse(rsc_path, cls_type='geom_type')
        tools.MyPrint().pprint(self.cls)
        gdal.SetConfigOption('SXF_RSC_FILENAME', self.rsc_path.encode('utf-8'))
        # gdal.SetConfigOption('SXF_LAYER_FULLNAME', False)  # usage of long layer names

        self.sxf_ds = gdal.OpenEx(self.sxf_path)

1 Answer 1

1

I found solution: self.sxf_ds = gdal.OpenEx(self.sxf_path, gdal.OF_VERBOSE_ERROR, ['SXF']) As i understand: GDAL is C/C++ library and main docs are written for these languages. All methods(functions) and constants are linked via SWIG. gdal.py imports gdalconstants.py and in the second one on line 341 (gdal 2.0.1) there is declaration of "my" constant _gdalconst.OF_VERBOSE_ERROR_swigconstant(_gdalconst) OF_VERBOSE_ERROR = _gdalconst.OF_VERBOSE_ERROR so in python we need to use gdal.OF_VERBOSE_ERROR

1
  • 1
    An explanation of why this worked may be helpful for others having the same issue. Commented Apr 18, 2016 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.