1

Click here to load reader

Spatial script for CIMA

Embed Size (px)

Citation preview

Page 1: Spatial script for CIMA

#commands for adding spatial data!1!2#Take a look at the file first!3#less parkcoord.json!4!5#get the file on the server!6scp parkcoord.json [email protected]:app-root/data!7!8#ssh into the machine!9ssh [email protected]!10!11!12#import into mongo!13mongoimport -d parks -c parkpoints --type json --file app-root/data/parkcoord.json -h 14$OPENSHIFT_NOSQL_DB_HOST -u admin -p $OPENSHIFT_NOSQL_DB_PASSWORD!…!15#open the mongo shell!16mongo !17!18#build the index!19db.parkpoints.ensureIndex({"pos":"2d"});!20!21#Now some queries!22#simple spatial!23db.parkpoints.find({"pos" : { "$near" : [-37, 41]}});!24!25#spatial and text query using regex!26db.parkpoints.find( { Name : /lincoln/i, pos : { $near : [-37,41] }} );!27!28#geonear TODO!29db.runCommand({ geoNear : "parkpoints", near : [-37,41], num : 10 });!30!31!32https://github.com/openshift/openshift-mongo-node-express-example!33!34http://nodewsos-spdemo.rhcloud.com/ws/parks!35!36!37!38!39!40!41#create a new collection from scratch!42db.createCollection("checkin");!43db.checkin.ensureIndex( { "pos" : "2d" } );!44!45#insert a new record!46db.checkin.insert({ "created" : new Date(), "Notes" : 'just landed', "pos" : [-76.7302 , 25.5332 ] })!47! !48#quick query to make sure it worked!49db.checkin.find( { pos : { $near : [-37,41] } } )!50!51#add a second document closer to query point!52#this is an upsert - since we don't pass in the _id it creates a new record!53db.checkin.save({ created : new Date(), Notes: 'that was a big step', pos : [-37.7302 , 40.5332 ]});!54!55#one way to update original document!56myDoc = db.checkin.findOne({_id : ObjectId("50130d8ea8f6532e83026bc1")});!57myDoc.Notes = "really the landing";!58db.checkin.save(myDoc);!59!60!61!62!63

64