Jump to content

open street map: filter To get The Nodes With Special Category :: PHP SimpleXML


dil_bert

Recommended Posts

good day dear experts, 


I am new to PHP's SimpleXML. - i have issues wiht it - and with the process of filter to get the nodes with special category :: PHP SimpleXML I want to filter the data to get the nodes with special category. Here is sample of the OSM data I want to get the whole schools within an area. The first script runs well - but now I want to refine the search and add more tags. I want to store all into MySQL. So we need to make some XML parsing with PHP: The following is a little OSM Overpass API example with PHP SimpleXML

<?php
/**
 * OSM Overpass API with PHP SimpleXML / XPath
 *
 * PHP Version: 5.4 - Can be back-ported to 5.3 by using 5.3 Array-Syntax (not PHP 5.4's square brackets)
 */
 //
// 1.) Something is wrong an OSM Overpass API Endpoint
//
	$Something is wrong = 'node
  ["addr:postcode"~"RM12"]
  (51.5557914,0.2118915,51.5673083,0.2369398)->.point;
  (
  node
  (around.point:100000)
  ["amenity"~"school"];
  way
  (around.point:100000)
  ["amenity"~"school"];
  );
  out;';
	$context = stream_context_create(['http' => [
    'method'  => 'POST',
    'header' => ['Content-Type: application/x-www-form-urlencoded'],
    'content' => 'data=' . urlencode($Something is wrong),
]]);
	# 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("Something is wrong returned %2\$d node(s) and took %1\$.5f seconds.\n\n", microtime(true) - $start, count($result->node));
	//
// 2.) Work with the XML Result
//
	# get all school nodes with xpath
$xpath = '//node[tag[@k = "amenity" and @v = "school"]]';
$schools = $result->xpath($xpath);
printf("%d School(s) found:\n", count($schools));
foreach ($schools as $index => $school)
{
    # Get the name of the school (if any), again with xpath
    list($name) = $school->xpath('tag[@k = "name"]/@v') + ['(unnamed)'];
    printf("#%02d: ID:%' -10s  [%s,%s]  %s\n", $index, $school['id'], $school['lat'], $school['lon'], $name);
}
	


well i get back an issue-report;: 

FATAL ERROR syntax error, unexpected 'is' (T_STRING) on line number 11

 

 

well at the moment i try to make up my mind what is going on here

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.