【问题标题】:How to successfully fit a map into a longitude/latitude bounding box with the correct geographical scale and plot GPS points如何成功地将地图放入具有正确地理比例的经度/纬度边界框并绘制 GPS 点
【发布时间】:2020-05-08 09:42:59
【问题描述】:

问题概述

很抱歉问了一个简单的问题,但我是 R 新手,在使用地图执行任务时遇到了困难。

我有一组十进制形式的经度和纬度 GPS 点,这些点是在现场收集的。我的目标是将这些 GPS 点绘制到我从 GADM 资源中提取的斯里兰卡地图上。

运行代码后,斯里兰卡的南端从经度/纬度网格框的顶部中间突出,而不是斯里兰卡的整个图像在经度/纬度网格框内可见(见图 2)。

问题:

我可以独立制作斯里兰卡的地图(见图 2),以及单独的经度/纬度网格框(见图 1)。但是,我无法在纬度/经度网格框内绘制斯里兰卡地图,同时将网格框中的 GPS 点绘制在现场收集数据的正确位置。

所需的输出如图 3 所示(见下文)。我正在尝试将图像 1 放置在网格框内,并在网格框的边缘使用斯里兰卡的正确经度/纬度比例尺。最后,我想在地图上绘制 GPS 点,就像图 3 中提供的示例一样。

如果有人能帮助我,我将非常感激!

由于我缺乏知识,我真的无法弄清楚这里出了什么问题,并且经过数小时尝试不同的 R 代码组合以通过尝试重现此stack overflow question 并遵循此exercise on species distribution modeling 来解决问题.

非常亲切的问候。

R 代码

##Libraries that are going to be used:

   library("sp")
   library("raster")
   library("maptools")
   library("rgdal")
   library("dismo")
   library("spatialEco")
   library("ggplot2")
   library("dplyr")

###Open the directory pathway

 Blue.whale<-readr::read_csv("Blue_Whale_GPS_Best.csv")
 summary(Blue.whale)

##Plotting the map of Sri Lanka
   bioclim1.data <- getData('GADM', country='LKA', level=1)
   Sri_Lanka<-plot(bioclim1.data, main="Adm. Boundaries Sri Lanka Level 0")


 ###My attempt at creating a longitude/latitude grid box

    Sri.Lanka.bbox<-bbox(Blue.whale)
    xlim <- c(min(Sri.Lanka.bbox[1,1]), max(Sri.Lanka.bbox[1,2]))
    ylim <- c(min(Sri.Lanka.bbox[2,1]), max(Sri.Lanka.bbox[2,2]))

  ###Plot the longitude/latitude grid box
     dev.new()
     plot(Sri_Lanka, xlim=xlim, ylim=ylim, add=T)


 ##Plot map
   par(mfrow=c(1,1))
   dev.new()

####Convert the format of the data from factors to numeric

    Latitude<-as.numeric(Blue.whale$Latitude)
    Longitude<-as.numeric(Blue.whale$Longitude)

##To make species distribution modeling more streamlined, it is useful to have an 
##idea of how widely our species is geographically distributed. We are going to find 
 ##general latitudinal and longitudinal boundaries and store this information:

  # Determine geographic extent of our data
    max.lat <- ceiling(max(Blue.whale$Latitude))
    min.lat <- floor(min(Blue.whale$Latitude))
    max.lon <- ceiling(max(Blue.whale$Longitude))
    min.lon <- floor(min(Blue.whale$Longitude))
    geographic.extent <- extent(x = c(min.lon, max.lon, min.lat, max.lat))

     # Plot the base map

       dev.new()

       plot(bioclim1.data, 
            xlim = c(min.lon, max.lon),
            ylim = c(min.lat, max.lat),
            axes = TRUE, 
            col = "grey95")

       # Add the points for individual observation
         points(x = Blue.whale$Longitude, 
                y = Blue.whale$Latitude, 
                col = "olivedrab", 
                pch = 15, 
                cex = 0.50)

图片 1:

图 2:

图 3:

【问题讨论】:

    标签: r github gis latitude-longitude raster


    【解决方案1】:

    对于示例 3,他们裁剪了美国的地图以关注该物种发生的地点,而您想要显示与整个斯里兰卡国家相关的鲸鱼目击发生地点。要显示整个国家和所有目击事件,您需要更改绘图限制以匹配两个数据源的末端。此代码应该会产生您想要的情节,如果需要,您可以添加 ceiling / floor 参数以改善美学:

    ##get bounding box of Sri Lanka shapefile
    bb=bioclim1.data@bbox
    
    plot(bioclim1.data, 
         xlim = c(min(c(min.lon,bb[1,1])), max(c(max.lon,bb[1,2]))),
         ylim = c(min(c(min.lat,bb[2,1])), max(c(max.lat,bb[2,2]))),
         axes = TRUE, 
         col = "grey95")
    
    # Add the points for individual observation
    points(x = Blue.whale$Longitude, 
           y = Blue.whale$Latitude, 
           col = "olivedrab", 
           pch = 15, 
           cex = 0.50)
    

    【讨论】:

    • 非常感谢琼斯博士。我真的很感谢你的帮助。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-19
    • 1970-01-01
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    相关资源
    最近更新 更多