diff --git a/analysers/Analyser_Merge.py b/analysers/Analyser_Merge.py index 76973ded0..99ff62e9d 100644 --- a/analysers/Analyser_Merge.py +++ b/analysers/Analyser_Merge.py @@ -540,7 +540,7 @@ def __init__(self, source): class Load(object): def __init__(self, x = ("NULL",), y = ("NULL",), srid = 4326, table_name = None, create = None, - select = {}, uniq = None, where = lambda res: True, xFunction = lambda i: i, yFunction = lambda i: i): + select = {}, uniq = None, where = lambda res: True, map = lambda i: i, xFunction = lambda i: i, yFunction = lambda i: i): """ Describ the conversion of data set loaded with COPY into the database into an other table more usable for processing. @param x: the name of x column, as or converted to longitude, can be a SQL expression formatted as ("SQL CODE",) @@ -551,6 +551,7 @@ def __init__(self, x = ("NULL",), y = ("NULL",), srid = 4326, table_name = None, @param select: dict reformatted as SQL to filter row import before conversion, prefer this as the where param @param uniq: select distinct by column list @param where: lambda expression taking row as dict and returning boolean to determine whether or not inserting the row into the table + @param map: lambda return a replace record @param xFunction: lambda expression for convert x content column before reprojection, identity by default @param yFunction: lambda expression for convert y content column before reprojection, identity by default """ @@ -562,6 +563,7 @@ def __init__(self, x = ("NULL",), y = ("NULL",), srid = 4326, table_name = None, self.select = select self.uniq = uniq self.where = where + self.map = map self.xFunction = xFunction self.yFunction = yFunction @@ -642,9 +644,12 @@ def setData(res): giscurs_getpoint = osmosis.gisconn.cursor(cursor_factory=psycopg2.extras.DictCursor) mult_space = re.compile(r'\s+') def insertOfficial(res): - x = self.xFunction(res[0]) - y = self.yFunction(res[1]) - if (not self.pip or (x and y)) and self.where(res): + if not self.where(res): + return + res = self.map(res) + x = self.xFunction(res['_x']) + y = self.yFunction(res['_y']) + if not self.pip or (x and y): is_pip = False if self.pip: giscurs_getpoint.execute("SELECT ST_AsText(ST_Transform(ST_SetSRID(ST_MakePoint(%(x)s, %(y)s), %(SRID)s), 4326))" % {"x": x, "y": y, "SRID": self.srid}) diff --git a/analysers/analyser_merge_power_plant_FR.py b/analysers/analyser_merge_power_plant_FR.py index fab17704e..97bc91ee0 100644 --- a/analysers/analyser_merge_power_plant_FR.py +++ b/analysers/analyser_merge_power_plant_FR.py @@ -25,6 +25,7 @@ from .Analyser_Merge import Analyser_Merge, Source, CSV, Load, Mapping, Select, Generate from .Analyser_Merge_Geocode_Addok_CSV import Geocode_Addok_CSV from .modules import downloader +from .modules import Stablehash class Analyser_Merge_Power_Plant_FR(Analyser_Merge): @@ -39,7 +40,8 @@ def __init__(self, config, logger = None): columns = 'Commune', citycode = 'codeINSEECommune', delimiter = ';', logger = logger), separator = u";"), Load("longitude", "latitude", - where = lambda res: res.get('max_puissance') and float(res["max_puissance"]) > 1000), + where = lambda res: res.get('max_puissance') and float(res["max_puissance"]) > 1000, + map = lambda res: dict(res, **{"_x": float(res["_x"]) + (Stablehash.stablehash(str(res)) % 200 - 100) * 0.00001, "_y": float(res["_y"]) + (Stablehash.stablehash(str(res)) % 212 - 106) * 0.00001})), Mapping( select = Select( types = ["ways", "relations"],