2017-07-04 3 views
0

Ich möchte mit GeoJson Daten arbeiten, die das unten erwähnte Format haben;GeoJson Daten in R

{ "id": 1, 
     "geometry": 
    { "type": "Point", 
    "coordinates": [ 
     -3.706, 
     40.3], 
    "properties": {"appuserid": "5b46-7d3c-48a6-9c08-cc894", 
    "eventtype": "location", 
    "devicedate": "2016-06-08T07:25:21", 
    "date": "2016-06-08T07:25:06.507", 
    "location": { 
     "building": "2", 
     "floor": "0", 
     "elevation": "" 
     }}} 

Das Problem ist, ich eine „Where“ -Klausel „appuserid“ verwenden möchten, und die ausgewählten Datensätze zur Bearbeitung auswählen. Ich weiß nicht, wie es geht? Ich habe bereits Daten von einem Mongodb in einem Datenrahmen gespeichert.
Im Moment versuche ich es wie folgt zu tun;

library(sqldf) 
    sqldf("SELECT * FROM d WHERE d$properties$appuserid = '0000-0000-0000-0000'") 

Aber es gibt einen Fehler.

Error: Only lists of raw vectors are currently supported 

Code ist unten;

library(jsonlite); 
    con <- mongo(collection = "geodata", db = "MongoDb", url = "mongodb://192.168.26.18:27017", verbose = FALSE, options = ssl_options()); 
    d <- con$find(); 

    library(jqr) 
    jq(d, '.features[] | select(d$properties$appuserid == "5b46-7d3c-48a6-9c08-cc894")') 

    Error : Error in jq.default(d, ".features[] | select(d$properties$appuserid == \"5b46-7d3c-48a6-9c08-cc894\")") : 
    jq method not implemented for data.frame. 
+0

sqldf auf Datenrahmen funktioniert und erfordert, dass Sie eine gültige SQL-Zeichenfolge als erstes Argument liefern . Ist d ein Datenrahmen? $ ist kein SQL-Operator. Ich schlage vor, Sie überprüfen [fragen] und [MCVE]. –

Antwort

0

jqr ist eine Option, ein R-Client für jq https://stedolan.github.io/jq/

x <- '{ 
     "type": "FeatureCollection", 
     "features": [ 
      { 
       "type": "Feature", 
       "properties": { 
        "population": 200 
       }, 
       "geometry": { 
        "type": "Point", 
        "coordinates": [ 
         10.724029, 
         59.926807 
        ], 
        "properties": { 
         "appuserid": "5b46-7d3c-48a6-9c08-cc894" 
        } 
       } 
      }, 
      { 
       "type": "Feature", 
       "properties": { 
        "population": 600 
       }, 
       "geometry": { 
        "type": "Point", 
        "coordinates": [ 
         10.715789, 
         59.904778 
        ], 
        "properties": { 
         "appuserid": "c7e866a7-e32d-4dc2-adfd-c2ca065b25ce" 
        } 
       } 
      } 
     ] 
    }' 

    library(jqr) 
    jq(x, '.features[] | select(.geometry.properties.appuserid == "5b46-7d3c-48a6-9c08-cc894")') 

kehrt

{ 
     "type": "Feature", 
     "properties": { 
      "population": 200 
     }, 
     "geometry": { 
      "type": "Point", 
      "coordinates": [ 
       10.724029, 
       59.926807 
      ], 
      "properties": { 
       "appuserid": "5b46-7d3c-48a6-9c08-cc894" 
      } 
     } 
    } 
+0

Vielen Dank für Ihre Antwort. Aber es funktioniert nicht für einen Datenrahmen. – sara

+0

Ich schlage vor, Sie versuchen 'dplyr' zum Parsen von data.frames – sckott