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