문제

Im newbie in python, so excuse me for this newbie question. I have a class and a function:

class Datasource(mapnik.PythonDatasource):
    def __init__(self):
        super(Datasource, self).__init__()

    def features(self, query):
        return mapnik.PythonDatasource.wkb_features(mvt)

def tileLayer(request, version, shapefile_id, zoom, x, y):
    mvt = requestHandler(request, zoom, x, y)

    datasource = mapnik.Python(factory='Datasource')

How can I pass the mvt variable to the Datasource class when calling mapnik.Python(factory='Datasource')

도움이 되었습니까?

해결책

You can add additional arguments to mapnik.Python method - they will be passed to datasource __init__:

mvt = requestHandler(request, zoom, x, y)
datasource = mapnik.Python(factory='Datasource', mvt=mvt)

add argument to Datasource class __init__ method definition and use it to save mvt in class instance:

class Datasource(mapnik.PythonDatasource):
    def __init__(self, mvt):
        super(Datasource, self).__init__()
        self.mvt = mvt

    def features(self, query):
        return mapnik.PythonDatasource.wkb_features(self.mvt)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top