Skip to content

Commit

Permalink
Load sources with explicit geometry srids and update tax_lot table im…
Browse files Browse the repository at this point in the history
…port (#16)
  • Loading branch information
pratishta authored Mar 18, 2024
1 parent 3b16b80 commit e07ce1c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 68 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,16 @@ psql ${BUILD_ENGINE_URI} \
dbt test --select "source:*"
```

### Create tables
psql ${BUILD_ENGINE_URI} \
--set ON_ERROR_STOP=1 --single-transaction --quiet \
--file create_tables.sql \
--variable SCHEMA_NAME=${BUILD_ENGINE_SCHEMA}

### Populate tables
psql ${BUILD_ENGINE_URI} \
--set ON_ERROR_STOP=1 --single-transaction --quiet \
--file import_tables.sql \
--variable SCHEMA_NAME=${BUILD_ENGINE_SCHEMA}

### TBD
10 changes: 0 additions & 10 deletions create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,3 @@ DO $$ BEGIN
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

CREATE TABLE IF NOT EXISTS "pluto" (
"bbl" text PRIMARY KEY NOT NULL,
"borough_id" char(2) NOT NULL,
"block" text NOT NULL,
"lot" text NOT NULL,
"address" text,
"land_use_id" char(2),
"wkt" text
);
98 changes: 42 additions & 56 deletions import_tables.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
BEGIN;
COPY borough ("id", "title", "abbr")
FROM '../borough.csv'
DELIMITER ','
CSV HEADER;

COMMIT;
COPY borough ("id", "title", "abbr")
FROM '../borough.csv'
DELIMITER ','
CSV HEADER;

BEGIN;
COPY land_use ("id", "description", "color")
FROM '../land_use.csv'
DELIMITER ','
CSV HEADER;

COMMIT;
COPY land_use ("id", "description", "color")
FROM '../land_use.csv'
DELIMITER ','
CSV HEADER;

INSERT INTO tax_lot
SELECT
Expand All @@ -21,46 +16,37 @@ SELECT
block,
lot,
address,
land_use_id,
ST_GeomFromText(wkt, 4326) as wgs84,
ST_GeomFromText(wkt, 2263) as li_ft
FROM pluto
INNER JOIN borough ON pluto.borough_id=borough.abbr;

BEGIN;
COPY zoning_district (
"id",
"label",
"wgs84",
"li_ft"
)
FROM '../zoning_district.csv'
DELIMITER ','
CSV HEADER;

COMMIT;

BEGIN;
COPY zoning_district_class (
"id",
"category",
"description",
"url",
"color"
)
FROM '../zoning_district_class.csv'
DELIMITER ','
CSV HEADER;

COMMIT;

BEGIN;
COPY zoning_district_zoning_district_class (
"zoning_district_id",
"zoning_district_class_id"
)
FROM '../zoning_district_zoning_district_class.csv'
DELIMITER ','
CSV HEADER;

COMMIT;
land_use as land_use_id,
ST_Transform(wkt, 4326) as wgs84,
wkt as li_ft
FROM source_pluto
INNER JOIN borough ON source_pluto.borough=borough.abbr;

COPY zoning_district (
"id",
"label",
"wgs84",
"li_ft"
)
FROM '../zoning_district.csv'
DELIMITER ','
CSV HEADER;

COPY zoning_district_class (
"id",
"category",
"description",
"url",
"color"
)
FROM '../zoning_district_class.csv'
DELIMITER ','
CSV HEADER;

COPY zoning_district_zoning_district_class (
"zoning_district_id",
"zoning_district_class_id"
)
FROM '../zoning_district_zoning_district_class.csv'
DELIMITER ','
CSV HEADER;
4 changes: 2 additions & 2 deletions sql/load_sources.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS "source_pluto" (
"lot" text NOT NULL,
"address" text,
"land_use" char(2),
"wkt" geometry
"wkt" geometry(MULTIPOLYGON, 2263)
);
CREATE INDEX pluto_geom_idx
ON source_pluto
Expand All @@ -22,7 +22,7 @@ CREATE TABLE IF NOT EXISTS "source_zoning_districts" (
"zonedist" text NOT NULL,
"shape_leng" float,
"shape_area" float,
"wkt" geometry
"wkt" geometry(MULTIPOLYGON, 4326)
);
CREATE INDEX zoning_districts_geom_idx
ON source_zoning_districts
Expand Down

0 comments on commit e07ce1c

Please sign in to comment.