コード例 #1
0
ファイル: drawbox.php プロジェクト: Gannaf/OpenCityStreets
// define your box
$set_lat1 = 51;
$set_lng1 = 0;
$set_lat2 = 51.3;
$set_lng2 = 0.3;
$set_img_file = 'test.png';
$set_img_width = 1000;
$set_img_height = $set_img_width * (abs($set_lat2 - $set_lat1) / abs($set_lng2 - $set_lng1));
// End of settings
if (!mysql_connect($set_db_server, $set_db_user, $set_db_pass)) {
    die("Error connecting to database\n\n");
}
if (!mysql_select_db($set_db_db)) {
    die("Error selecting database '{$set_db_db}'\n\n");
}
$timer = new RunTimer();
$result = mysql_query("SELECT way_id, AsText(way_geom) as way_geom FROM ways WHERE MBRIntersects(GeomFromText('Polygon(({$set_lat1} \n{$set_lng1},{$set_lat2} {$set_lng1},{$set_lat2} {$set_lng2},{$set_lat1} {$set_lng2},{$set_lat1} {$set_lng1}))'), way_geom)");
$count = mysql_num_rows($result);
$selecttime = $timer->get_runtime();
echo "Time to execute select: {$selecttime} seconds.  {$count} records returned.\n";
$im = imagecreate($set_img_width, $set_img_height);
$bgcolor = imagecolorallocate($im, 255, 255, 255);
$node_color = imagecolorallocate($im, 0, 0, 0);
while ($row = mysql_fetch_array($result)) {
    $points = explode(",", substr($row['way_geom'], 11, -1));
    $lastx = 0;
    $lasty = 0;
    for ($loop = 0; $loop < sizeof($points); $loop++) {
        $lldata = explode(" ", $points[$loop]);
        $x = intval(($lldata[1] - $set_lng1) * ($set_img_width / ($set_lng2 - $set_lng1)));
        $y = $set_img_height - intval(($lldata[0] - $set_lat1) * ($set_img_height / abs($set_lat2 - $set_lat1)));
コード例 #2
0
$set_log_interval = 100000;
// End of settings
$reader = new XMLReader();
if (!$reader->open($set_osm_filename)) {
    die("Error opening OSM file\n\n");
}
if (!mysql_connect($set_db_server, $set_db_user, $set_db_pass)) {
    die("Error connecting to database\n\n");
}
if (!mysql_select_db($set_db_db)) {
    die("Error selecting database '{$set_db_db}'\n\n");
}
$nodes_in = 0;
$ways_in = 0;
$tagfinder = new TagFinder();
$runtimer = new RunTimer();
mysql_query("LOCK TABLES nodes, nodes_to_ways, tags, tags_to_nodes, tags_to_ways, ways WRITE");
while ($reader->read()) {
    if (in_array($reader->nodeType, array(XMLReader::TEXT, XMLReader::CDATA, XMLReader::WHITESPACE, XMLReader::SIGNIFICANT_WHITESPACE)) && $name != '') {
        continue;
    }
    /*if ($reader->name == 'osm')
    		continue;*/
    if ($reader->name == 'node') {
        $nodes_in++;
        if (($nodes_in + $ways_in) % $set_log_interval == 0) {
            $runtimer->log_interval($nodes_in, $ways_in, $tagfinder->hits(), $tagfinder->misses());
        }
        $node = array();
        $tags = array();
        $node['id'] = $reader->getAttribute('id');