简体   繁体   中英

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 "

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

After extracting the data I have found a shape file. I am trying to plot this shape file in google map using R code. 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 .

Your shapefile's .prj file begins with:

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 .

The typical lat / lon coordinate system that ggmap() expects is WGS 84, coded as EPSG:4326 .

TLDR: Convert your data's projection from EPSG:3106 to EPSG:4326, and plot accordingly.

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)

情节

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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