python - 如何将变量传递给mapnik数据源类?

标签 python mapnik

我是Python新手,所以请原谅我回答这个新手问题。我有一个类和一个函数:

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')

调用mapnik.Python(factory='Datasource')时,如何将mvt变量传递给Datasource

最佳答案

您可以向 mapnik.Python 方法添加其他参数 - 它们将被传递到数据源 __init__:

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

Datasource__init__方法定义添加参数,并使用它在类实例中保存mvt:

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)

关于python - 如何将变量传递给mapnik数据源类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21973478/

相关文章:

C#:python 文件中的类反射机制(获取函数、参数等)

C++ mapnik 未定义对规则的引用

makefile - 由于 icuuc 无法配置 Mapnik

node.js - 错误 : cannot find module 'mime'

python - 有没有办法从类中删除 __bool__ 方法?

python - 使用tensorflow和numpy时出现奇怪的数据类型错误

python 3.3.4 : python-daemon-3K ; How to use runner

Python 不按顺序打印消息

gis - 使用 Mapnik 将 osm 数据转换为 png

redis - 如何在 redis (Mapnik) 中存储 postgis 数据源?