简体   繁体   English

使用 tmap 绘制空间点数据的问题

[英]Issues plotting spatial point data using tmap

I have created a class Large SpatialPointDataFrame from a csv file, and I am trying to plot the data points using tmap.我已经从 csv 文件创建了 class 大型 SpatialPointDataFrame,并且我正在尝试使用 tmap 对数据点进行 plot。 When I plotted the SpatialPointDataFrame using plot(), everything looked fine.当我使用 plot() 绘制 SpatialPointDataFrame 时,一切看起来都很好。 However, when I tried to plot it using tmap, it only shows one single point plus it is not where it should be, btw, the point that got shown is the last item in the data frame.但是,当我尝试使用 tmap 对其进行 plot 时,它只显示一个点,而且它不在应有的位置,顺便说一句,显示的点是数据框中的最后一项。 I'm thinking there might be something wrong with my projecton?我在想我的投影仪可能有问题? CRS(Using SVY21 or EPSG:3414) properties of the SpatialPointDataFrame: SpatialPointDataFrame 的 CRS(使用 SVY21 或 EPSG:3414)属性:

crs: +init=epsg:3414 +proj=tmerc +lat_0=1.366666666666667 +lon_0=103.8333333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +ellps=WGS84 +units=m +no_defs

This is how I converted the dataframe to a spatialpointdataframe, where listing is the original dataframe read from a csv file.这就是我将 dataframe 转换为空间点数据帧的方式,其中列表是从 csv 文件中读取的原始 dataframe。

coords <- listing[ , c("latitude", "longitude")]
crs <- CRS("+init=epsg:3414")
listing_sp <- SpatialPointsDataFrame(coords = coords, listing, proj4string = crs)

Any suggestions on how I should debug?关于我应该如何调试的任何建议?

In your code, where you have crs <- CRS("+init=epsg:3414") , you are assigning a projection but your source data has not yet been transformed to that projection.在您的代码中,您有crs <- CRS("+init=epsg:3414") ,您正在分配一个投影,但您的源数据尚未转换为该投影。 If your source data is in lat/lon it's meant to be used with the WGS84 projection ( epsg code 4326 ).如果您的源数据采用纬度/经度,则应与 WGS84 投影( epsg 代码 4326 )一起使用。

Once you create your spatialPointDataFrame using the projection matching your coordinates, you simply have to reproject using spTransform .使用与坐标匹配的投影创建 spatialPointDataFrame 后,您只需使用spTransform重新投影。 To reproject to SVY21, you still need to transform.要重新投影到 SVY21,您仍然需要进行转换。 Can't test without some reproducible data but it should look like this.没有一些可重复的数据就无法测试,但它应该看起来像这样。

coords <- listing[ , c("latitude", "longitude")]
crs <- CRS("+init=epsg:4326")
listing_sp <- SpatialPointsDataFrame(coords = coords, listing, proj4string = crs)
listing_sp_svy21 <- spTransform(listing_sp, CRS("+init=epsg:3414"))

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

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