com presentations: 4 developers talk tweaks.: osm-4dev12.xml slides/map/bug.jpg slides/map/finding-food-data-mongo.xml
slides/map/finding-food-import-mongo-script.xml slides/map/finding-food-import-mongo.xml slides/map/finding-food-import-mongo2.xml
slides/map/terms-and-conditions.xml slides/mongodb/me.xml
| From: | Derick Rethans | Date: | Wed, 18 Apr 2012 12:54:30 +0000 |
| Subject: | com presentations: 4 developers talk tweaks.: osm-4dev12.xml slides/map/bug.jpg slides/map/finding-food-data-mongo.xml slides/map/finding-food-import-mongo-script.xml slides/map/finding-food-import-mongo.xml slides/map/finding-food-import-mongo2.xml slides/map/terms-and-conditions.xml slides/mongodb/me.xml |
||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-1796@lists.php.net to get a copy of this message | ||
Commit: 4d8ddc8f0caba470e6526518032b100c7f068a5c
Author: Derick Rethans <github@derickrethans.nl> Wed, 18 Apr 2012 14:54:30 +0200
Parents: c1e32da97a4891f639c296f48c3f5b2d999b5c7b
Branches: master
Link: http://git.php.net/?p=presentations.git;a=commitdiff;h=4d8ddc8f0caba470e6526518032b100c7f068a5c
Log:
4 developers talk tweaks..
Changed paths:
M osm-4dev12.xml
A slides/map/bug.jpg
M slides/map/finding-food-data-mongo.xml
A slides/map/finding-food-import-mongo-script.xml
M slides/map/finding-food-import-mongo.xml
A slides/map/finding-food-import-mongo2.xml
M slides/map/terms-and-conditions.xml
M slides/mongodb/me.xml
diff --git a/osm-4dev12.xml b/osm-4dev12.xml index 41bdef5..61d2f95 100644 --- a/osm-4dev12.xml +++ b/osm-4dev12.xml @@ -1,22 +1,16 @@ <?xml version="1.0" encoding="utf-8"?> -<presentation - template="css" - navmode="html" - navbarbackground="#4373b4" - navbartopiclinks="0" - navColor="#f1fbff" - logo1="" - backgroundfixed="1" > +<presentation> <topic>Maps</topic> <title>Geolocation and Maps with PHP and MongoDB</title> <event>4developers</event> -<location>Poznán, Poland</location> +<location>Poznań, Poland</location> <date>April 18th, 2012</date> <speaker>Derick Rethans</speaker> <email>derick@derickrethans.nl</email> <twitter>derickr</twitter> -<joindin></joindin> +<joindin>http://joind.in/6314</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 @@ -64,6 +58,8 @@ What is X? <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> diff --git a/slides/map/bug.jpg b/slides/map/bug.jpg new file mode 100644 index 0000000..012dba7 Binary files /dev/null and b/slides/map/bug.jpg differ diff --git a/slides/map/finding-food-data-mongo.xml b/slides/map/finding-food-data-mongo.xml index 2f31e57..de7ded8 100644 --- a/slides/map/finding-food-data-mongo.xml +++ b/slides/map/finding-food-data-mongo.xml @@ -5,8 +5,8 @@ <example><![CDATA[<?php header('Content-type: text/plain'); $m = new Mongo( 'mongodb://localhost:27017' ); -$d = $m->selectDb( 'poi' ); -$d->ensureIndex( array( 'poi' => '2d' ) ); +$c = $m->demo->poi; +$c->ensureIndex( array( 'loc' => '2d' ) ); ]]></example> </div> <div effect="fade-in-out"> diff --git a/slides/map/finding-food-import-mongo-script.xml b/slides/map/finding-food-import-mongo-script.xml new file mode 100644 index 0000000..697c0da --- /dev/null +++ b/slides/map/finding-food-import-mongo-script.xml @@ -0,0 +1,126 @@ +<slide> +<title>Importing data</title> + +<example><![CDATA[<?php +$file = $argv[1]; +$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 ) ); + +$locations = array(); + +$z = new XMLReader(); +$z->open( $argv[1]); +while ($z->read() && $z->name !== 'node' ); +$c = 0; + +while ($z->name === 'node') { + $dom = new DomDocument; + $node = simplexml_import_dom($dom->importNode($z->expand(), true)); + + $q = array(); + $q['id'] = "n" . (string) $node['id']; + $q['type'] = 1; + $q['loc'] = array( (float) $node['lon'], (float) $node['lat'] ); + parseNode($q, $node); + if (count($q['tags']) > 0) { + $d->insert( $q ); + } + + // also keep a cache of all nodes and locations + $locations[(string) $node['id']] = "{$node['lon']}|{$node['lat']}"; + + $z->next('node'); + $c++; + if ($c % 1000 === 0) { + echo "."; + } + if ($c % 100000 === 0) { + echo "\n", $c, "\n"; + } +} +echo "\n"; + +$z = new XMLReader(); +$z->open( $argv[1]); +while ($z->read() && $z->name !== 'way' ); +$c = 0; + +while ($z->name === 'way') { + $dom = new DomDocument; + $way = simplexml_import_dom($dom->importNode($z->expand(), true)); + + $q = array(); + $q['id'] = "w" . (string) $node['id']; + $q['type'] = 2; + parseNode($q, $way); + fetchLocations($q, $locations, $way); + if (count($q['tags']) > 0) { + $d->insert( $q ); + } + + $z->next('way'); + if (++$c % 100 === 0) { + echo "."; + } + if ($c % 10000 === 0) { + echo "\n", $c, "\n"; + } +} +echo "\n"; + + +function fetchLocations(&$q, $nodes, $node) +{ + $locations = array(); + foreach ($node->nd as $nd) { + if (isset( $nodes[(string) $nd['ref']])) { + $nr = explode('|', $nodes[(string) $nd['ref']]); + $locations[] = array( (float) $nr[0], (float) $nr[1] ); + } + } + $q['loc'] = $locations; +} + +function parseNode(&$q, $sxml) +{ + $standAloneNode = false; + $street = $postcode = $nr = $cuisine = false; + $tags = $tagsIndexed = array(); + $ignoreTags = array( 'created_by', 'abutters' ); + + foreach( $sxml->tag as $tag ) + { + if ($tag['k'] == 'name') { + $q['name'] = trim( (string) $tag['v'] ); + $standAloneNode = true; + } else { + if (!in_array( $tag['k'], $ignoreTags)) { + $tags[(string) $tag['k']] = (string) $tag['v']; + $tagsIndexed[] = array( 'k' => (string) $tag['k'], 'v' => (string) $tag['v'] ); + } + } + if ($tag['k'] == 'addr:street') { + $street = $tag['v']; + } + if ($tag['k'] == 'addr:postcode') { + $postcode = strtoupper( (string) $tag['v'] ); + } + if ($tag['k'] == 'addr:housenumber') { + $nr = $tag['v']; + } + } + + if ( $street || $nr || $postcode ) + { + $q['address'] = trim( "{$street} {$nr} {$postcode}"); + } + $q['tags'] = $tags; + $q['tags_indexed'] = $tagsIndexed; +} +]]></example> +</slide> diff --git a/slides/map/finding-food-import-mongo.xml b/slides/map/finding-food-import-mongo.xml index e4b0cc1..b534ccc 100644 --- a/slides/map/finding-food-import-mongo.xml +++ b/slides/map/finding-food-import-mongo.xml @@ -17,10 +17,10 @@ $db->poi->ensureIndex( [ 'tags.oneway' => 1 ] );</example> <blurb>or:</blurb> <example>$doc = array( 'name' => 'A440', - 'tags' = { [ - 'k' => 'highway', 'v' => 'secondary', - 'k' => 'oneway', 'v' => 'yes' - ] } + 'tags' = [ + { 'k' => 'highway', 'v' => 'secondary' }, + { 'k' => 'oneway', 'v' => 'yes' } + ] ); $db->poi->ensureIndex( [ 'name' => 1 ] ); diff --git a/slides/map/finding-food-import-mongo2.xml b/slides/map/finding-food-import-mongo2.xml new file mode 100644 index 0000000..57990d8 --- /dev/null +++ b/slides/map/finding-food-import-mongo2.xml @@ -0,0 +1,37 @@ +<slide> +<title>Importing data</title> + +<example>{ + "_id" : ObjectId("4f8d9b6644670adc440510eb"), + "id" : "w1572026939", + "type" : NumberLong(2), + "name" : "Noura", + "address" : "Curzon Street 16 W1J 5HP", + "tags" : { + "addr:housenumber" : "16", + "addr:postcode" : "W1J 5HP", + "addr:street" : "Curzon Street", + "amenity" : "restaurant", + "building" : "yes", + "contact:phone" : "+44 20 74951050", + "cuisine" : "lebanese" + }, + "tags_indexed" : [ + { "k" : "addr:housenumber", "v" : "16" }, + { "k" : "addr:postcode", "v" : "W1J 5HP" }, + { "k" : "addr:street", "v" : "Curzon Street" }, + { "k" : "amenity", "v" : "restaurant" }, + { "k" : "building", "v" : "yes" }, + { "k" : "contact:phone", "v" : "+44 20 74951050" }, + { "k" : "cuisine", "v" : "lebanese" } + ], + "loc" : [ + [ -0.1479191, 51.5067744 ], + [ -0.1480757, 51.5067491 ], + [ -0.1481252, 51.5068679 ], + [ -0.1479687, 51.5068932 ], + [ -0.1479191, 51.5067744 ] + ] +} +</example> +</slide> diff --git a/slides/map/terms-and-conditions.xml b/slides/map/terms-and-conditions.xml index 10f371d..9f80000 100644 --- a/slides/map/terms-and-conditions.xml +++ b/slides/map/terms-and-conditions.xml @@ -1,8 +1,5 @@ <slide> <title>Terms and Conditions</title> -<blurb>OSM:</blurb> -<list><bullet>OpenStreetMap is open data, licensed under the Creative Commons Attribution-ShareAlike 2.0 licence (CC-BY-SA).</bullet></list> -<break/> <blurb>Google Maps:</blurb> <list> <bullet>*Can I generate a map image using the Google Static Maps API which I store and serve from my website?* — You may *not* store and serve copies @@ -15,4 +12,9 @@ Use of the Google Geocoding API is subject to a query limit of 2,500 geolocation requests per day</bullet> </list> +<break/> +<div effect="fade-in"> +<blurb>OSM:</blurb> +<list><bullet>OpenStreetMap is open data, licensed under the Creative Commons Attribution-ShareAlike 2.0 licence (CC-BY-SA).</bullet></list> +</div> </slide> diff --git a/slides/mongodb/me.xml b/slides/mongodb/me.xml index 3a5ab65..3b0cb57 100644 --- a/slides/mongodb/me.xml +++ b/slides/mongodb/me.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<slide template="white"> +<slide template="title"> <title>About Me</title> <image filename="../tdd/derick_photo.jpg" align="right" pdf-float="1" x-offset="21.3" y-offset="10" pdf-scale="0.25"/> @@ -12,4 +12,8 @@ <bullet>Author of the mcrypt, input_filter, dbus, translit and date/time extensions</bullet> </list> +<div class="footer"> +<image align="left" filename="10gen.png" pdf-scale="0.4" x-offset="2" y-offset="12.3"/> +<image align="right" filename="mongodb.png" pdf-scale="0.4" x-offset="18" y-offset="13.3"/> +</div> </slide>
diff --git a/osm-4dev12.xml b/osm-4dev12.xml index 41bdef5..61d2f95 100644 --- a/osm-4dev12.xml +++ b/osm-4dev12.xml @@ -1,22 +1,16 @@ <?xml version="1.0" encoding="utf-8"?> -<presentation - template="css" - navmode="html" - navbarbackground="#4373b4" - navbartopiclinks="0" - navColor="#f1fbff" - logo1="" - backgroundfixed="1" > +<presentation> <topic>Maps</topic> <title>Geolocation and Maps with PHP and MongoDB</title> <event>4developers</event> -<location>Poznán, Poland</location> +<location>Poznań, Poland</location> <date>April 18th, 2012</date> <speaker>Derick Rethans</speaker> <email>derick@derickrethans.nl</email> <twitter>derickr</twitter> -<joindin></joindin> +<joindin>http://joind.in/6314</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 @@ -64,6 +58,8 @@ What is X? <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> diff --git a/slides/map/bug.jpg b/slides/map/bug.jpg new file mode 100644 index 0000000..012dba7 Binary files /dev/null and b/slides/map/bug.jpg differ diff --git a/slides/map/finding-food-data-mongo.xml b/slides/map/finding-food-data-mongo.xml index 2f31e57..de7ded8 100644 --- a/slides/map/finding-food-data-mongo.xml +++ b/slides/map/finding-food-data-mongo.xml @@ -5,8 +5,8 @@ <example><![CDATA[<?php header('Content-type: text/plain'); $m = new Mongo( 'mongodb://localhost:27017' ); -$d = $m->selectDb( 'poi' ); -$d->ensureIndex( array( 'poi' => '2d' ) ); +$c = $m->demo->poi; +$c->ensureIndex( array( 'loc' => '2d' ) ); ]]></example> </div> <div effect="fade-in-out"> diff --git a/slides/map/finding-food-import-mongo-script.xml b/slides/map/finding-food-import-mongo-script.xml new file mode 100644 index 0000000..697c0da --- /dev/null +++ b/slides/map/finding-food-import-mongo-script.xml @@ -0,0 +1,126 @@ +<slide> +<title>Importing data</title> + +<example><![CDATA[<?php +$file = $argv[1]; +$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 ) ); + +$locations = array(); + +$z = new XMLReader(); +$z->open( $argv[1]); +while ($z->read() && $z->name !== 'node' ); +$c = 0; + +while ($z->name === 'node') { + $dom = new DomDocument; + $node = simplexml_import_dom($dom->importNode($z->expand(), true)); + + $q = array(); + $q['id'] = "n" . (string) $node['id']; + $q['type'] = 1; + $q['loc'] = array( (float) $node['lon'], (float) $node['lat'] ); + parseNode($q, $node); + if (count($q['tags']) > 0) { + $d->insert( $q ); + } + + // also keep a cache of all nodes and locations + $locations[(string) $node['id']] = "{$node['lon']}|{$node['lat']}"; + + $z->next('node'); + $c++; + if ($c % 1000 === 0) { + echo "."; + } + if ($c % 100000 === 0) { + echo "\n", $c, "\n"; + } +} +echo "\n"; + +$z = new XMLReader(); +$z->open( $argv[1]); +while ($z->read() && $z->name !== 'way' ); +$c = 0; + +while ($z->name === 'way') { + $dom = new DomDocument; + $way = simplexml_import_dom($dom->importNode($z->expand(), true)); + + $q = array(); + $q['id'] = "w" . (string) $node['id']; + $q['type'] = 2; + parseNode($q, $way); + fetchLocations($q, $locations, $way); + if (count($q['tags']) > 0) { + $d->insert( $q ); + } + + $z->next('way'); + if (++$c % 100 === 0) { + echo "."; + } + if ($c % 10000 === 0) { + echo "\n", $c, "\n"; + } +} +echo "\n"; + + +function fetchLocations(&$q, $nodes, $node) +{ + $locations = array(); + foreach ($node->nd as $nd) { + if (isset( $nodes[(string) $nd['ref']])) { + $nr = explode('|', $nodes[(string) $nd['ref']]); + $locations[] = array( (float) $nr[0], (float) $nr[1] ); + } + } + $q['loc'] = $locations; +} + +function parseNode(&$q, $sxml) +{ + $standAloneNode = false; + $street = $postcode = $nr = $cuisine = false; + $tags = $tagsIndexed = array(); + $ignoreTags = array( 'created_by', 'abutters' ); + + foreach( $sxml->tag as $tag ) + { + if ($tag['k'] == 'name') { + $q['name'] = trim( (string) $tag['v'] ); + $standAloneNode = true; + } else { + if (!in_array( $tag['k'], $ignoreTags)) { + $tags[(string) $tag['k']] = (string) $tag['v']; + $tagsIndexed[] = array( 'k' => (string) $tag['k'], 'v' => (string) $tag['v'] ); + } + } + if ($tag['k'] == 'addr:street') { + $street = $tag['v']; + } + if ($tag['k'] == 'addr:postcode') { + $postcode = strtoupper( (string) $tag['v'] ); + } + if ($tag['k'] == 'addr:housenumber') { + $nr = $tag['v']; + } + } + + if ( $street || $nr || $postcode ) + { + $q['address'] = trim( "{$street} {$nr} {$postcode}"); + } + $q['tags'] = $tags; + $q['tags_indexed'] = $tagsIndexed; +} +]]></example> +</slide> diff --git a/slides/map/finding-food-import-mongo.xml b/slides/map/finding-food-import-mongo.xml index e4b0cc1..b534ccc 100644 --- a/slides/map/finding-food-import-mongo.xml +++ b/slides/map/finding-food-import-mongo.xml @@ -17,10 +17,10 @@ $db->poi->ensureIndex( [ 'tags.oneway' => 1 ] );</example> <blurb>or:</blurb> <example>$doc = array( 'name' => 'A440', - 'tags' = { [ - 'k' => 'highway', 'v' => 'secondary', - 'k' => 'oneway', 'v' => 'yes' - ] } + 'tags' = [ + { 'k' => 'highway', 'v' => 'secondary' }, + { 'k' => 'oneway', 'v' => 'yes' } + ] ); $db->poi->ensureIndex( [ 'name' => 1 ] ); diff --git a/slides/map/finding-food-import-mongo2.xml b/slides/map/finding-food-import-mongo2.xml new file mode 100644 index 0000000..57990d8 --- /dev/null +++ b/slides/map/finding-food-import-mongo2.xml @@ -0,0 +1,37 @@ +<slide> +<title>Importing data</title> + +<example>{ + "_id" : ObjectId("4f8d9b6644670adc440510eb"), + "id" : "w1572026939", + "type" : NumberLong(2), + "name" : "Noura", + "address" : "Curzon Street 16 W1J 5HP", + "tags" : { + "addr:housenumber" : "16", + "addr:postcode" : "W1J 5HP", + "addr:street" : "Curzon Street", + "amenity" : "restaurant", + "building" : "yes", + "contact:phone" : "+44 20 74951050", + "cuisine" : "lebanese" + }, + "tags_indexed" : [ + { "k" : "addr:housenumber", "v" : "16" }, + { "k" : "addr:postcode", "v" : "W1J 5HP" }, + { "k" : "addr:street", "v" : "Curzon Street" }, + { "k" : "amenity", "v" : "restaurant" }, + { "k" : "building", "v" : "yes" }, + { "k" : "contact:phone", "v" : "+44 20 74951050" }, + { "k" : "cuisine", "v" : "lebanese" } + ], + "loc" : [ + [ -0.1479191, 51.5067744 ], + [ -0.1480757, 51.5067491 ], + [ -0.1481252, 51.5068679 ], + [ -0.1479687, 51.5068932 ], + [ -0.1479191, 51.5067744 ] + ] +} +</example> +</slide> diff --git a/slides/map/terms-and-conditions.xml b/slides/map/terms-and-conditions.xml index 10f371d..9f80000 100644 --- a/slides/map/terms-and-conditions.xml +++ b/slides/map/terms-and-conditions.xml @@ -1,8 +1,5 @@ <slide> <title>Terms and Conditions</title> -<blurb>OSM:</blurb> -<list><bullet>OpenStreetMap is open data, licensed under the Creative Commons Attribution-ShareAlike 2.0 licence (CC-BY-SA).</bullet></list> -<break/> <blurb>Google Maps:</blurb> <list> <bullet>*Can I generate a map image using the Google Static Maps API which I store and serve from my website?* — You may *not* store and serve copies @@ -15,4 +12,9 @@ Use of the Google Geocoding API is subject to a query limit of 2,500 geolocation requests per day</bullet> </list> +<break/> +<div effect="fade-in"> +<blurb>OSM:</blurb> +<list><bullet>OpenStreetMap is open data, licensed under the Creative Commons Attribution-ShareAlike 2.0 licence (CC-BY-SA).</bullet></list> +</div> </slide> diff --git a/slides/mongodb/me.xml b/slides/mongodb/me.xml index 3a5ab65..3b0cb57 100644 --- a/slides/mongodb/me.xml +++ b/slides/mongodb/me.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<slide template="white"> +<slide template="title"> <title>About Me</title> <image filename="../tdd/derick_photo.jpg" align="right" pdf-float="1" x-offset="21.3" y-offset="10" pdf-scale="0.25"/> @@ -12,4 +12,8 @@ <bullet>Author of the mcrypt, input_filter, dbus, translit and date/time extensions</bullet> </list> +<div class="footer"> +<image align="left" filename="10gen.png" pdf-scale="0.4" x-offset="2" y-offset="12.3"/> +<image align="right" filename="mongodb.png" pdf-scale="0.4" x-offset="18" y-offset="13.3"/> +</div> </slide>