-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from olincollege/sv-silver
Added a silverdb folder and crosswalk code
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from night_light.bronze_db.util import connect_to_duckdb | ||
|
||
def generate_silver_crosswalks() -> None: | ||
""" | ||
Creates crosswalk table for the silver database | ||
Rewrites pervious verison of the table if it exists. | ||
""" | ||
db_path = "silver.db" | ||
conn = connect_to_duckdb(db_path) | ||
conn.execute("ATTACH DATABASE 'bronze.db' AS bronze") | ||
|
||
query = """ | ||
DROP TABLE IF EXISTS crosswalks; | ||
CREATE TABLE crosswalks AS | ||
SELECT OBJECTID, Class_Loc, CrossType, geometry | ||
FROM bronze.crosswalks; | ||
""" | ||
|
||
conn.execute(query) | ||
print("Silver table regenerated for crosswalks") | ||
|
||
if __name__ == "__main__": | ||
generate_silver_crosswalks() |