Your SlideShare is downloading. ×
0
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Where in the world
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Where in the world

1,298

Published on

Slides from my php geodata talk at DPC10.

Slides from my php geodata talk at DPC10.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,298
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • - Different datums: WGS84, NAD27, NAD83…
  • Simple as yes or no…
  • Distance between 2 points…(don't mention solutions)
  • Regions can overlap…
  • Remember this?So, if 80%...DISCOVERY
  • Accuracy: to nearest exchangeReliability: proxies, VPNs, Networks structure
  • Other IP geo-databases availableAPI options
  • Single positionContinously updating positionPermit stale data
  • EXIF – used by some camerasGives latitude, longitude, and lat-reg (N/S), long-ref (E/W)
  • Twitter4 squareGowallaSocial graphSearch by hash-tags; user-configured integration…endless choiceCustom file input
  • Having gone to all this effort to find this data, you’re going to throw it away.
  • Also get analysis tools
  • OGC - Open Geospatial Consortium - standards
  • Please document the format…for your colleague's sanity!
  • Co-ordinate conversion is complicatedUse a library
  • Cartesian geometry for a grid based system
  • Haversine corrects for projection distortion over long distancesSpheroid geometrySuffers from antipodal errors – use Vincenty insteadNote the Greek
  • JS
  • Most overlays require cartesian geometry – need to convert.
  • Go see Mike's uncon talk at 2pm
  • Transcript

    • 1. Where in the World?<br />Geo-data in PHP<br />
    • 2. 80% of data has a geo-component<br />
    • 3. Some background<br />
    • 4. Mercator - 1569<br />
    • 5. 51 28’ 38”N0 0’ 0” E<br />Munich, 11E<br />Paris, 2E<br />Madrid, 3W<br />Prime meridian<br />Know your datum!<br />
    • 6. Points<br />Paris<br />52°20'28N, 04°53'25E<br />12 Grimmauld Place, London<br />What makes up geo-data?<br />
    • 7. Lines<br />M4<br />Sunset Boulevard<br />Dover TSS<br />What makes up geo-data?<br />
    • 8. Polygons<br />London<br />Somerset<br />Contour<br />What makes up geo-data?<br />
    • 9. Is point x within y?<br />Questions, questions…<br />
    • 10. Does line x pass through y?<br />Questions, questions…<br />
    • 11. How far is point x from point y?<br />Questions, questions…<br />
    • 12. Which region is point x within?<br />Regions can overlap:<br />District: ClaphamBorough: WandswothCity: LondonCountry: UK<br />Questions, questions…<br />
    • 13. 80% of data has a geo-component<br />So how do I find it?<br />
    • 14. Geo-data from web visitors<br />
    • 15. Every web visitor offers 2 sources of geo-data:<br /><ul><li> IP address
    • 16. Ask the browser!</li></ul>Where is my visitor?<br />
    • 17. home<br />51 26’ 55.2” N<br />0 0’ 0.1” W<br />exchange<br />Accurate?<br />IP gives you the location of the Serving area interface (telco exchange).<br />Some exchanges can be 5 miles away!<br />home<br />office<br />Reliable?<br />Proxies<br />VPNs<br />Network distributions (ever tried geo-locating an AOL IP?)<br />exchange<br />The problem with IP<br />
    • 18. include("geoip.inc"); <br />$gi = geoip_open("/usr/local/share/GeoIP/GeoIP.dat",GEOIP_STANDARD);<br />$country_code = geoip_country_code_by_addr($gi, "24.24.24.24");<br />$country_name = geoip_country_name_by_addr($gi, "24.24.24.24”); <br />Free data library from MaxMind….<br /><ul><li>Pure PHP
    • 19. Pear extension
    • 20. Apache module</li></ul>Use the code…<br />
    • 21. function myCallback(position) {<br /> // called if the browser reports its location<br />}<br />if (navigator.geolocation) {navigator.geolocation.getCurrentPosition(myCallback);<br />}<br />W3C spec:http://dev.w3.org/geo/api/spec-source.html<br />Mozilla, where art thou?<br />
    • 22. Geo-data from content<br />
    • 23. “Journey’s End”by nathanhayag<br />“MacRitchie Reservoir, Singapore”<br />Geo-data encoded in the image file:<br />1°22'18”N103°49'27"E<br />A picture says a thousand words<br />
    • 24. $exif = exif_read_data('file.jpg');<br />$long[‘deg’] = $exif['GPSLongitude'][0];<br />$long[‘min’] = $exif['GPSLongitude'][1] / 60;<br />$long[‘sec’] = $exif['GPSLongitude'][2] / 3600;<br />$lat[‘deg’] = $exif['GPSLatitude'][0];<br />$lat[‘min’] = $exif['GPSLatitude'][1] / 60;<br />$lat[‘sec’] = $exif['GPSLatitude'][2] / 3600;<br />Reading EXIF<br />
    • 25. “Journey’s End”by nathanhayag<br />“MacRitchie Reservoir, Singapore”<br />Parse text for location data….<br />Usual PHP information retrieval techniques apply<br />http://phpir.com/ to learn more<br />A picture says a thousand words<br />
    • 26. “Journey’s End”by nathanhayag<br />“MacRitchie Reservoir, Singapore”<br />Feeling brave?<br />Image recognition and association<br />A picture says a thousand words<br />
    • 27. External sources<br />
    • 28. Don’t forget…<br />
    • 29. Primitive data-types<br />$long = 51.5723<br />$lat = -0.0179<br />Class structures<br />$point = new GISPoint;<br />$point->setLatitude(51,21,35,'N');<br />$point->setLongitude(0,1,21, 'W');<br />Geo-data in PHP variables<br />
    • 30. MySQL storage<br />CREATE TABLE tweet(<br /> id BIGINT,<br /> user VARCHAR(15),<br /> message VARCHAR(140),<br /> location VARCHAR(16)<br /> );<br />INSERT INTO tweet VALUES (<br /> 15924144610,<br /> 'manarth',<br /> 'hello!',<br /> '0512732N0000319W'<br /> ); <br />Persistent storage<br />
    • 31. MySQL Spatial extensions<br />CREATE TABLE tweet(<br /> id BIGINT,<br /> user VARCHAR(15),<br /> message VARCHAR(140),<br />location POINT<br /> );<br />INSERT INTO tweet VALUES (<br /> 15924144610,<br /> 'manarth',<br /> 'hello!',<br />PointFromWKT(Point(51.1,-0.2))<br /> ); <br />Spatial extensions<br />
    • 32. MySQL<br />MS SQL<br />Oracle<br />Postgres – PostGIS<br />Geo-data in the DB<br />
    • 33. WKT: Well Known Text<br />POINT(6 10) LINESTRING(3 4,10 50,20 25)<br />WKB: Well Known Binary<br />1010010001001010<br />GeoJSON<br />{<br /> "geometry": {<br /> "type" : "Point",<br /> "coordinates" : [97.03125, 39.7265625] }<br />}<br />Write to disk?<br />
    • 34. Binary Terrain<br />Coverage (ArcGIS)<br />DEM <br />Spatial Data File (Autodesk)<br />…<br />More (obscure) formats<br />
    • 35. Discovery<br />Storage<br />Analysis<br />
    • 36. Geo-centric:Cartesian<br />http://trac.osgeo.org/proj/wiki/man_cs2cs<br />Coordinate conversion<br />
    • 37. Cartesian geometry<br />a<br />(x1, y1)<br />√<br />(y1 – y2)2 + (x2 – x1)2<br />y1 – y2<br />b<br />x2 – x1<br />(x2, y2)<br />Distance from a to b<br />
    • 38. Geo-centric geometry<br />Greater circle route<br />a<br />(λs, Φs)<br />Haversine formula<br />b<br />(λf, Φf)<br />Distance from a to b<br />
    • 39. function haversine($a) {<br /> return (sin($a/2) * sin($a/2));<br />}<br />function ahaversine($a) {<br /> return 2 * asin(sqrt($a));<br />}<br />function haversine_separation($a, $b) {<br /> // assume a radius of 3956 miles.<br /> define ('RADIUS', 3956);<br /> // convert degree inputs to radians<br /> $a = array(deg2rad($a['long']), deg2rad($a['lat']));<br /> $b = array(deg2rad($b['long']), deg2rad($b['lat']));<br /> $x = haversine($a['long'] - $b['long']) + (cos($a['long']) * cos($b['long']) * haversine(abs($a['lat'] - $b['lat'])));<br /> // $d (distance) is therefore R * inverse haversine($x)<br /> $d = RADIUS * ihaversine($x);<br /> return $d;<br />}<br />Haversine calculations<br />
    • 40. SELECT DISTANCE(a, b);<br />SELECT INTERSECTS (a, b);<br />SELECT DISJOINT (a, b);<br />SELECT OVERLAPS (a, b);<br />SELECT CONTAINS (a, b);<br />SELECT WITHIN (a, b);<br />Some limitations – currently measures against MBR – Minimum Bounding Rectangle<br />Spatial analysis in MySQL<br />
    • 41. Discovery<br />Storage<br />Analysis<br />Visualisation<br />
    • 42. Map APIs<br />
    • 43. Simple overlays<br />
    • 44. Heatmaps<br />
    • 45. Custom visualisation<br />
    • 46. Image generation<br />
    • 47. Upcoming conferences<br /><ul><li>Bristol Indiemedia Bristol – June
    • 48. Ignite BristolBristol - July
    • 49. DrupalconCopenhagen - August
    • 50. PHP NWManchester - October</li></ul>Upcoming conferences<br /><ul><li>DrupalconCopenhagen - August
    • 51. PHP NWManchester - October
    • 52. PHP BarcelonaBarcelona - October
    • 53. ZendConSanta Clara - October</li></ul>Loremipsum<br />Loremipsum dolor sit amet, consecteturadipisicingelit, sed do eiusmodtemporincididuntutlabore et dolore magna aliqua. Utenim ad minim veniam,<br />quisnostrud exercitation ullamcolaboris nisi utaliquip ex ea commodoconsequat. Duisauteirure dolor in reprehenderit in voluptatevelitessecillumdoloreeu<br />fugiatnullapariatur. Excepteursintoccaecatcupidatat non proident, sunt in culpa qui officiadeseruntmollitanim id estlaborum<br />Invisible feedback<br />
    • 54. Discovery<br />Storage<br />Analysis<br />Visualisation<br />
    • 55. 80% of data has a geo-component<br />
    • 56. Marcus Deglos<br />marcus@deglos.com<br />http://deglos.com/<br />@manarth<br />Thanks for coming!<br />http://joind.in/1555<br />

    ×