]> git.openstreetmap.org Git - nominatim.git/blob - data-sources/gb-postcodes/convert_codepoint.php
Merge branch 'patch-1' of https://github.com/ganeshkrishnan1/Nominatim into ganeshkri...
[nominatim.git] / data-sources / gb-postcodes / convert_codepoint.php
1 #!/usr/bin/env php
2 <?php
3
4 echo <<< EOT
5
6 ALTER TABLE gb_postcode ADD COLUMN easting bigint;
7 ALTER TABLE gb_postcode ADD COLUMN northing bigint;
8
9 TRUNCATE gb_postcode;
10
11 COPY gb_postcode (id, postcode, easting, northing) FROM stdin;
12
13 EOT;
14
15 $iCounter = 0;
16 while ($sLine = fgets(STDIN)) {
17     $aColumns = str_getcsv($sLine);
18
19     // insert space before the third last position
20     // https://stackoverflow.com/a/9144834
21     $postcode = $aColumns[0];
22     $postcode = preg_replace('/\s*(...)$/', ' $1', $postcode);
23
24     echo join("\t", array($iCounter, $postcode, $aColumns[2], $aColumns[3]))."\n";
25
26     $iCounter = $iCounter + 1;
27 }
28
29 echo <<< EOT
30 \.
31
32 UPDATE gb_postcode SET geometry=ST_Transform(ST_SetSRID(CONCAT('POINT(', easting, ' ', northing, ')')::geometry, 27700), 4326);
33
34 ALTER TABLE gb_postcode DROP COLUMN easting;
35 ALTER TABLE gb_postcode DROP COLUMN northing;
36
37 EOT;