| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- // head of html
- echo '<!DOCTYPE html>
- <html lang="cs" dir="ltr">
- <head>
- <title>Deutschen Bahn Streckennetz to RDF</title>
- <meta charset="utf-8">
- <meta name="robots" content="index,follow">
- <meta name="author" content="Jáchym Kellar">
- <!-- <meta http-equiv="X-UA-Compatible" content="IE=edge"> -->
- <style>
- body{
- margin-top: 80px;
- text-align: center;
- }
- .start{
- font-size: 28px;
- text-decoration: none;
- letter-spacing: 1px;
- }
- a{
- text-decoration: none;
- }
- a:hover{
- text-decoration: underline;
- }
- .pozn{
- font-size: 13px;
- }
- </style>
- </head>
- <body>
- <h2>Deutsche Bahn dataset → SPOI data model</h2>
-
- <h4>Deutsche Bahn: <a href="http://data.deutschebahn.com/dataset/data-streckennetz" target="_blank">http://data.deutschebahn.com/dataset/data-streckennetz</a></h4>
- <h4>SPOI: <a href="http://sdi4apps.eu/spoi/" target="_blank">http://sdi4apps.eu/spoi</a></h4>
-
- <br><br>
-
- ';
- // click to start transformation -> reload page
- echo '<a href="railwayStationNodes.php?transform=start" class="start">Start</a>';
- echo '<br><span class="pozn">(this may take a while)</span>';
- // should start the transformation? - get method
- if (IsSet($_GET['transform'])){
- $status=$_GET['transform'];
- if($status == "start"){
- transform();
- }
- }
- // end of html document
- echo ' </body>
- </html>
- ';
- // 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 "<br><br>Zip archive file size: ".format_size($filesize)."<br>";
- // 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<br>';
- }
- // delete archive
- unlink('DB-Netz_INSPIRE.zip');
-
- // filesize of geojson
- $filesize = filesize("railwayStationNodes.geojson");
- echo "GeoJson file size: ".format_size($filesize)."<br>";
- // create rdf
- $soubor = fopen("railwayStationNodes.rdf", "w");
- // write head of rdf
- fwrite($soubor, '<?xml version="1.0" encoding="utf-8"?');
- fwrite($soubor, ">\r\n");
- fwrite($soubor, '<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:dcterms="http://purl.org/dc/terms/1.1/"
- xmlns:foaf="http://xmlns.com/foaf/0.1/"
- xmlns:geos="http://www.opengis.net/ont/geosparql#"
- xmlns:owl="http://www.w3.org/2002/07/owl#"
- xmlns:poi="http://www.openvoc.eu/poi#"
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
- xmlns:sf="http://www.opengis.net/ont/sf#"
- xmlns:skos="http://www.w3.org/2004/02/skos/core#">
- ');
- // load geojson
- $string = file_get_contents("railwayStationNodes.geojson");
- $json = json_decode($string, true);
- echo 'Memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB<br>";
- // 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, ' <rdf:Description rdf:about="http://www.sdi4apps.eu/poi/#'.$id.'">');
- fwrite($soubor, "\r\n");
-
- $label = $item['properties']['geographicalName'];
- $label = trim($label);
- fwrite($soubor, ' <rdfs:label xml:lang="de">'.$label.'</rdfs:label>');
- fwrite($soubor, "\r\n");
-
- fwrite($soubor, ' <geos:asWKT rdf:datatype="http://www.openlinksw.com/schemas/virtrdf#Geometry">POINT('.$coordinate1.' '.$coordinate2.')</geos:asWKT>');
- fwrite($soubor, "\r\n");
- fwrite($soubor, ' <poi:class rdf:resource="http://gis.zcu.cz/SPOI/Ontology#transportation"/>');
- //fwrite($soubor, ' <poi:category>railway</poi:category>');
- fwrite($soubor, "\r\n");
- fwrite($soubor, ' <poi:class rdf:resource="http://gis.zcu.cz/SPOI/Ontology#railway_station"/>');
- //fwrite($soubor, ' <poi:categoryOSM>railway.station</poi:categoryOSM>');
- fwrite($soubor, "\r\n");
-
- //fwrite($soubor, ' <poi:categoryWaze rdf:resource="http://www.openvoc.eu/waze_classification#Transportation"/>');
- //fwrite($soubor, "\r\n");
- fwrite($soubor, ' <geos:sfWithin rdf:resource="http://dbpedia.org/resource/Germany"/>');
- fwrite($soubor, "\r\n");
- fwrite($soubor, ' <geos:sfWithin rdf:resource="http://www.geonames.org/2921044"/>');
- fwrite($soubor, "\r\n");
- fwrite($soubor, ' <dc:identifier rdf:resource="http://www.sdi4apps.eu/poi/#'.$id.'"/>');
- fwrite($soubor, "\r\n");
- fwrite($soubor, ' <dc:publisher>SPOI (http://sdi4apps.eu/spoi)</dc:publisher>');
- fwrite($soubor, "\r\n");
- fwrite($soubor, ' <dc:title xml:lang="de">'.$label.'</dc:title>');
- fwrite($soubor, "\r\n");
- fwrite($soubor, ' <dc:rights rdf:resource="https://creativecommons.org/licenses/by/4.0/"/>');
- fwrite($soubor, "\r\n");
- fwrite($soubor, ' <dc:source rdf:resource="http://data.deutschebahn.com/"/> ');
- fwrite($soubor, "\r\n");
- $date = getdate();
- fwrite($soubor, ' <dcterms:created rdf:datatype="http://www.w3.org/2001/XMLSchema#date">'.$date['year']."-".$date['mon']."-".$date['mday'].'</dcterms:created>');
- fwrite($soubor, "\r\n");
-
- fwrite($soubor, ' </rdf:Description>');
- fwrite($soubor, "\r\n");
- }
- fwrite($soubor, "</rdf:RDF>");
- fclose($soubor);
- // delete json
- unlink('railwayStationNodes.geojson');
- // link to download rdf
- echo '<a href="railwayStationNodes.rdf" target="_blank">Download RDF file</a>';
- // filesize of rdf
- $filesize = filesize("railwayStationNodes.rdf");
- echo " (".format_size($filesize).")<br>";
- }
- // 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]); }
- }
- ?>
|