#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    7
    Rep Power
    0

    connecting to the overpass-endpoint with PHP


    currently want to dive into php with some real world projects +

    connecting to the endpoint of Overpass.

    a list of comma seperated values - is this correct.... ?

    i want to translate the following overopass-turbo requests into a request that i run against the endpoint of the overpass-api ... like so,

    Code:
    $endpoint = 'http://overpass-api.de/api/interpreter';
    i want to retrieve the data that i get with the following term -- that i use with the overpass-turbo-access;:
    Code:
    [out:csv(::id,::type,"name","addr:postcode","addr:city","addr:street","addr:housenumber","website"," contact:email=*")][timeout:600];
    {{geocodeArea:Schweiz}}->.a;
    ( node(area.a)[amenity=hospital];
      way(area.a)[amenity=hospital];
      rel(area.a)[amenity=hospital];);
    out;
    so i have to port over the above mentioned code into the following approach:
    Code:
    # please do not stress this service, this example is for demonstration purposes only.
    $endpoint = 'http://overpass-api.de/api/interpreter';
    libxml_set_streams_context($context);
    $start = microtime(true);
    
    $result = simplexml_load_file($endpoint);
    printf("Query returned %2\$d node(s) and took %1\$.5f seconds.\n\n", microtime(true) - $start, count($result->node));
    
     
    
    // 2.) Work with the XML Result
    any idea!? Look forward to hear from you
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,350
    Rep Power
    630
    First when posting PHP code please use the proper tags. See the sticky at the top of this forum that says READ THIS BEFORE POSTING.

    As for your specific questions, this should help you get started.

    To parse XML you want to use the XML parser. There are various tutorials on how to do that, you just need to google it.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo