com presentations: Added new slides for my Mongo/OSM talk for IPC.: mongo-osm-ipc12.xml slides/map/find-mongo-html.xml slides/map/find-mongo.xml
slides/map/find-mongo2.xml slides/map/finding-food-import-mongo.xml slides/map/finding-food-import-mongo2.xml slides/map/finding-food-take2.xml
slides/map/import-script1.xml slides/map/import-script2.xml slides/map/import-sizes1.xml slides/map/osm-parse-into-db.xml slides/map/title.xml
slides/mongodb/osm

From: Date: Fri, 12 Oct 2012 16:53:43 +0000
Subject: com presentations: Added new slides for my Mongo/OSM talk for IPC.: mongo-osm-ipc12.xml slides/map/find-mongo-html.xml slides/map/find-mongo.xml
slides/map/find-mongo2.xml slides/map/finding-food-import-mongo.xml slides/map/finding-food-import-mongo2.xml slides/map/finding-food-take2.xml
slides/map/import-script1.xml slides/map/import-script2.xml slides/map/import-sizes1.xml slides/map/osm-parse-into-db.xml slides/map/title.xml
slides/mongodb/osm
Groups: php.pres 
Request: Send a blank email to pres+get-1852@lists.php.net to get a copy of this message
Commit: 087def5125aa25a7055cff25bc54214d2a9bc5eb Author: Derick Rethans <github@derickrethans.nl> Fri, 12 Oct 2012 17:53:43 +0100 Parents: 37beb61c8268864f69580b1d9a937e6676475cfa Branches: master Link: http://git.php.net/?p=presentations.git;a=commitdiff;h=087def5125aa25a7055cff25bc54214d2a9bc5eb Log: Added new slides for my Mongo/OSM talk for IPC. Changed paths: A mongo-osm-ipc12.xml A slides/map/find-mongo-html.xml A slides/map/find-mongo.xml A slides/map/find-mongo2.xml M slides/map/finding-food-import-mongo.xml M slides/map/finding-food-import-mongo2.xml M slides/map/finding-food-take2.xml A slides/map/import-script1.xml A slides/map/import-script2.xml A slides/map/import-sizes1.xml M slides/map/osm-parse-into-db.xml M slides/map/title.xml A slides/mongodb/osm-schema1.xml A slides/mongodb/osm-schema2.xml A slides/mongodb/osm-schema3.xml

