Baltimore Buildings Import
Work In Progress
This import is currently being worked on.
This page intends to detail the process of importing building outlines provided by the City of Baltimore. Addresses will be assigned using a parcel map.
Building outlines source: https://data.baltimorecity.gov/Geographic/Building-Footprint-Shape/deus-s85f
Parcel map source: https://data.baltimorecity.gov/Geographic/Parcels-Shape/jk3c-vrfy
Import Data into Database
- Create Postgres database named "buildings".
-- Add PostGIS extensions create extension postgis;
- Import buildings Shapefile and add "cleanGeometry" function.
shp2pgsql -s 2248 building.shp buildings | psql -d buildings psql -d buildings < cleanGeometry.sql
Simplify Outlines while Preserving Topology
-- Extract multipolygons into polygons create table poly as ( select gid, (st_dump(geom)).* from buildings ); create index poly_geom_gist on poly using GIST(geom); -- Extract rings out of polygons create table rings as ( select st_exteriorRing((st_dumpRings(geom)).geom) as geom from poly ); create index rings_geom_gist on rings using GIST(geom); -- Simplify rings (takes a long time) create table simplerings as ( select st_simplifyPreserveTopology(st_linemerge(st_union(geom)), 0.000001) as geom from rings ); create index simplerings_geom_gist on simplerings using GIST(geom); -- Extract lines from simplified rings create table simplelines as ( select (st_dump(geom)).geom as geom from simplerings ); create index simplelines_geom_gist on simplelines using GIST(geom); -- Rebuild polygons from lines (takes a long time) create table simplepolys as ( select (st_dump(st_polygonize(distinct geom))).geom as geom from simplelines ); alter table simplepolys add column gid serial primary key; create index simplepolys_geom_gist on simplepolys using gist(geom); -- Clean building geometry create table simple_buildings as (SELECT cleangeometry(geom) as geom FROM simplepolys); -- Remove interior courtyards (takes a long time) create table bunion as (select (ST_Dump(ST_Union(ST_MakeValid(geom)))).* as geom from poly); delete from simple_buildings where not exists ( select * from bunion where st_intersects(bunion.geom, simple_buildings.geom) and st_area(st_intersection(bunion.geom, simple_buildings.geom))/st_area(simple_buildings.geom) > 0.5 );
Validate Simplified Data
Manually review and fix validation errors and warnings.