Skip to content

Commit

Permalink
fix: Process the refs for ways when using a local database (#20)
Browse files Browse the repository at this point in the history
* fix: Process the refs for ways when using a local database

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Rob Savoye <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 24, 2024
1 parent 0f557c8 commit b358100
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions osm_rawdata/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ def createSQL(
select += f"tags->>'{k1}', "
select = select[:-2]

# If a way, we need the refs for conflating with JOSM
if table == "ways_poly":
select += ", refs "

join_or = list()
join_and = list()
for entry in config.config["where"][table]:
Expand Down Expand Up @@ -493,35 +497,28 @@ def queryLocal(
if len(item) <= 1 and len(result) == 1:
return result
# break
geom = wkt.loads(item[0])
# print(f"{item}")
tags = dict()
tags["id"] = item[1]
geom = wkt.loads(item[0])
# tags["id"] = item[1]
tags["version"] = item[2]
if query.find(" refs ") > 0:
tags["refs"] = str(item[len(item) - 1])
# breakpoint()
i = 3
# If there are no tables, we're using a custom SQL query
if len(self.qc.config["tables"]) > 0:
# map the value in the select to the values returns for them.
for _table, values in self.qc.config["select"].items():
for entry in values:
if i == len(item):
break
[[k, v]] = entry.items()
if item[i] is not None:
tags[k] = item[i]
i += 1
else:
# Figure out the tags from the custom SELECT
end = query.find("FROM")
res = query[:end].split(" ")
# This should be the geometry
geom = wkt.loads(item[0])
# This should be the OSM ID
tags[res[2][:-1]] = item[1]
# This should be the version
tags[res[3][:-1]] = item[2]
# Figure out the tags from the SELECT part of the query
keys = query.replace(",", "").replace("tags->>", "").replace("'", "")
end = keys.find("FROM")
res = keys[:end].split(" ")
# This should be the geometry
geom = wkt.loads(item[0])
for i in range(2, len(item)):
# print(f"{res[i]} = {item[i - 1]}")
if item[i - 1] is None:
continue
tags[res[i]] = item[i - 1]
features.append(Feature(geometry=geom, properties=tags))
return FeatureCollection(features)
# return features

def queryRemote(
self,
Expand Down Expand Up @@ -854,7 +851,7 @@ def main():
log.info(f"Canned Query returned {len(result['features'])} records")

outfile = open(args.outfile, "w")
geojson.dump(result, outfile)
geojson.dump(result, outfile, indent=4)

log.debug(f"Wrote {args.outfile}")

Expand Down

0 comments on commit b358100

Please sign in to comment.