diff --git a/mongo-osm-ipc12.xml b/mongo-osm-ipc12.xml new file mode 100644 index 0000000..163c366 --- /dev/null +++ b/mongo-osm-ipc12.xml @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="utf-8"?> +<presentation css="10gen-strict.css"> +<topic>Maps</topic> +<title>Store a Country in your Database</title> +<event>International PHP Conference</event> +<location>Mainz, Germany</location> +<date>October 16th, 2012</date> +<speaker>Derick Rethans</speaker> +<email>derick@derickrethans.nl</email> +<twitter>derickr</twitter> +<joindin>http://joind.in/7316</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. +--> + +<!-- +What is X? +--> +<slide>slides/map/osm-what.xml</slide> +<slide>slides/map/what-is-osm.xml</slide> +<slide>slides/map/leaflet.xml</slide> + +<slide>slides/map/osm-data.xml</slide> + +<slide>slides/map/osm-tags1.xml</slide> +<slide>slides/map/osm-tags2.xml</slide> +<slide>slides/map/osm-tags3.xml</slide> +<slide>slides/map/osm-tags4.xml</slide> +<slide>slides/map/osm-tags-edit.xml</slide> + + +<slide>slides/map/osm-mapping-party1.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/mongodb/osm-to-mongo-data.xml</slide> +<slide>slides/mongodb/osm-to-mongo-data2.xml</slide> +<slide>slides/mongodb/osm-to-mongo-data3.xml</slide> +<slide>slides/mongodb/osm-to-mongo-data4.xml</slide> +<slide>slides/mongodb/osm-schema1.xml</slide> +<slide>slides/mongodb/osm-schema2.xml</slide> +<slide>slides/mongodb/osm-schema3.xml</slide> +<slide>slides/map/finding-food-import-mongo2.xml</slide> +<slide>slides/map/import-script1.xml</slide> +<slide>slides/map/import-sizes1.xml</slide> +<slide>slides/map/import-script2.xml</slide> + +<slide>slides/mongodb/idx-geo.xml</slide> +<slide>slides/mongodb/idx-geo2.xml</slide> +<slide>slides/mongodb/idx-geo-geohash.xml</slide> +<slide>slides/mongodb/idx-geo3.xml</slide> +<slide>slides/mongodb/idx-geo4.xml</slide> + +<slide>slides/map/find-mongo.xml</slide> +<slide>slides/map/find-mongo2.xml</slide> +<slide>slides/map/find-mongo-html.xml</slide> +<slide>slides/map/finding-food-take2.xml</slide> + +<slide>slides/mongodb/resources.xml</slide> + +</presentation> diff --git a/slides/map/find-mongo-html.xml b/slides/map/find-mongo-html.xml new file mode 100644 index 0000000..8b25285 --- /dev/null +++ b/slides/map/find-mongo-html.xml @@ -0,0 +1,139 @@ +<slide> +<title>The HTML side</title> + +<example><![CDATA[ +<!DOCTYPE html> +<html> +<head> + <title>Your Country in a Database</title> + <meta charset="utf-8" /> + <style> +body { + padding: 0; + margin: 0; +} +html, body, #map { + height: 100%; +} +#search { + z-index: 1000; + position: absolute; + top: 10px; + right: 30px; + width: 250px; + background-color: white; + border: 1px solid black; + padding: 4px; +} + </style> + + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + + <link rel="stylesheet" href="leaflet.css" /> + + <!--[if lte IE 8]><link rel="stylesheet" href="leaflet.ie.css" /><![endif]--> +</head> + +<body> + <div id="map"></div> + <div id='search'> + <form> + <input size="5" name='radius' id='radius' type='text' value='0.5'/> km<br/> + <input onClick="changeQuery(); return false;" type='submit' value="Find!"/> + </form> + + </div> + + <script src="leaflet.js"></script> + <script type="text/javascript" src="jquery-1.7.2.min.js"></script> + + <script> + var map = new L.Map('map'); + + var cloudmadeUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', + cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors', + cloudmade = new L.TileLayer( + cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution} + ); + + map.setView(new L.LatLng(51.5116, -0.1019), 17).addLayer(cloudmade); + + var geojsonMarkerOptions = { + radius: 12, + fillColor: "#8888ff", + color: "#33f", + weight: 1, + opacity: 1, + fillOpacity: 0.6 + }; + var geojsonAreaOptions = { + radius: 8, + fillColor: "#8888ff", + color: "#33f", + weight: 1, + opacity: 1, + fillOpacity: 0.2 + }; + + var geoJsonOptions = { + pointToLayer: function (latlng) { + myOptions = geojsonMarkerOptions; + myOptions.radius = calcCircleSize(); + return new L.CircleMarker(latlng, myOptions); + } + } + + var geojsonLayer = new L.GeoJSON(null, geoJsonOptions); + map.addLayer(geojsonLayer); + geojsonLayer.on("featureparse", function (e) { + if (e.properties && e.properties.popupContent){ + e.layer.bindPopup(e.properties.popupContent); + } + if (e.properties && e.properties.style && e.layer.setStyle) { + e.layer.setStyle(e.properties.style); + } else if (e.geometryType == 'Polygon' && map.getZoom() >= 16) { + e.layer.setStyle(geojsonAreaOptions); + } else { + e.layer.setStyle(geojsonMarkerOptions); + } + }); + + map.on('moveend', changeLocation); + + var popup = new L.Popup(); + + function calcCircleSize() { + z = map.getZoom(); + return Math.min(12, Math.max(2, 15 - ((15-z) * 3))); + } + + function changeLocation(event) { + center = map.getCenter(); + + radiusInput = document.getElementById('radius'); + + $.ajax({ + url: "fetch-mongo-fixed2.php" + + '?lat=' + center.lat + '&lon=' + center.lng + + '&d=' + radiusInput.value, + beforeSend: function ( xhr ) { + xhr.overrideMimeType("text/plain; charset=x-user-defined"); + } + }).done(function ( data ) { + geojsonLayer.clearLayers(); + res = jQuery.parseJSON(data); + res.forEach( function(value) { + if (map.getZoom() < 16 && value.geometry.type == 'Polygon') { + value.geometry.type = 'Point'; + value.geometry.coordinates = value.geometry.coordinates[0][0]; + } + geojsonLayer.addGeoJSON(value); + + } ); + }); + } + </script> +</body> +</html> +]]></example> +</slide> diff --git a/slides/map/find-mongo.xml b/slides/map/find-mongo.xml new file mode 100644 index 0000000..5ad7c53 --- /dev/null +++ b/slides/map/find-mongo.xml @@ -0,0 +1,22 @@ +<slide> +<title>Querying our dataset</title> + +<example> +$m = new Mongo( 'mongodb://localhost' ); +$d = $m->selectDb( 'demo' ); + +$wantedD = isset($_GET['d']) ? $_GET['d']: 1; +$query = array( 'tags' => array( '$not' => array( '$size' => 0 ) ) ); + +$s = $d->command( + array( + 'geoNear' => 'poi', + 'spherical' => true, + 'near' => array( (float) $_GET['lon'], (float) $_GET['lat'] ), + 'num' => 250, + 'maxDistance' => $wantedD / 6371.01, + 'query' => $query, + ) +); +</example> +</slide> diff --git a/slides/map/find-mongo2.xml b/slides/map/find-mongo2.xml new file mode 100644 index 0000000..be373ec --- /dev/null +++ b/slides/map/find-mongo2.xml @@ -0,0 +1,47 @@ +<slide> +<title>Converting to GEOJson</title> + +<example> +foreach( $s['results'] as $res) +{ + $o = $res['obj']; + $ret = array( + 'type' => 'Feature', + 'properties' => array( 'popupContent' => '' ), + ); + if ( isset( $o['tags'] ) ) { + $name = $content = ''; + foreach ( $o['tags'] as $tagName => $value ) { + list( $tagName, $value ) = explode( '=', $value ); + if ( $tagName == 'name' ) { + $name = $value; + } else { + $content .= "<br/>{$tagName}: {$value}\n"; + } + } + $ret['properties']['popupContent'] = "<b>{$name}</b>" . $content; + } + if ($o['type'] == 1) { + $ret['geometry'] = array( + 'type' => "Point", + 'coordinates' => $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; +} +echo json_encode( $rets, JSON_PRETTY_PRINT ); +</example> +</slide> diff --git a/slides/map/finding-food-import-mongo.xml b/slides/map/finding-food-import-mongo.xml index da632cb..2f8dbe8 100644 --- a/slides/map/finding-food-import-mongo.xml +++ b/slides/map/finding-food-import-mongo.xml @@ -19,7 +19,7 @@ $db->poi->find( [ 'name' => 'Strand' ] ); $db->poi->find( [ 'tags.highway' => [ '$exists' => 1 ] ] ); </example> <list> - <bullet>Lots of indexed are required</bullet> + <bullet>Lots of indexes are required</bullet> <bullet>Easy to extract data from</bullet> </list> </div> diff --git a/slides/map/finding-food-import-mongo2.xml b/slides/map/finding-food-import-mongo2.xml index 57990d8..4da5bfe 100644 --- a/slides/map/finding-food-import-mongo2.xml +++ b/slides/map/finding-food-import-mongo2.xml @@ -2,28 +2,18 @@ <title>Importing data</title> <example>{ - "_id" : ObjectId("4f8d9b6644670adc440510eb"), - "id" : "w1572026939", + "_id" : "w77002328", "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" } + "tags" : [ + "addr:housenumber=16", + "addr:postcode=W1J 5HP", + "addr:street=Curzon Street", + "amenity=restaurant", + "building=yes", + "contact:phone=+44 20 74951050", + "cuisine=lebanese", + "name=Noura" ], "loc" : [ [ -0.1479191, 51.5067744 ], diff --git a/slides/map/finding-food-take2.xml b/slides/map/finding-food-take2.xml index 568b395..3d0b6ec 100644 --- a/slides/map/finding-food-take2.xml +++ b/slides/map/finding-food-take2.xml @@ -1,5 +1,5 @@ <slide> -<title>Seeing the data</title> +<title>The data in action!</title> <iframe filename='examples/find-poi-mongo2.php'/> </slide> diff --git a/slides/map/import-script1.xml b/slides/map/import-script1.xml new file mode 100644 index 0000000..2398f0e --- /dev/null +++ b/slides/map/import-script1.xml @@ -0,0 +1,25 @@ +<slide> +<title>The import script (1)</title> + +<list> + <bullet>Open file with XML Reader</bullet> + <bullet>Loop over all nodes, and: + <list> + <bullet>Store their latitude/longitude in an array</bullet> + <bullet>If the node has tags, store the node in the database</bullet> + </list> + <example> +"_id" : "n105", +"type" : NumberLong(1), +"loc" : [ -0.1430911, 51.5238028 ], +"tags" : [ "amenity=pub", "name=The Green Man" ] + </example> + </bullet> + <bullet>Loop over all the ways, and: + <list> + <bullet>Look up locations for each node in the node array</bullet> + <bullet>Store the way into the database</bullet> + </list> + </bullet> +</list> +</slide> diff --git a/slides/map/import-script2.xml b/slides/map/import-script2.xml new file mode 100644 index 0000000..0a2e7a0 --- /dev/null +++ b/slides/map/import-script2.xml @@ -0,0 +1,30 @@ +<slide> +<title>The import script (2)</title> + +<list> + <bullet>Open file with XML Reader</bullet> + <bullet>Loop over all nodes, and: + <list> + <bullet>*Store the node in the database*</bullet> + </list> + </bullet> + <bullet>Loop over all the ways, and: + <list> + <bullet>*Look up locations for each node in the database*</bullet> + <bullet>Store the way into the database</bullet> + </list> + </bullet> + <bullet>Memory usage: 1.3 MB </bullet> + <bullet>But quite a bit slower</bullet> +</list> +<example> +"count" : 2253986, +"size" : 213572964, +"avgObjSize" : 94.7534563213791, +"storageSize" : 339603456, +"totalIndexSize" : 354830224, +"indexSizes" : { + "_id_" : 118846336, "loc_2d" : 74156320, "tags_1" : 161827568 +}, +</example> +</slide> diff --git a/slides/map/import-sizes1.xml b/slides/map/import-sizes1.xml new file mode 100644 index 0000000..fd01a7d --- /dev/null +++ b/slides/map/import-sizes1.xml @@ -0,0 +1,24 @@ +<slide> +<title>Usage</title> + +<blurb>London:</blurb> +<list> + <bullet>2 million nodes / 750 thousand ways</bullet> + <bullet>Memory usage: 827 MB </bullet> + <bullet>DB stats: + <example> +"count" : 445689, +"size" : 135102204, +"avgObjSize" : 303.1311160921629, +"storageSize" : 159219712, +"totalIndexSize" : 188677552, +"indexSizes" : { "_id_" : 22712928, "loc_2d" : 91906416, "tags_1" : 74058208 }, + </example> + </bullet> +</list> +<blurb>United Kingdom:</blurb> +<list> + <bullet>45 million nodes / 10 million ways</bullet> + <bullet>which is 20 times as much…</bullet> +</list> +</slide> diff --git a/slides/map/osm-parse-into-db.xml b/slides/map/osm-parse-into-db.xml index ff8255a..d970c7d 100644 --- a/slides/map/osm-parse-into-db.xml +++ b/slides/map/osm-parse-into-db.xml @@ -7,6 +7,6 @@ <bullet>Parse XML file with PHP into a DB (MongoDB)</bullet> <bullet>Query database</bullet> <bullet>Show data</bullet> - <bullet>Profit (or in our case, we found a restaurant)!</bullet> + <bullet>WIN!</bullet> </list> </slide> diff --git a/slides/map/title.xml b/slides/map/title.xml index e806577..32f5edb 100644 --- a/slides/map/title.xml +++ b/slides/map/title.xml @@ -1,6 +1,8 @@ <slide template="white" type="title" background="london-map-old.jpg"> <blurb class="event-title">:-:title:-:</blurb> -<blurb class="event-date">:-:event:-: - :-:location:-: - :-:date:-:</blurb> +<blurb class="event-date">:-:event:-:</blurb> +<blurb class="event-date">:-:location:-: - :-:date:-:</blurb> +<break/> <blurb class="event-presenter">Derick Rethans - :-:email:-: - twitter: @:-:twitter:-:</blurb> <blurb class="pres-url-small">:-:url:-:</blurb> <blurb class="pres-url-small">:-:joindin:-:</blurb> diff --git a/slides/mongodb/osm-schema1.xml b/slides/mongodb/osm-schema1.xml new file mode 100644 index 0000000..8254377 --- /dev/null +++ b/slides/mongodb/osm-schema1.xml @@ -0,0 +1,25 @@ +<slide> +<title>Tags as a key/value combination</title> + +<example>$doc = array( + 'name' => 'A440', + 'tags' => [ + 'highway' => 'secondary', + 'oneway' => 'yes' + ] +); +$db->poi->ensureIndex( [ 'name' => 1 ] ); +$db->poi->ensureIndex( [ 'tags.highway' => 1 ] ); +$db->poi->ensureIndex( [ 'tags.oneway' => 1 ] ); + +// Road with name=Strand +$db->poi->find( [ 'name' => 'Strand' ] ); +// All roads +$db->poi->find( [ 'tags.highway' => [ '$exists' => 1 ] ] ); +</example> +<list> + <bullet>Lots of indexes are required</bullet> + <bullet>Easy to extract data from</bullet> +</list> +</slide> + diff --git a/slides/mongodb/osm-schema2.xml b/slides/mongodb/osm-schema2.xml new file mode 100644 index 0000000..30ded34 --- /dev/null +++ b/slides/mongodb/osm-schema2.xml @@ -0,0 +1,29 @@ +<slide> +<title>Tags as dictionary</title> + +<example>$doc = array( + 'tags' => [ + [ 'k' => 'name', 'v' => 'A440' ], + [ 'k' => 'highway', 'v' => 'secondary' ], + [ 'k' => 'oneway', 'v' => 'yes' ] + ] +); +$db->poi->ensureIndex( [ 'tags.v' => 1, 'tags.k' => 1 ] ); + +// Road with name=Strand +$db->poi->find( [ + 'tags' => [ '$elemMatch' => [ 'k' : 'name', 'v' : 'Strand' ] ] +] ); +// All roads +$db->poi->find( [ 'tags.k' => 'highway' ] ); +</example> +<list> + <bullet>Two indexes required: + <list> + <bullet>one for key/value combinations</bullet> + <bullet>one for "all roads" question (on %tags_indexed.k%)</bullet> + </list> + </bullet> + <bullet>Good for finding key/value combinations</bullet> +</list> +</slide> diff --git a/slides/mongodb/osm-schema3.xml b/slides/mongodb/osm-schema3.xml new file mode 100644 index 0000000..f71b391 --- /dev/null +++ b/slides/mongodb/osm-schema3.xml @@ -0,0 +1,22 @@ +<slide> +<title>Tags as concatenated strings</title> + +<example>$doc = array( + 'tags' => [ + 'name=A440', + 'highway=secondary', + 'oneway=yes' + ] +); +$db->poi->ensureIndex( [ 'tags' => 1 ] ); + +// Road with name=Strand +$db->poi->find( [ 'tags' => 'name=Strand' ] ); +// All roads +$db->poi->find( [ 'tags' => new MongoRegex( '/^highway=/' ) ] );</example> +<list> + <bullet>One index required</bullet> + <bullet>Good for finding key/value combinations</bullet> + <bullet>Good enough for doing the "all roads" question</bullet> +</list> +</slide>
« previous php.pres (#1852) next »