我是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')
如何在调用mvt
Datasource
变量传递给mapnik.Python(factory='Datasource')
类
答案 0 :(得分:1)
您可以向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)