Deutsche Bahn dataset → SPOI data model

Deutsche Bahn: http://data.deutschebahn.com/dataset/data-streckennetz

SPOI: http://sdi4apps.eu/spoi



'; // click to start transformation -> reload page echo 'Start'; echo '
(this may take a while)'; // should start the transformation? - get method if (IsSet($_GET['transform'])){ $status=$_GET['transform']; if($status == "start"){ transform(); } } // end of html document echo ' '; // download and transform data - main function transform(){ // download data file_put_contents("DB-Netz_INSPIRE.zip", fopen("http://download-data.deutschebahn.com/static/datasets/streckennetz/DB_Inspire_GeoJSON.zip", 'r')); // filesize of downloaded archive $filesize = filesize("DB-Netz_INSPIRE.zip"); echo "

Zip archive file size: ".format_size($filesize)."
"; // unzip archive $zip = new ZipArchive; $res = $zip->open('DB-Netz_INSPIRE.zip'); if ($res === TRUE) { // extract only railwayStationNodes $zip->extractTo(getcwd()."/", "railwayStationNodes.geojson"); $zip->close(); } else { echo 'Extract - error
'; } // delete archive unlink('DB-Netz_INSPIRE.zip'); // filesize of geojson $filesize = filesize("railwayStationNodes.geojson"); echo "GeoJson file size: ".format_size($filesize)."
"; // create rdf $soubor = fopen("railwayStationNodes.rdf", "w"); // write head of rdf fwrite($soubor, '\r\n"); fwrite($soubor, ' '); // load geojson $string = file_get_contents("railwayStationNodes.geojson"); $json = json_decode($string, true); echo 'Memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB
"; // loop a transform data foreach($json['features'] as $item) { $coordinate1 = $item['geometry']['coordinates'][0]; $coordinate2 = $item['geometry']['coordinates'][1]; $id = $item['properties']['id']; fwrite($soubor, ' '); fwrite($soubor, "\r\n"); $label = $item['properties']['geographicalName']; $label = trim($label); fwrite($soubor, ' '.$label.''); fwrite($soubor, "\r\n"); fwrite($soubor, ' POINT('.$coordinate1.' '.$coordinate2.')'); fwrite($soubor, "\r\n"); fwrite($soubor, ' '); //fwrite($soubor, ' railway'); fwrite($soubor, "\r\n"); fwrite($soubor, ' '); //fwrite($soubor, ' railway.station'); fwrite($soubor, "\r\n"); //fwrite($soubor, ' '); //fwrite($soubor, "\r\n"); fwrite($soubor, ' '); fwrite($soubor, "\r\n"); fwrite($soubor, ' '); fwrite($soubor, "\r\n"); fwrite($soubor, ' '); fwrite($soubor, "\r\n"); fwrite($soubor, ' SPOI (http://sdi4apps.eu/spoi)'); fwrite($soubor, "\r\n"); fwrite($soubor, ' '.$label.''); fwrite($soubor, "\r\n"); fwrite($soubor, ' '); fwrite($soubor, "\r\n"); fwrite($soubor, ' '); fwrite($soubor, "\r\n"); $date = getdate(); fwrite($soubor, ' '.$date['year']."-".$date['mon']."-".$date['mday'].''); fwrite($soubor, "\r\n"); fwrite($soubor, ' '); fwrite($soubor, "\r\n"); } fwrite($soubor, "
"); fclose($soubor); // delete json unlink('railwayStationNodes.geojson'); // link to download rdf echo 'Download RDF file'; // filesize of rdf $filesize = filesize("railwayStationNodes.rdf"); echo " (".format_size($filesize).")
"; } // filesize function function format_size($size) { $sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"); if ($size == 0) { return('n/a'); } else { return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]); } } ?>