Spatial mongo for PHP and Zend
-
Upload
steven-citron-pousty -
Category
Technology
-
view
1.471 -
download
1
description
Transcript of Spatial mongo for PHP and Zend
![Page 1: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/1.jpg)
1
Build Your Own Foursquare! Develop GeoSpatial Apps with
Zend, MongoDB and OpenShift
Steven Citron-PoustyPaaS Dust Spreader, Red Hat@TheSteve0
![Page 2: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/2.jpg)
2
Agenda
• Learn a little spatial
• Load some spatial data into mongo
• Do a query or two
SIGN UP CODE: zendcon
![Page 3: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/3.jpg)
3
Git repo for the data and code
https://github.com/thesteve0/parks-php-zf2
Please remember the point here is not that this is great PHP or ZF2 code. This is mostly to show you how to do spatial queries in mongo through PHP. The main file with that code is:
https://github.com/thesteve0/parks-php-zf2/blob/master/module/Application/src/Application/Controller/IndexController.php
The data file is in the root dir and is called parks.json
![Page 4: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/4.jpg)
4
Assumptions
1) You can use the command line
2) You are comfortable with Mongo command line
3) Please ask questions – though since there are things I really want to cover, they may have to wait until the end or after the session
![Page 5: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/5.jpg)
5
What is OpenShift?
Red Hat’s free platform as a service for applications in the cloud.
![Page 6: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/6.jpg)
6 Dalbera on Flickr
![Page 7: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/7.jpg)
7
Kind of like Amazon, right? Nope.
![Page 8: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/8.jpg)
8Cook24v on Flickr
![Page 9: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/9.jpg)
9
![Page 10: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/10.jpg)
10
What’s supported?
![Page 11: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/11.jpg)
11
There’s more? What’s the catch?
• OpenShift is free-as-in-beer & free-as-in-freedom
• Three 512 MB RAM / 1 GB storage gears
• Need more resources, just ask!
• We are really in Developer Preview
![Page 12: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/12.jpg)
12
On to spatial!
![Page 13: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/13.jpg)
13
Spatial is fun
The only spatial functionality Mongo currently has is:
1) Near
2) Containment
All of it is laid out on one page:
http://www.mongodb.org/display/DOCS/Geospatial+Indexing
First link on a google search for “mongodb spatial indexing”
![Page 14: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/14.jpg)
14
Caveats
1. Assumes coords. are between -180 and 180
2. Can handle any 2D coordinates
3. Has methods to handle curvature of the earth (spherical)
![Page 15: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/15.jpg)
15
How to make it work
1) Put your coordinates into an arrary{ loc : [ 50 , 30 ] } //SUGGESTED OPTION
{ loc : { x : 50 , y : 30 } }
{ loc : { foo : 50 , y : 30 } }
{ loc : { lon : 40.739037, lat: 73.992964 } }
2) Make a 2d index
db.places.ensureIndex( { loc : "2d" } )
![Page 16: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/16.jpg)
16
Demo
1. I have an app and a mongo instance running
2. Load some spatial data in JSON format
3. Make the 2d index
4. Do some fun spatial and mongoDB work
5. Show some PHP code that takes advantage of it
![Page 17: Spatial mongo for PHP and Zend](https://reader033.fdocuments.us/reader033/viewer/2022052619/555146adb4c905bd1c8b5053/html5/thumbnails/17.jpg)
17
Conclusion
1. Spatial is easy and fun on Mongo with PHP
2. You can now build your own FourSquare or other checkin application.
3. You can also build your own field data entry system.
4. You can build and deploy your application quickly without having to think about infrastructure.
SIGN UP CODE: zendcon
http://openshift.redhat.com