PHP code example of mediasuitenz / overpass2geojson

1. Go to this page and download the library: Download mediasuitenz/overpass2geojson library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mediasuitenz / overpass2geojson example snippets


// Example from above
$url = 'http://overpass.osm.rambler.ru/cgi/interpreter?data=[out:json][timeout:25];%20(%20way[%22highway%22]%20(-43.5594542,172.6998653,-43.5548322,172.708076);%20node(w)-%3E.x;%20);%20out;';

// cURL the API
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$osmJsonData = curl_exec($ch);

// convert accepts JSON string or array e.g. from json_decode($osmJsonData, true);

$geojson = Overpass2Geojson::convertWays($osmJsonData); // Returns JSON encoded string
$geojson = Overpass2Geojson::convertWays($osmJsonData, false); // Returns array with GeoJSON structure
$geojson = Overpass2Geojson::convertNodes($osmJsonData);