/
extract_csv_to_ogr.sql
43 lines (35 loc) · 1014 Bytes
/
extract_csv_to_ogr.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
SELECT AssetCode AS id,
UPRN AS uprn,
Organisation AS org,
OrganisationLabel AS org_label,
PropertyName AS property,
-- StreetName has some carriage returns and line feeds in it, so we need to clean it up.
TRIM(
REPLACE(
REPLACE(StreetName, CHAR(13), ' '),
CHAR(10),
' '
)
) AS street,
PostTown AS town,
-- Postcode has some carriage returns and line feeds in it, so we need to clean it up.
REPLACE(
REPLACE(TRIM(Postcode), CHAR(13), ''),
CHAR(10),
''
) AS postcode,
-- Clean up and combine the tenure columns.
REPLACE(TenureType, CAST(X'a0' AS TEXT), '') as tenure,
TRIM(TenureDetail) as tenure_detail,
HoldingType AS holding,
-- Convert the GeoX and GeoY columns to a geometry.
Transform(
SetSRID(
MakePoint(CAST(GeoX AS INTEGER), CAST(GeoY AS INTEGER)),
27700
),
4326
) AS geom
FROM local_authority_land_and_assets_2021
-- Only include rows where we have a valid geometry.
WHERE GeoX != '' AND GeoY != ''