Beispiel #1
0
def check_string(result, func, cargs, offset=-1, str_result=False):
    """
    Checks the string output returned from the given function, and frees
    the string pointer allocated by OGR.  The `str_result` keyword
    may be used when the result is the string pointer, otherwise
    the OGR error code is assumed.  The `offset` keyword may be used
    to extract the string pointer passed in by-reference at the given
    slice offset in the function arguments.
    """
    if str_result:
        # For routines that return a string.
        ptr = result
        if not ptr:
            s = None
        else:
            s = string_at(result)
    else:
        # Error-code return specified.
        check_err(result)
        ptr = ptr_byref(cargs, offset)
        # Getting the string value
        s = ptr.value
    # Correctly freeing the allocated memory beind GDAL pointer
    # w/the VSIFree routine.
    if ptr:
        lgdal.VSIFree(ptr)
    return s
Beispiel #2
0
def check_arg_errcode(result, func, cargs):
    """
    The error code is returned in the last argument, by reference.
    Check its value with `check_err` before returning the result.
    """
    check_err(arg_byref(cargs))
    return result
Beispiel #3
0
def check_const_string(result, func, cargs, offset=None):
    """
    Similar functionality to `check_string`, but does not free the pointer.
    """
    if offset:
        check_err(result)
        ptr = ptr_byref(cargs, offset)
        return ptr.value
    else:
        return result
Beispiel #4
0
def check_geom_offset(result, func, cargs, offset=-1):
    "Chcks the geometry at the given offset in the C parameter list."
    check_err(result)
    geom = ptr_byref(cargs, offset=offset)
    return check_geom(geom, func, cargs)
Beispiel #5
0
def check_errcode(result, func, cargs):
    """
    Check the error code returned (c_int).
    """
    check_err(result)
    return