[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/avinet/MapServer/main/src/mapscript/python/pymodule.i [Back]  [Original]

/******************************************************************************
 * Project:  MapServer
 * Purpose:  Python-specific enhancements to MapScript
 * Author:   Sean Gillies, sgillies@frii.com
 *
 ******************************************************************************
 *
 * Python-specific mapscript code has been moved into this 
 * SWIG interface file to improve the readability of the main
 * interface file.  The main mapscript.i file includes this
 * file when SWIGPYTHON is defined (via 'swig -python ...').
 *
 *****************************************************************************/

/******************************************************************************
 * Simple Typemaps
 *****************************************************************************/

/* Translates Python None to C NULL for strings */
//%typemap(in,parse="z") char * "";

/* To support imageObj::getBytes */
%typemap(out) gdBuffer {
    $result = PyBytes_FromStringAndSize((const char*)$1.data, $1.size);
    if( $1.owns_data )
       msFree($1.data);
}


/*
 *  Typemap for counted arrays of doubles code;
    errmsg = msGetErrorString("\n");
    
    switch (errcode) {
        case MS_IOERR:
            PyErr_SetString(PyExc_IOError, errmsg);
            break;
        case MS_MEMERR:
            PyErr_SetString(PyExc_MemoryError, errmsg);
            break;
        case MS_TYPEERR:
            PyErr_SetString(PyExc_TypeError, errmsg);
            break;
        case MS_EOFERR:
            PyErr_SetString(PyExc_EOFError, errmsg);
            break;
        case MS_CHILDERR:
            PyErr_SetString(MSExc_MapServerChildError, errmsg);
            break;
        default:
            PyErr_SetString(MSExc_MapServerError, errmsg);
            break;
    }

    free(errmsg);
}
  
%}

%exception {
    $action {
        errorObj *ms_error = msGetErrorObj();
       
        switch(ms_error->code) {
            case MS_NOERR:
                break;
            case MS_NOTFOUND:
                msResetErrorList();
                break;
            case -1:
                break;
            case MS_IOERR:
                /*
                if (strcmp(ms_error->routine, "msSearchDiskTree()") != 0) {
                    _raise_ms_exception();
                    msResetErrorList();
                    return NULL;
                }
                */
            default:
                _raise_ms_exception();
                msResetErrorList();
                return NULL;
        }
                
    }
}
         
%pythoncode %{
MapServerError = _mapscript.MapServerError
MapServerChildError = _mapscript.MapServerChildError
%}

%feature("pythonappend") layerObj %{
    self.p_map = None
    if map: 
        self.p_map = map%}

%feature("pythonappend") classObj %{
    self.p_layer = None
    if layer: 
        self.p_layer = layer%}

%feature("shadow") insertClass %{
    def insertClass(*args):
        """
        Insert a **copy** of the class into the layer at the requested *index*. 
        Default index of -1 means insertion at the end of the array of classes. Returns the index at which the class was inserted.
        """
        actualIndex=$action(*args)
        args[1].p_layer=args[0]
        return actualIndex%}


%feature("shadow") getClass %{
    def getClass(*args):
        """
        Fetch the requested class object at *i*. Returns NULL if the class index is out of the legal range. 
        The numclasses field contains the number of classes available, and the first class is index 0.
        """
        clazz = $action(*args)
        if clazz:
            if args and len(args)!=0:
                clazz.p_layer=args[0]
            else:
                clazz.p_layer=None
        return clazz%}

%feature("shadow") insertLayer %{
    def insertLayer(*args):
        """
        Insert a copy of *layer* into the map at *index*.
        The default value of *index* is -1, which means the last possible index. 
        Returns the index of the new layer, or -1 in the case of a failure.
        """
        actualIndex=$action(*args)
        args[1].p_map=args[0]
        return actualIndex%}

%feature("shadow") getLayer %{
    def getLayer(*args):
        """
        Returns a reference to the layer at index *i*.
        """
        layer = $action(*args)
        if layer:
            if args and len(args)!=0:
                layer.p_map=args[0]
            else:
                layer.p_map=None
        return layer%}

%feature("shadow") getLayerByName %{
    def getLayerByName(*args):
        """
        Returns a reference to the named layer.
        """
        layer = $action(*args)
        if layer:
            if args and len(args)!=0:
                layer.p_map=args[0]
            else:
                layer.p_map=None
        return layer%}

Web Proxy Viewer  |  New URL  |  Original Page