简体   繁体   English

使用R在Google地图中定位位置点的问题

[英]Problem in positioning the location points in google map using R

I am facing problem in creating map. 我在创建地图时遇到问题。 I have downloaded a shape file from- 我从以下位置下载了形状文件:

location link: " https://data.humdata.org/dataset/80920682-bbb5-421e-b7ac-f89b7b640a5c/resource/c545d196-bc2c-44ed-9028-316ab080a41c " 位置链接:“ https://data.humdata.org/dataset/80920682-bbb5-421e-b7ac-f89b7b640a5c/resource/c545d196-bc2c-44ed-9028-316ab080a41c

zip file link: https://data.humdata.org/dataset/80920682-bbb5-421e-b7ac-f89b7b640a5c/resource/c545d196-bc2c-44ed-9028-316ab080a41c/download/bgd_poi_healthfacilities_lged.zip zip文件链接: https : //data.humdata.org/dataset/80920682-bbb5-421e-b7ac-f89b7b640a5c/resource/c545d196-bc2c-44ed-9028-316ab080a41c/download/bgd_poi_healthfacilities_lged.zip

After extracting the data I have found a shape file. 提取数据后,我找到了一个形状文件。 I am trying to plot this shape file in google map using R code. 我正在尝试使用R代码在Google地图中绘制此形状文件。 But It is not showing anything? 但是它什么也没显示?

library(maptools)
library(ggmap)

counties.mpl <- readShapePoints("bgd_poi_healthfacilities_lged")

#Coordinates looks like:

counties.mpl@coords

       coords.x1 coords.x2
    0  531533.8   2524464
    1  531004.7   2531410
    2  533228.5   2525061
    3  531723.1   2488972
    4  532347.8   2492098
    5  518104.8   2520361

#map code:
mymap <- get_map(location="Bangladesh", zoom=6)
ggmap(mymap)+
  geom_point(data=counties.mpl@coords, 
             aes(x=counties.mpl@coords[,1], y=counties.mpl@coords[,2]))

Could anybody please help me to solve this? 有人可以帮我解决这个问题吗? Thanks in advance. 提前致谢。

As the others have noted, your shapefile uses a different coordinate system, & you'll need to transform it to lat / lon before the geom_point() layer can sit nicely over mymap . 正如其他人所指出的那样,您的shapefile使用了不同的坐标系,并且您需要将其转换为lat / lon,然后geom_point()层才能很好地位于mymap之上。

Your shapefile's .prj file begins with: shapefile的.prj文件开头为:

PROJCS["BangladeshTM WGS1984",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984", ...

The link here explains what each part means, but for our purpose, you just need to know that the shapefile's projected coordinate system is "BangladeshTM WGS1984", ie Bangladesh Transverse Mercator, coded as EPSG:3106 . 此处的链接说明了每个零件的含义,但是出于我们的目的,您只需要知道shapefile的投影坐标系是“孟加拉国WGS1984”,即孟加拉国横麦卡托,编码为EPSG:3106

The typical lat / lon coordinate system that ggmap() expects is WGS 84, coded as EPSG:4326 . ggmap()期望的典型纬度/经度坐标系是WGS 84,编码为EPSG:4326

TLDR: Convert your data's projection from EPSG:3106 to EPSG:4326, and plot accordingly. TLDR:将数据的投影从EPSG:3106转换为EPSG:4326,并进行相应绘制。

counties.mpl <- readShapePoints("bgd_poi_healthfacilities_lged")

# define current projection
proj4string(counties.mpl) <- CRS("+init=epsg:3106") # Bangladesh Transverse Mercator system

# remap to lat / long projection
counties.mpl.remapped <- spTransform(counties.mpl, CRS("+init=epsg:4326"))

# extract the coordinates as a data frame.
df <- as.data.frame(counties.mpl.remapped@coords)
colnames(df) <- c("lon", "lat")

# plot results
mymap <- get_map(location="Bangladesh", zoom=6)

ggmap(mymap) +
  geom_point(data = df)

情节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM