mirror of
https://github.com/zyphlar/sonoma-import.git
synced 2024-03-08 15:07:48 +00:00
Update necessary sql
This commit is contained in:
parent
f5bf0bb964
commit
24c15b41e1
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -6,5 +6,8 @@
|
||||||
*.shx
|
*.shx
|
||||||
*.xml
|
*.xml
|
||||||
|
|
||||||
|
# backups
|
||||||
|
original_data-backup.sql
|
||||||
|
|
||||||
# VIM stuff
|
# VIM stuff
|
||||||
*.swp
|
*.swp
|
||||||
|
|
|
@ -12,6 +12,7 @@ CREATE INDEX ON sonoma_county_building_outlines USING GIST (loc_geom);
|
||||||
|
|
||||||
-- added fields for the parcels table
|
-- added fields for the parcels table
|
||||||
ALTER TABLE parcels__public_
|
ALTER TABLE parcels__public_
|
||||||
|
ADD COLUMN "addr:housenumber" text,
|
||||||
ADD COLUMN "addr:street" text,
|
ADD COLUMN "addr:street" text,
|
||||||
ADD COLUMN loc_geom geometry(multipolygon,32616),
|
ADD COLUMN loc_geom geometry(multipolygon,32616),
|
||||||
ADD COLUMN building_count integer,
|
ADD COLUMN building_count integer,
|
||||||
|
@ -22,34 +23,38 @@ UPDATE parcels__public_ SET loc_geom = ST_MakeValid(ST_Transform(geom,32616));
|
||||||
CREATE INDEX ON parcels__public_ USING GIST (loc_geom);
|
CREATE INDEX ON parcels__public_ USING GIST (loc_geom);
|
||||||
|
|
||||||
-- parse and expand parcel street addresses
|
-- parse and expand parcel street addresses
|
||||||
UPDATE parcels__public_ SET "addr:street" = initcap(addrst)||' '||
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+)$', '\1')),
|
||||||
CASE
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+)$', '\2')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+)'
|
||||||
WHEN upper(addrsf) = 'AV' THEN 'Avenue'
|
AND situsfmt1 NOT LIKE '%NONE' AND situsfmt1 NOT SIMILAR TO '([0-9]+) ([A-Z ]+) (AVE|DR|RD|ST|LN|CT|PL|CIR|TER|BLVD|PKWY|HWY)' AND situsfmt1 NOT SIMILAR TO '% ([^A-Z]+)';
|
||||||
WHEN upper(addrsf) = 'DR' THEN 'Drive'
|
-- select situsfmt1, "addr:housenumber", "addr:street" from parcels__public_ limit 100;
|
||||||
WHEN upper(addrsf) = 'RD' THEN 'Road'
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z]+) AVE$', '\1')),
|
||||||
WHEN upper(addrsf) = 'ST' THEN 'Street'
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) AVE$', '\2 Avenue')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+) AVE';
|
||||||
WHEN upper(addrsf) = 'LN' THEN 'Lane'
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) DR$', '\1')),
|
||||||
WHEN upper(addrsf) = 'CT' THEN 'Court'
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) DR$', '\2 Drive')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+) DR';
|
||||||
WHEN upper(addrsf) = 'PL' THEN 'Place'
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) RD$', '\1')),
|
||||||
WHEN upper(addrsf) = 'CR' THEN 'Circle'
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) RD$', '\2 Road')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+) RD';
|
||||||
WHEN upper(addrsf) = 'TE' THEN 'Terrace'
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) ST$', '\1')),
|
||||||
WHEN upper(addrsf) = 'PK' THEN 'Park'
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) ST$', '\2 Street')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+) ST';
|
||||||
WHEN upper(addrsf) = 'WY' THEN 'Way'
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) LN$', '\1')),
|
||||||
WHEN upper(addrsf) = 'BV' THEN 'Boulevard'
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) LN$', '\2 Lane')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+) LN';
|
||||||
WHEN upper(addrsf) = 'PW' THEN 'Parkway'
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) CT$', '\1')),
|
||||||
WHEN upper(addrsf) = 'TL' THEN 'Trail'
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) CT$', '\2 Court')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+) CT';
|
||||||
WHEN upper(addrsf) = 'HW' THEN 'Highway'
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) PL$', '\1')),
|
||||||
WHEN upper(addrsf) = 'WA' THEN 'Way'
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) PL$', '\2 Place')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+) PL';
|
||||||
WHEN upper(addrsf) = 'TR' THEN 'Terrace'
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) CIR$', '\1')),
|
||||||
WHEN upper(addrsf) = 'SQ' THEN 'Square'
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) CIR$', '\2 Circle')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+) CIR';
|
||||||
WHEN upper(addrsf) = 'AL' THEN 'Alley'
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) TER$', '\1')),
|
||||||
WHEN upper(addrsf) = 'BL' THEN 'Boulevard'
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) TER$', '\2 Terrace')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+) TER';
|
||||||
WHEN upper(addrsf) = 'CI' THEN 'Circle'
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) BLVD$', '\1')),
|
||||||
WHEN upper(addrsf) = 'PT' THEN 'Point'
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) BLVD$', '\2 Boulevard')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+) BLVD';
|
||||||
WHEN upper(addrsf) = 'PI' THEN 'Pike'
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) PKWY$', '\1')),
|
||||||
WHEN upper(addrsf) = 'LA' THEN 'Lane'
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) PKWY$', '\2 Parkway')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+) PKWY';
|
||||||
ELSE '' -- NULL cases mostly have the suffix in the name field
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) HWY$', '\1')),
|
||||||
END;
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) ([A-Z ]+) HWY$', '\2 Highway')) where situsfmt1 SIMILAR TO '([0-9]+) ([A-Z ]+) HWY';
|
||||||
|
-- select situsfmt1, "addr:housenumber", "addr:street" from parcels__public_ limit 100;
|
||||||
|
update parcels__public_ SET "addr:housenumber" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) HWY ([0-9]+)$', '\1')),
|
||||||
|
"addr:street" = initcap(REGEXP_REPLACE(situsfmt1, '^([0-9]+) HWY ([0-9]+)$', 'Highway \2')) where situsfmt1 SIMILAR TO '([0-9]+) HWY ([0-9]+)';
|
||||||
|
-- select situsfmt1, "addr:housenumber", "addr:street" from parcels__public_ where situsfmt1 SIMILAR TO '([0-9]+) HWY ([0-9]+)';
|
||||||
|
|
||||||
|
|
||||||
-- identify repeating parcels (indicates multiple addresses associated with buildings)
|
-- identify repeating parcels (indicates multiple addresses associated with buildings)
|
||||||
|
@ -64,6 +69,7 @@ UPDATE parcels__public_ SET repeating = TRUE
|
||||||
FROM geom_counts2
|
FROM geom_counts2
|
||||||
WHERE ids @> ARRAY[gid];
|
WHERE ids @> ARRAY[gid];
|
||||||
|
|
||||||
|
-------------------------------------------------------TODO
|
||||||
|
|
||||||
-- identify parcels with multiple buildings
|
-- identify parcels with multiple buildings
|
||||||
UPDATE parcels__public_ SET building_count = NULL WHERE building_count IS NOT NULL;
|
UPDATE parcels__public_ SET building_count = NULL WHERE building_count IS NOT NULL;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user