R中的GeoJson数据

时间:2017-07-04 13:28:37

标签: r geojson

我想处理具有下述格式的GeoJson数据;

    { "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": ""
      }}}

问题是我想将“Where”子句用于“appuserid”并选择要处理的所选记录。我不知道怎么做?我已经在数据帧中保存了Mongodb中的数据 现在我正试着这样做;

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

但它给出了一个错误。

Error: Only lists of raw vectors are currently supported

代码在下面;

   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.

1 个答案:

答案 0 :(得分:0)

jqr是一个选项,是jq https://stedolan.github.io/jq/

的R客户端
    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")')

返回

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