Skip to content

Commit

Permalink
fix: Improve how the boundary gets parese dand passed as a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
robsavoye committed Sep 16, 2023
1 parent 963207d commit 6e8aa13
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions osm_fieldwork/make_data_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self,
self.xls = BytesIO(file.read())

def getFeatures(self,
boundary: str,
boundary: FeatureCollection,
polygon: bool,
):
"""
Expand All @@ -120,18 +120,13 @@ def getFeatures(self,
"""
log.info("Extracting features from Postgres...")

if type(boundary) != dict:
clip = open(boundary, "r")
geom = geojson.load(clip)
if 'features' in geom:
poly = geom['features'][0]['geometry']
else:
poly = geom["geometry"]
if 'features' in boundary:
poly = boundary['features'][0]['geometry']
else:
poly = boundary
poly = boundary["geometry"]
wkt = shape(poly)

collection = self.db.execQuery(geom)
collection = self.db.execQuery(boundary)
if not collection:
return None

Expand All @@ -150,8 +145,9 @@ def cleanFeatures(self,
(FeatureCollection): The modifed data
"""
log.debug("Cleaning features")
cleaned = FilterData()
cleaned.parse(self.xls)
cleaned.parse(self.xls, self.db.qc.config)
new = cleaned.cleanData(collection)
#jsonfile = open(filespec, "w")
#dump(new, jsonfile)
Expand Down Expand Up @@ -214,7 +210,7 @@ def main():
quit()

# if verbose, dump to the terminal.
if args.verbose is not None:
if args.verbose:
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
Expand All @@ -225,7 +221,9 @@ def main():
log.addHandler(ch)

extract = MakeExtract(args.uri, args.config, args.xlsfile)
data = extract.getFeatures(args.boundary, args.polygon)
file = open(args.boundary, 'r')
poly = geojson.load(file)
data = extract.getFeatures(poly, args.polygon)
log.debug(f"Query returned {len(data['features'])} features")
# FIXME: just for debugging before filtering!
# if len(data['features']) > 0:
Expand All @@ -234,6 +232,7 @@ def main():
# jsonfile.close()

cleaned = extract.cleanFeatures(data)

jsonfile = open(args.geojson, "w")
dump(cleaned, jsonfile)
jsonfile.close()
Expand Down

0 comments on commit 6e8aa13

Please sign in to comment.