Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
fix: Uses Geometry() instead of point or polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
rsavoye committed Jan 4, 2024
1 parent 86e8e62 commit 3fbadd0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
12 changes: 6 additions & 6 deletions tm_admin/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def __init__(self,
'string': 'character varying',
'bytes': 'bytea',
'timestamp': 'timestamp without time zone',
'polygon': 'polygon',
'point': 'point',
'polygon': 'geometry(Polygon,4326)',
'point': 'geometry(Point,4326)',
'json': 'json',
}

Expand Down Expand Up @@ -303,10 +303,10 @@ def createSQLTable(self):
for line in values:
# these are usually from the types.yaml file, which have no
# settings beyond the enum value.
# if type(line) == str:
# print(f"SQL TABLE: {typedef} {line}")
# typedef = table
# continue
if type(line) == str:
# print(f"SQL TABLE: {typedef} {line}")
typedef = table
continue
[[k, v]] = line.items()
required = ""
array = ""
Expand Down
24 changes: 13 additions & 11 deletions tm_admin/tmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ def writeAllData(self,
return True

builtins = ['int32', 'int64', 'string', 'timestamp', 'bool']
#bar = Bar('Importing into TMAdmin', max=len(data))
# columns2 = self.getColumns(table)
pbar = tqdm(data)
for record in pbar:
# for record in data:
Expand Down Expand Up @@ -259,15 +257,14 @@ def writeAllData(self,
# If it's not a standard datatype, it's an enum in types_tm.py
if self.config[key]['datatype'] not in builtins:
if self.config[key]['datatype'] == 'point':
geom = get_coordinates(wkb.loads(val))
values += f"point({geom[0][0]}, {geom[0][1]}), "
geom = wkb.loads(val)
# values += f"point({geom[0][0]}, {geom[0][1]}), "
values += f"{geom.geoms[0].wkb_hex}, "
continue
elif self.config[key]['datatype'] == 'polygon':
geom = get_coordinates(wkb.loads(val))
poly = ''
for x, y in geom:
poly += f"({x},{y}), "
values += f"polygon('({poly[:-2]})'), "
geom = wkb.loads(val)
values += f"'{geom.geoms[0].wkb_hex}', "
# values += f"polygon('({poly[:-2]})'), "
continue
elif type(val) == list:
values += "'{"
Expand Down Expand Up @@ -419,13 +416,13 @@ def main():
# dump python, or have performance issues. Past a certain threshold
# the data needs to be queried in pages instead of the entire table.
if entries > threshold:
# importThread(data, tmpg[0], doit)
with concurrent.futures.ThreadPoolExecutor(max_workers=cores) as executor:
index = 0
for block in range(0, entries, chunk):
data = doit.getPage(block, chunk)
page = round(len(data) / cores)
# log.debug(f"Dispatching Block {index}")
# importThread(data, tmpg[0], doit)
result = executor.submit(importThread, data, tmpg[index], doit)
index += 1
executor.shutdown()
Expand All @@ -450,11 +447,16 @@ def main():
block = 0
while block <= entries:
log.debug("Dispatching Block %d:%d" % (block, block + chunk))
result = executor.submit(importThread, data[block : block + chunk], tmpg[index], doit)
importThread(data, tmpg[0], doit)
# result = executor.submit(importThread, data[block : block + chunk], tmpg[index], doit)
block += chunk
index += 1
executor.shutdown()

# cleanup the connections
#for conn in tmpg:
# conn.close()

if __name__ == "__main__":
"""This is just a hook so this file can be run standalone during development."""
main()

0 comments on commit 3fbadd0

Please sign in to comment.