}
    $constituency_code = $constituency_map[$constituency_name];
    $output_osm_ways->begin_way();
    $output_osm_ways->add_tag('name', $constituency_name);
    $output_osm_ways->add_tag('hk_district_code', $district_code);
    $output_osm_ways->add_tag('hk_constituency_code', $constituency_code);
    foreach ($way['nds'] as $nd_ref) {
        if (!isset($input_nodes[$nd_ref])) {
            continue;
        }
        $node = $input_nodes[$nd_ref];
        $output_osm_ways->add_vertex($node['lat'], $node['lon']);
    }
    $output_osm_ways->end_way();
}
$output_contents = $output_osm_ways->serialize_to_xml();
file_put_contents($osm_output, $output_contents) or die("Couldn't write file '{$output_osm_file}'");
$php_output_handle = fopen($php_output, "w") or die("Couldn't open {$php_output}\n");
fwrite($php_output_handle, '$hk_district_code_accepted_values = array(' . "\n");
foreach ($district_map as $name => $code) {
    fwrite($php_output_handle, '    "' . $code . '",' . "\n");
}
fwrite($php_output_handle, ');' . "\n\n");
fwrite($php_output_handle, '$hk_constituency_code_accepted_values = array(' . "\n");
foreach ($constituency_map as $name => $code) {
    fwrite($php_output_handle, '    "' . $code . '",' . "\n");
}
fwrite($php_output_handle, ');' . "\n\n");
fwrite($php_output_handle, '$hk_district_name_translation_table = array(' . "\n");
foreach ($district_map as $full_name => $code) {
    $name_parts = explode(' ', $full_name, 2);
        $osm_ways->begin_way();
        foreach ($vertices as $vertex) {
            $x = $vertex['x'];
            $y = $vertex['y'];
            if ($convert_from_uk) {
                $geo = NEtoLL($x, $y);
                $lat = $geo['latitude'];
                $lon = $geo['longitude'];
            } else {
                if (isset($proj_convert)) {
                    list($lon, $lat) = $proj_convert->lcc2ll(array($x, $y));
                } else {
                    $lat = $y;
                    $lon = $x;
                }
            }
            $osm_ways->add_vertex($lat, $lon);
        }
        if (!is_array($current_attributes)) {
            die("Bad attributes: " . error_log(print_r($current_attributes, true)));
        }
        foreach ($current_attributes as $key => $value) {
            $osm_ways->add_tag($key, $value);
        }
        $osm_ways->end_way();
    }
}
$osm_xml = $osm_ways->serialize_to_xml();
$output_file_handle = fopen($output_file, 'w') or die("Couldn't open {$output_file} for writing");
fwrite($output_file_handle, $osm_xml);
fclose($output_file_handle);