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

More Related Content

Similar to Where in the world

Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesDas Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesStephan Schmidt
 
Geolocation on Rails
Geolocation on RailsGeolocation on Rails
Geolocation on Railsnebirhos
 
Handling Real-time Geostreams
Handling Real-time GeostreamsHandling Real-time Geostreams
Handling Real-time Geostreamsguest35660bc
 
Handling Real-time Geostreams
Handling Real-time GeostreamsHandling Real-time Geostreams
Handling Real-time GeostreamsRaffi Krikorian
 
OSCON july 2011
OSCON july 2011OSCON july 2011
OSCON july 2011chelm
 
Better Visualization of Trips through Agglomerative Clustering
Better Visualization of  Trips through     Agglomerative ClusteringBetter Visualization of  Trips through     Agglomerative Clustering
Better Visualization of Trips through Agglomerative ClusteringAnbarasan S
 
Geo search introduction
Geo search introductionGeo search introduction
Geo search introductionkenshin03
 
Intro To PostGIS
Intro To PostGISIntro To PostGIS
Intro To PostGISmleslie
 
Perlで任意精度計算
Perlで任意精度計算Perlで任意精度計算
Perlで任意精度計算lestrrat
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2osfameron
 
10. Getting Spatial
10. Getting Spatial10. Getting Spatial
10. Getting SpatialFAO
 
R getting spatial
R getting spatialR getting spatial
R getting spatialFAO
 

Similar to Where in the world (20)

Fun with Maps and PHP
Fun with Maps and PHPFun with Maps and PHP
Fun with Maps and PHP
 
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesDas Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
 
Geolocation on Rails
Geolocation on RailsGeolocation on Rails
Geolocation on Rails
 
Handling Real-time Geostreams
Handling Real-time GeostreamsHandling Real-time Geostreams
Handling Real-time Geostreams
 
Handling Real-time Geostreams
Handling Real-time GeostreamsHandling Real-time Geostreams
Handling Real-time Geostreams
 
OSCON july 2011
OSCON july 2011OSCON july 2011
OSCON july 2011
 
Better Visualization of Trips through Agglomerative Clustering
Better Visualization of  Trips through     Agglomerative ClusteringBetter Visualization of  Trips through     Agglomerative Clustering
Better Visualization of Trips through Agglomerative Clustering
 
Groovy
GroovyGroovy
Groovy
 
Jan 2012 HUG: RHadoop
Jan 2012 HUG: RHadoopJan 2012 HUG: RHadoop
Jan 2012 HUG: RHadoop
 
Geo search introduction
Geo search introductionGeo search introduction
Geo search introduction
 
Geolocation
GeolocationGeolocation
Geolocation
 
Code
CodeCode
Code
 
Spark - Citi Bike NYC
Spark - Citi Bike NYCSpark - Citi Bike NYC
Spark - Citi Bike NYC
 
10. R getting spatial
10.  R getting spatial10.  R getting spatial
10. R getting spatial
 
Intro To PostGIS
Intro To PostGISIntro To PostGIS
Intro To PostGIS
 
#rtgeo (Where 2.0 2011)
#rtgeo (Where 2.0 2011)#rtgeo (Where 2.0 2011)
#rtgeo (Where 2.0 2011)
 
Perlで任意精度計算
Perlで任意精度計算Perlで任意精度計算
Perlで任意精度計算
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
 
10. Getting Spatial
10. Getting Spatial10. Getting Spatial
10. Getting Spatial
 
R getting spatial
R getting spatialR getting spatial
R getting spatial
 

More from Marcus Deglos

Drupal feature proposal: two new stream-wrappers
Drupal feature proposal: two new stream-wrappersDrupal feature proposal: two new stream-wrappers
Drupal feature proposal: two new stream-wrappersMarcus Deglos
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh thingsMarcus Deglos
 
Vagrant crash course
Vagrant crash courseVagrant crash course
Vagrant crash courseMarcus Deglos
 
Drupal haters gonna hate
Drupal haters gonna hateDrupal haters gonna hate
Drupal haters gonna hateMarcus Deglos
 
Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2Marcus Deglos
 
Speeding Up The Snail
Speeding Up The SnailSpeeding Up The Snail
Speeding Up The SnailMarcus Deglos
 

More from Marcus Deglos (10)

Drupal feature proposal: two new stream-wrappers
Drupal feature proposal: two new stream-wrappersDrupal feature proposal: two new stream-wrappers
Drupal feature proposal: two new stream-wrappers
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh things
 
Vagrant crash course
Vagrant crash courseVagrant crash course
Vagrant crash course
 
Drupal haters gonna hate
Drupal haters gonna hateDrupal haters gonna hate
Drupal haters gonna hate
 
Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2
 
With one click
With one clickWith one click
With one click
 
Panels rocks!
Panels rocks!Panels rocks!
Panels rocks!
 
Varnish bof
Varnish bofVarnish bof
Varnish bof
 
SSO To go
SSO To goSSO To go
SSO To go
 
Speeding Up The Snail
Speeding Up The SnailSpeeding Up The Snail
Speeding Up The Snail
 

Recently uploaded

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 

Recently uploaded (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 

Where in the world

Editor's Notes

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