com presentations: OSM talk for LoneStar PHP.: osm-lonestar12.xml slides/map/finding-food-data-mongo.xml
slides/map/finding-food-import-mongo-script.xml slides/map/osm-editors.xml slides/map/osrm-services.xml slides/map/osrm.png slides/map/osrm.xml
slides/map/osrm3.png
| From: | Derick Rethans | Date: | Tue, 26 Jun 2012 13:27:51 +0000 |
| Subject: | com presentations: OSM talk for LoneStar PHP.: osm-lonestar12.xml slides/map/finding-food-data-mongo.xml slides/map/finding-food-import-mongo-script.xml slides/map/osm-editors.xml slides/map/osrm-services.xml slides/map/osrm.png slides/map/osrm.xml slides/map/osrm3.png |
||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-1826@lists.php.net to get a copy of this message | ||
Commit: d8ba752183cdb80603b3f2e279031f42dd261476
Author: Derick Rethans <github@derickrethans.nl> Tue, 26 Jun 2012 15:27:51 +0200
Parents: 794448800b4d4c865dba3d7094f97976c81a1000
Branches: master
Link: http://git.php.net/?p=presentations.git;a=commitdiff;h=d8ba752183cdb80603b3f2e279031f42dd261476
Log:
OSM talk for LoneStar PHP.
Changed paths:
A osm-lonestar12.xml
M slides/map/finding-food-data-mongo.xml
M slides/map/finding-food-import-mongo-script.xml
M slides/map/osm-editors.xml
A slides/map/osrm-services.xml
A slides/map/osrm.png
A slides/map/osrm.xml
A slides/map/osrm3.png
diff --git a/osm-lonestar12.xml b/osm-lonestar12.xml new file mode 100644 index 0000000..f59282e --- /dev/null +++ b/osm-lonestar12.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="utf-8"?> +<presentation css="10gen-strict.css"> +<topic>Maps</topic> +<title>OpenStreetMap and PHP</title> +<event>LoneStar PHP</event> +<location>Addison, TX, US</location> +<date>June 29th, 2012</date> +<speaker>Derick Rethans</speaker> +<email>derick@derickrethans.nl</email> +<twitter>derickr</twitter> +<joindin>http://joind.in/6338</joindin> +<slide>slides/map/title.xml</slide> +<slide>slides/mongodb/me.xml</slide> + +<!-- +In this talk I will be explaining the strong points of OpenStreetMap and why +using GoogleMaps for your websites is generally a bad idea. Contrary to popular +belief, GoogleMaps isn't as amazing as it looks and they are a lot more evil +than they look. OpenStreetMap's data is also easily accessible for use in PHP +applications and the generated tiles can easily be embedded into a Web 2.0 +application. Its open nature is a welcome and powerful geo database that can be +added to and used in whatever way imaginary. +--> + +<slide>slides/map/earth-not-a-sphere.xml</slide> +<slide>slides/map/earth-sphere-approximation.xml</slide> +<slide>slides/map/meridian.xml</slide> +<slide>slides/map/projections.xml</slide> + +<!-- +What is X? +--> +<slide>slides/map/osm-what.xml</slide> +<slide>slides/map/what-is-osm.xml</slide> +<slide>slides/map/what-is-googlemaps.xml</slide> +<slide>slides/map/terms-and-conditions.xml</slide> +<slide>slides/map/leaflet.xml</slide> + +<slide>slides/map/openlayers-location.xml</slide> +<slide>slides/map/openlayers-location-services.xml</slide> +<slide>slides/map/reverse.xml</slide> +<slide>slides/map/reverse-services.xml</slide> +<slide>slides/map/osrm.xml</slide> +<slide>slides/map/osrm-services.xml</slide> + +<slide>slides/map/html-location-services.xml</slide> + +<slide>slides/map/osm-data.xml</slide> + +<slide>slides/map/osm-tags-edit.xml</slide> + + +<slide>slides/map/osm-mapping-party1.xml</slide> +<slide>slides/map/osm-mapping-party2.xml</slide> +<slide>slides/map/osm-editors.xml</slide> +<slide>slides/map/osm-data-uses.xml</slide> + +<slide>slides/map/osm-parse-into-db.xml</slide> +<slide>slides/map/osm-xapi.xml</slide> + +<slide>slides/map/finding-food-import-mongo.xml</slide> +<slide>slides/map/finding-food-import-mongo2.xml</slide> +<slide>slides/map/finding-food-import-mongo-script.xml</slide> +<slide>slides/map/finding-food-data-mongo.xml</slide> +<slide>slides/map/finding-food-take2.xml</slide> + +<slide>slides/mongodb/resources.xml</slide> + +</presentation> diff --git a/slides/map/finding-food-data-mongo.xml b/slides/map/finding-food-data-mongo.xml index de7ded8..59541c0 100644 --- a/slides/map/finding-food-data-mongo.xml +++ b/slides/map/finding-food-data-mongo.xml @@ -12,12 +12,7 @@ $c->ensureIndex( array( 'loc' => '2d' ) ); <div effect="fade-in-out"> <example><![CDATA[ $wantedD = isset($_GET['d']) ? $_GET['d']: 1; -$query = array( 'tags_indexed.k' => 'cuisine', 'tags_indexed.v' => $_GET['cuisine'] ); - -if ( $_GET['cuisine'] == 'all' ) -{ - $query = array( 'tags_indexed.k' => 'amenity', 'tags_indexed.v' => 'restaurant' ); -} +$query = array( 'tags_indexed.k' => array( '$ne' => 'landuse' ) ); $s = $d->command( array( @@ -37,30 +32,53 @@ $s = $d->command( </div> <div effect="fade-in-out"> <example><![CDATA[ -foreach( $s['results'] as $res) +foreach( $s['results'] as $res) { $o = $res['obj']; - if (!isset($o['name'])) { + if (!isset($o['tags']['name'])) { continue; } $ret = array( 'type' => 'Feature', - 'properties' => array( - 'name' => $o['name'], - 'popupContent' => $o['name'], - ) + 'properties' => array( 'name' => '?', 'popupContent' => '' ), ); - if ($o['type'] == 1) { + if (isset( $o['tags']['name'] ) ) + { + $ret['properties'] = array( + 'name' => $o['tags']['name'], + 'popupContent' => "<b>{$o['tags']['name']}</b>", + ); + } + if ( isset( $o['tags'] ) ) + { + foreach ( $o['tags'] as $tagName => $value ) + { + $ret['properties']['popupContent'] .= "<br/>{$tagName}: {$value}\n"; + } + } + if ($o['type'] == 1) + { $ret['geometry'] = array( 'type' => "Point", 'coordinates' => $o['loc'] ); } - if ($o['type'] == 2) { - $ret['geometry'] = array( - 'type' => "Polygon", - 'coordinates' => array($o['loc']), - ); + if ($o['type'] == 2) + { + if ($o['loc'][0] == $o['loc'][count($o['loc']) - 1]) + { + $ret['geometry'] = array( + 'type' => "Polygon", + 'coordinates' => array($o['loc']), + ); + } + else + { + $ret['geometry'] = array( + 'type' => "LineString", + 'coordinates' => $o['loc'], + ); + } } $rets[] = $ret; } diff --git a/slides/map/finding-food-import-mongo-script.xml b/slides/map/finding-food-import-mongo-script.xml index 697c0da..5a08bf2 100644 --- a/slides/map/finding-food-import-mongo-script.xml +++ b/slides/map/finding-food-import-mongo-script.xml @@ -7,9 +7,7 @@ $m = new Mongo( 'mongodb://localhost:27017' ); $d = $m->selectCollection( 'demo', 'poi' ); $d->drop(); $d->ensureIndex( array( 'loc' => '2d' ) ); -$d->ensureIndex( array( 'name' => 1 ) ); -$d->ensureIndex( array( 'tags_indexed' => 1 ) ); -$d->ensureIndex( array( 'tags_indexed.k' => 1, 'tags_indexed.v' => 1 ) ); +$d->ensureIndex( array( 'tags_indexed.v' => 1, 'tags_indexed.k' => 1 ) ); $locations = array(); @@ -27,9 +25,7 @@ while ($z->name === 'node') { $q['type'] = 1; $q['loc'] = array( (float) $node['lon'], (float) $node['lat'] ); parseNode($q, $node); - if (count($q['tags']) > 0) { - $d->insert( $q ); - } + $d->insert( $q ); // also keep a cache of all nodes and locations $locations[(string) $node['id']] = "{$node['lon']}|{$node['lat']}"; @@ -96,7 +92,6 @@ function parseNode(&$q, $sxml) foreach( $sxml->tag as $tag ) { if ($tag['k'] == 'name') { - $q['name'] = trim( (string) $tag['v'] ); $standAloneNode = true; } else { if (!in_array( $tag['k'], $ignoreTags)) { diff --git a/slides/map/osm-editors.xml b/slides/map/osm-editors.xml index e072c99..79b93ee 100644 --- a/slides/map/osm-editors.xml +++ b/slides/map/osm-editors.xml @@ -1,5 +1,5 @@ <slide> -<title>Editting the map</title> +<title>Editing the map</title> <div effect="fade-out"> <image filename='editor-none.png'/> </div> diff --git a/slides/map/osrm-services.xml b/slides/map/osrm-services.xml new file mode 100644 index 0000000..b8b9fbd --- /dev/null +++ b/slides/map/osrm-services.xml @@ -0,0 +1,18 @@ +<slide> +<title>Routing engine: OSRM</title> + +<list> + <bullet>Open source routing engine</bullet> + <bullet>Website at http://project-osrm.org/</bullet> + <bullet>Demo website at http://map.project-osrm.org</bullet> + <bullet>Server API access + <list> + <bullet>some usage restrictions</bullet> + <bullet>some requirements for usage</bullet> + </list> + </bullet> + <bullet>It is *really* fast!</bullet> +</list> + +<image filename="osrm3.png"/> +</slide> diff --git a/slides/map/osrm.png b/slides/map/osrm.png new file mode 100644 index 0000000..de1541d Binary files /dev/null and b/slides/map/osrm.png differ diff --git a/slides/map/osrm.xml b/slides/map/osrm.xml new file mode 100644 index 0000000..81d02be --- /dev/null +++ b/slides/map/osrm.xml @@ -0,0 +1,23 @@ +<slide> +<title>Routing engine: OSRM</title> + +<div effect="fade-out"> +<image filename="osrm.png"/> +</div> + +<div effect="fade-in"> +<example result='1'><![CDATA[ +<?php +$nominatimUrl = 'http://nominatim.openstreetmap.org/search?format=json&limit=1&q='; +$from = urlencode( "The London Eye, London" ); +$to = urlencode( "St Paul's Cathedral, London" ); +$fromLL = json_decode( file_get_contents( "{$nominatimUrl}{$from}" ) ); +$toLL = json_decode( file_get_contents( "{$nominatimUrl}{$to}" ) ); + +$osrmUrl = 'http://router.project-osrm.org/viaroute'; +$osrmUrl .= sprintf( "?loc=%.4f,%.4f", $fromLL[0]->lat, $fromLL[0]->lon ); +$osrmUrl .= sprintf( "&loc=%.4f,%.4f", $toLL[0]->lat, $toLL[0]->lon ); +var_dump( json_decode( file_get_contents( $osrmUrl ) ) ); +?>]]></example> +</div> +</slide> diff --git a/slides/map/osrm3.png b/slides/map/osrm3.png new file mode 100644 index 0000000..a4f5c38 Binary files /dev/null and b/slides/map/osrm3.png differ
diff --git a/osm-lonestar12.xml b/osm-lonestar12.xml new file mode 100644 index 0000000..f59282e --- /dev/null +++ b/osm-lonestar12.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="utf-8"?> +<presentation css="10gen-strict.css"> +<topic>Maps</topic> +<title>OpenStreetMap and PHP</title> +<event>LoneStar PHP</event> +<location>Addison, TX, US</location> +<date>June 29th, 2012</date> +<speaker>Derick Rethans</speaker> +<email>derick@derickrethans.nl</email> +<twitter>derickr</twitter> +<joindin>http://joind.in/6338</joindin> +<slide>slides/map/title.xml</slide> +<slide>slides/mongodb/me.xml</slide> + +<!-- +In this talk I will be explaining the strong points of OpenStreetMap and why +using GoogleMaps for your websites is generally a bad idea. Contrary to popular +belief, GoogleMaps isn't as amazing as it looks and they are a lot more evil +than they look. OpenStreetMap's data is also easily accessible for use in PHP +applications and the generated tiles can easily be embedded into a Web 2.0 +application. Its open nature is a welcome and powerful geo database that can be +added to and used in whatever way imaginary. +--> + +<slide>slides/map/earth-not-a-sphere.xml</slide> +<slide>slides/map/earth-sphere-approximation.xml</slide> +<slide>slides/map/meridian.xml</slide> +<slide>slides/map/projections.xml</slide> + +<!-- +What is X? +--> +<slide>slides/map/osm-what.xml</slide> +<slide>slides/map/what-is-osm.xml</slide> +<slide>slides/map/what-is-googlemaps.xml</slide> +<slide>slides/map/terms-and-conditions.xml</slide> +<slide>slides/map/leaflet.xml</slide> + +<slide>slides/map/openlayers-location.xml</slide> +<slide>slides/map/openlayers-location-services.xml</slide> +<slide>slides/map/reverse.xml</slide> +<slide>slides/map/reverse-services.xml</slide> +<slide>slides/map/osrm.xml</slide> +<slide>slides/map/osrm-services.xml</slide> + +<slide>slides/map/html-location-services.xml</slide> + +<slide>slides/map/osm-data.xml</slide> + +<slide>slides/map/osm-tags-edit.xml</slide> + + +<slide>slides/map/osm-mapping-party1.xml</slide> +<slide>slides/map/osm-mapping-party2.xml</slide> +<slide>slides/map/osm-editors.xml</slide> +<slide>slides/map/osm-data-uses.xml</slide> + +<slide>slides/map/osm-parse-into-db.xml</slide> +<slide>slides/map/osm-xapi.xml</slide> + +<slide>slides/map/finding-food-import-mongo.xml</slide> +<slide>slides/map/finding-food-import-mongo2.xml</slide> +<slide>slides/map/finding-food-import-mongo-script.xml</slide> +<slide>slides/map/finding-food-data-mongo.xml</slide> +<slide>slides/map/finding-food-take2.xml</slide> + +<slide>slides/mongodb/resources.xml</slide> + +</presentation> diff --git a/slides/map/finding-food-data-mongo.xml b/slides/map/finding-food-data-mongo.xml index de7ded8..59541c0 100644 --- a/slides/map/finding-food-data-mongo.xml +++ b/slides/map/finding-food-data-mongo.xml @@ -12,12 +12,7 @@ $c->ensureIndex( array( 'loc' => '2d' ) ); <div effect="fade-in-out"> <example><![CDATA[ $wantedD = isset($_GET['d']) ? $_GET['d']: 1; -$query = array( 'tags_indexed.k' => 'cuisine', 'tags_indexed.v' => $_GET['cuisine'] ); - -if ( $_GET['cuisine'] == 'all' ) -{ - $query = array( 'tags_indexed.k' => 'amenity', 'tags_indexed.v' => 'restaurant' ); -} +$query = array( 'tags_indexed.k' => array( '$ne' => 'landuse' ) ); $s = $d->command( array( @@ -37,30 +32,53 @@ $s = $d->command( </div> <div effect="fade-in-out"> <example><![CDATA[ -foreach( $s['results'] as $res) +foreach( $s['results'] as $res) { $o = $res['obj']; - if (!isset($o['name'])) { + if (!isset($o['tags']['name'])) { continue; } $ret = array( 'type' => 'Feature', - 'properties' => array( - 'name' => $o['name'], - 'popupContent' => $o['name'], - ) + 'properties' => array( 'name' => '?', 'popupContent' => '' ), ); - if ($o['type'] == 1) { + if (isset( $o['tags']['name'] ) ) + { + $ret['properties'] = array( + 'name' => $o['tags']['name'], + 'popupContent' => "<b>{$o['tags']['name']}</b>", + ); + } + if ( isset( $o['tags'] ) ) + { + foreach ( $o['tags'] as $tagName => $value ) + { + $ret['properties']['popupContent'] .= "<br/>{$tagName}: {$value}\n"; + } + } + if ($o['type'] == 1) + { $ret['geometry'] = array( 'type' => "Point", 'coordinates' => $o['loc'] ); } - if ($o['type'] == 2) { - $ret['geometry'] = array( - 'type' => "Polygon", - 'coordinates' => array($o['loc']), - ); + if ($o['type'] == 2) + { + if ($o['loc'][0] == $o['loc'][count($o['loc']) - 1]) + { + $ret['geometry'] = array( + 'type' => "Polygon", + 'coordinates' => array($o['loc']), + ); + } + else + { + $ret['geometry'] = array( + 'type' => "LineString", + 'coordinates' => $o['loc'], + ); + } } $rets[] = $ret; } diff --git a/slides/map/finding-food-import-mongo-script.xml b/slides/map/finding-food-import-mongo-script.xml index 697c0da..5a08bf2 100644 --- a/slides/map/finding-food-import-mongo-script.xml +++ b/slides/map/finding-food-import-mongo-script.xml @@ -7,9 +7,7 @@ $m = new Mongo( 'mongodb://localhost:27017' ); $d = $m->selectCollection( 'demo', 'poi' ); $d->drop(); $d->ensureIndex( array( 'loc' => '2d' ) ); -$d->ensureIndex( array( 'name' => 1 ) ); -$d->ensureIndex( array( 'tags_indexed' => 1 ) ); -$d->ensureIndex( array( 'tags_indexed.k' => 1, 'tags_indexed.v' => 1 ) ); +$d->ensureIndex( array( 'tags_indexed.v' => 1, 'tags_indexed.k' => 1 ) ); $locations = array(); @@ -27,9 +25,7 @@ while ($z->name === 'node') { $q['type'] = 1; $q['loc'] = array( (float) $node['lon'], (float) $node['lat'] ); parseNode($q, $node); - if (count($q['tags']) > 0) { - $d->insert( $q ); - } + $d->insert( $q ); // also keep a cache of all nodes and locations $locations[(string) $node['id']] = "{$node['lon']}|{$node['lat']}"; @@ -96,7 +92,6 @@ function parseNode(&$q, $sxml) foreach( $sxml->tag as $tag ) { if ($tag['k'] == 'name') { - $q['name'] = trim( (string) $tag['v'] ); $standAloneNode = true; } else { if (!in_array( $tag['k'], $ignoreTags)) { diff --git a/slides/map/osm-editors.xml b/slides/map/osm-editors.xml index e072c99..79b93ee 100644 --- a/slides/map/osm-editors.xml +++ b/slides/map/osm-editors.xml @@ -1,5 +1,5 @@ <slide> -<title>Editting the map</title> +<title>Editing the map</title> <div effect="fade-out"> <image filename='editor-none.png'/> </div> diff --git a/slides/map/osrm-services.xml b/slides/map/osrm-services.xml new file mode 100644 index 0000000..b8b9fbd --- /dev/null +++ b/slides/map/osrm-services.xml @@ -0,0 +1,18 @@ +<slide> +<title>Routing engine: OSRM</title> + +<list> + <bullet>Open source routing engine</bullet> + <bullet>Website at http://project-osrm.org/</bullet> + <bullet>Demo website at http://map.project-osrm.org</bullet> + <bullet>Server API access + <list> + <bullet>some usage restrictions</bullet> + <bullet>some requirements for usage</bullet> + </list> + </bullet> + <bullet>It is *really* fast!</bullet> +</list> + +<image filename="osrm3.png"/> +</slide> diff --git a/slides/map/osrm.png b/slides/map/osrm.png new file mode 100644 index 0000000..de1541d Binary files /dev/null and b/slides/map/osrm.png differ diff --git a/slides/map/osrm.xml b/slides/map/osrm.xml new file mode 100644 index 0000000..81d02be --- /dev/null +++ b/slides/map/osrm.xml @@ -0,0 +1,23 @@ +<slide> +<title>Routing engine: OSRM</title> + +<div effect="fade-out"> +<image filename="osrm.png"/> +</div> + +<div effect="fade-in"> +<example result='1'><![CDATA[ +<?php +$nominatimUrl = 'http://nominatim.openstreetmap.org/search?format=json&limit=1&q='; +$from = urlencode( "The London Eye, London" ); +$to = urlencode( "St Paul's Cathedral, London" ); +$fromLL = json_decode( file_get_contents( "{$nominatimUrl}{$from}" ) ); +$toLL = json_decode( file_get_contents( "{$nominatimUrl}{$to}" ) ); + +$osrmUrl = 'http://router.project-osrm.org/viaroute'; +$osrmUrl .= sprintf( "?loc=%.4f,%.4f", $fromLL[0]->lat, $fromLL[0]->lon ); +$osrmUrl .= sprintf( "&loc=%.4f,%.4f", $toLL[0]->lat, $toLL[0]->lon ); +var_dump( json_decode( file_get_contents( $osrmUrl ) ) ); +?>]]></example> +</div> +</slide> diff --git a/slides/map/osrm3.png b/slides/map/osrm3.png new file mode 100644 index 0000000..a4f5c38 Binary files /dev/null and b/slides/map/osrm3.png differ