Skip to content

Commit

Permalink
Fuzzy geocoding results at municipality level in analyser_merge_power…
Browse files Browse the repository at this point in the history
…_plant_FR osm-fr#510
  • Loading branch information
frodrigo committed Jun 17, 2019
1 parent a646710 commit 098e9d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 9 additions & 4 deletions analysers/Analyser_Merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",)
Expand All @@ -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
"""
Expand All @@ -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

Expand Down Expand Up @@ -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})
Expand Down
4 changes: 3 additions & 1 deletion analysers/analyser_merge_power_plant_FR.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"],
Expand Down

0 comments on commit 098e9d9

Please sign in to comment.