首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R rMaps geoJson函数不作图

R rMaps geoJson函数不作图
EN

Stack Overflow用户
提问于 2015-02-12 19:06:24
回答 1查看 214关注 0票数 1

我有一个来自ESRI服务的JSON路由。我试图使用geoJson使用rMaps绘制路由图。我得到的唯一输出是地图,而不是多边形的绘图。

这是代码:

代码语言:javascript
复制
require(rMaps)
json = "{\"messages\":[],\"routes\":{\"fieldAliases\":{\"ObjectID\":\"ObjectID\",\"Name\":\"Name\",\"FirstStopID\":\"FirstStopID\",\"LastStopID\":\"LastStopID\",\"StopCount\":\"StopCount\",\"Total_TravelTime\":\"Total_TravelTime\",\"Total_Kilometers\":\"Total_Kilometers\",\"Total_Miles\":\"Total_Miles\",\"Shape_Length\":\"Shape_Length\"},\"geometryType\":\"esriGeometryPolyline\",\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326},\"features\":[{\"attributes\":{\"ObjectID\":1,\"Name\":\"Location 1 - Location 2\",\"FirstStopID\":1,\"LastStopID\":2,\"StopCount\":2,\"Total_TravelTime\":2.8403004080455228,\"Total_Kilometers\":0.79761507718052971,\"Total_Miles\":0.49561503145413888,\"Shape_Length\":0.0082585488982182334},\"geometry\":{\"paths\":[[[-122.40774845199996,37.783745569000075],[-122.40745999999996,37.783510000000035],[-122.40722999999997,37.783340000000067],[-122.40718999999996,37.783310000000029],[-122.40648999999996,37.782740000000047],[-122.40591999999998,37.782300000000077],[-122.40520999999995,37.782870000000059],[-122.40442999999999,37.78350000000006],[-122.40432999999996,37.783580000000029],[-122.40372999999994,37.784070000000042],[-122.40329999999994,37.78374000000008],[-122.40269999999998,37.783270000000073],[-122.40411865599998,37.782150343000069]]]}}]},\"directions\":[{\"routeId\":1,\"routeName\":\"Location 1 - Location 2\",\"summary\":{\"totalLength\":0.49561503145413888,\"totalTime\":2.8403004049323499,\"totalDriveTime\":2.8403004080455228,\"envelope\":{\"xmin\":-122.40789999999998,\"ymin\":37.782000000000039,\"xmax\":-122.40269999999998,\"ymax\":37.784070000000042,\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}},\"features\":[{\"attributes\":{\"length\":0,\"time\":0,\"text\":\"Start at Location 1\",\"ETA\":-2209161600000,\"maneuverType\":\"esriDMTDepart\"},\"compressedGeometry\":\"+1m91-6fki2+202vh+0+0\"},{\"attributes\":{\"length\":0.13919863031093585,\"time\":0.8808930174425843,\"text\":\"Go southeast on 5th St toward Stevenson St\",\"ETA\":-2209161600000,\"maneuverType\":\"esriDMTStraight\"},\"compressedGeometry\":\"+1m91-6fki2+202vh+36-2g\"},{\"attributes\":{\"length\":0.16963433548079213,\"time\":0.96497624999999998,\"text\":\"Turn left on Minna St\",\"ETA\":-2209161600000,\"maneuverType\":\"esriDMTTurnLeft\"},\"compressedGeometry\":\"+1m91-6fkes+202t1+3q+33\"},{\"attributes\":{\"length\":0.07799196861297697,\"time\":0.51913014739269459,\"text\":\"Turn right on 4th St\",\"ETA\":-2209161600000,\"maneuverType\":\"esriDMTTurnRight\"},\"compressedGeometry\":\"+1m91-6fkb2+20304+1p-1d\"},{\"attributes\":{\"length\":0.10879009704943393,\"time\":0.47530099321024388,\"text\":\"Turn right on Howard St\",\"ETA\":-2209161600000,\"maneuverType\":\"esriDMTTurnRight\"},\"compressedGeometry\":\"+1m91-6fk99+202un-2f-1u\"},{\"attributes\":{\"length\":0,\"time\":0,\"text\":\"Finish at Location 2, on the left\",\"ETA\":-2209161600000,\"maneuverType\":\"esriDMTStop\"},\"compressedGeometry\":\"+1m91-6fkbo+202sp+0+0\"}]}]}"
regions=RJSONIO::fromJSON(json)
lmap <- Leaflet$new()
lmap$tileLayer(provide='Stamen.TonerLite')
lmap$setView(c(37.78356, -122.4079), 13)
lmap$geoJson(
  regions)
legend_vec = c('red'='high', 'blue'='medium', 'green'='low')
lmap$legend(position = 'bottomright', 
            colors   =  names(legend_vec), 
            labels   =  as.vector(legend_vec))
lmap

有人知道为什么这个JSON没有显示在地图上吗?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-12 19:27:59

这不是一个有效的GeoJSON对象。L.GeoJSON (传单的GeoJSON层)只接受一个有效的GeoJSON特征回忆对象,或者一个带有有效的GeoJSON特征对象的数组。这是一个有效的GeoJSON特性回忆对象:

代码语言:javascript
复制
{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "properties": {
            "myProperty": "myValue"
        },
        "geometry": {
            "type": "Point",
            "coordinates": [0,0]
        }
    },{
        "type": "Feature",
        "properties": {
            "myProperty": "myValue"
        },
        "geometry": {
            "type": "LineString",
            "coordinates": [
                [-45, -45],
                [45, 45]
            ]
        }
    }]
}

您可以在这里了解更多关于GeoJSON的信息:http://geojson.org/和您可以在这里验证GeoJSON对象:为了更好的度量,这里也是对传单的L.GeoJSON层:http://leafletjs.com/reference.html#geojson的参考,以及关于如何使用L.GeoJSON层:http://leafletjs.com/examples/geojson.html的传单教程

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28485733

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档