0

I write some python functions to read/write simple spatial data like points, polygons, triangulated surfaces into/from a simple data structure in Python. I'm aware there are some possibilities to access those data structure from C or C++ like in this post: Passing Python list to C++ vector using Boost.python

However, I'm not an experienced programmer using templates and I would like to start first with an easy way - if it exist. So if I have a list of point objects (see simple class definition), how would I access this list from a C-Program reading the respective variables.

class point3d():

def __init__(self, objectName, version, id=[], xyz=[], prop=[], unit=[], val=[]):
    self.id = id
    self.xyz = xyz
    self.prop = prop
    self.unit = unit
    self.val = val
    dim = len(self.xyz)
    self.objectName = objectName
    self.version = version
    if dim == 1:
        self.x = self.xyz[0]
    elif dim == 2:
        self.x = self.xyz[0]
        self.y = self.xyz[1]
    elif dim == 3:
        self.x = self.xyz[0]
        self.y = self.xyz[1]
        self.z = self.xyz[2]

def __del__(self):
    pass

def getObjectName(self):
    return self.objectName

def getVersion(self):
    return self.version

def getXYZ(self):
    return self.xyz

def getDim(self):
    return self.dim

def getProp(self):
    return self.prop

def getUnit(self):
    return self.unit

def getVal(self):
    return self.val

def getId(self):
    return self.id

1 Answer 1

1

If you want to call a C/C++ function from your python program, ctypes is the way to go.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.