Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 24, 2024
1 parent bdaf472 commit 0da7e80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
3 changes: 1 addition & 2 deletions osm_rawdata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ def convert_geometry(geom_type):
return self.config

def getKeys(self):
"""
"""
""" """
keys = list()
# The first column returned is always the geometry
keys.append("geometry")
Expand Down
31 changes: 15 additions & 16 deletions osm_rawdata/pgasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from io import BytesIO
from pathlib import Path
from urllib.parse import urlparse
import flatdict

import asyncpg
import geojson
Expand Down Expand Up @@ -201,11 +200,11 @@ async def createJson(
feature["centroid"] = true
return json.dumps(feature)

async def recordsToFeatures(self,
records: list,
) -> list:
"""
Convert an asyncpg.Record to a GeoJson FeatureCollection.
async def recordsToFeatures(
self,
records: list,
) -> list:
"""Convert an asyncpg.Record to a GeoJson FeatureCollection.
Args:
records (list): The records from an SQL query
Expand All @@ -226,7 +225,7 @@ async def recordsToFeatures(self,
elif entry[i] is not None:
props[keys[i]] = entry[i]
i += 1
data.append(Feature(geometry = geom, properties = props))
data.append(Feature(geometry=geom, properties=props))

return data

Expand Down Expand Up @@ -406,8 +405,7 @@ async def execute(
self,
sql: str,
) -> list:
"""
Execute a raw SQL query and return the results.
"""Execute a raw SQL query and return the results.
Args:
sql (str): The SQL to execute
Expand All @@ -417,16 +415,16 @@ async def execute(
"""
# print(sql)
data = list()
if sql.find(';') <= 0:
if sql.find(";") <= 0:
queries = [sql]

async with self.pg.transaction():
queries = list()
# If using an SRID, we have to hide the sem-colon so the string
# doesn't split in the wrong place.
cmds = sql.replace("SRID=4326;P", "SRID=4326@P").split(';')
cmds = sql.replace("SRID=4326;P", "SRID=4326@P").split(";")
for sub in cmds:
queries.append(sub.replace('@', ';'))
queries.append(sub.replace("@", ";"))
continue

for query in queries:
Expand Down Expand Up @@ -650,7 +648,7 @@ async def execQuery(
if "geometry" in boundary:
polygons.append(boundary["geometry"])

if boundary['type'] == "MultiPolygon":
if boundary["type"] == "MultiPolygon":
# poly = boundary["features"][0]["geometry"]
points = list()
for coords in boundary["features"]["coordinates"]:
Expand All @@ -671,7 +669,7 @@ async def execQuery(
alldata = list()
queries = list()
if type(sql) != list:
queries = sql.split(';')
queries = sql.split(";")
else:
queries = sql

Expand All @@ -689,6 +687,7 @@ async def execQuery(

return collection


async def main():
"""This main function lets this class be run standalone by a bash script."""
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -743,10 +742,10 @@ async def main():
if args.boundary:
infile = open(args.boundary, "r")
inpoly = geojson.load(infile)
if inpoly['type'] == "MultiPolygon":
if inpoly["type"] == "MultiPolygon":
poly = FeatureCollection(inpoly)
else:
log.error(f"A boundary file is needed!")
log.error("A boundary file is needed!")

if args.uri is not None:
log.info("Using a Postgres database for the data source")
Expand Down

0 comments on commit 0da7e80

Please sign in to comment.