未在 shapefile 上绘制点

发布于 2025-01-13 11:06:09 字数 1061 浏览 3 评论 0原文

我正在尝试用波兰的 Powiaty(县)和克拉科夫所在的点绘制一个形状文件。这是我正在使用的代码。由于某种原因,该点没有出现在图中。

这是我获得波兰 Powiaty 的 shapefile 的地方: https://www.gis-support.pl/downloads/Powiaty.zip?_ga=2.76556755.796824239.1647028537-1312541903.1646793893

library(sf)

# Load shapefile
poland_Powiaty <- st_read("~/Powiaty.shp")

### Krakow's coordinates
krakow <- data.frame(x=19.940000819941382, 
                     y=50.06197893970872)

point <- st_as_sf(krakow, coords = c("x", "y"))
# Set the CRS of shapefile
st_crs(point) <- "+proj=tmerc +lat_0=0 +lon_0=19 +k=0.9993 +x_0=500000 +y_0=-5300000 +ellps=GRS80
+towgs84=0,0,0,0,0,0,0 +units=m +no_defs " # assign CRS to point

plot(poland_Powiaty[2])
plot(point,col="black",pch=19, cex=3,add=T)

Output

有谁知道如何将克拉科夫添加到地图中?

I am trying to plot a shapefile with Poland's Powiaty (counties) and a dot where Krakow is. This is the code that I'm using. For some reason, that dot is not appearing in the plot.

This is where I got the shapefile of Poland's Powiaty: https://www.gis-support.pl/downloads/Powiaty.zip?_ga=2.76556755.796824239.1647028537-1312541903.1646793893

library(sf)

# Load shapefile
poland_Powiaty <- st_read("~/Powiaty.shp")

### Krakow's coordinates
krakow <- data.frame(x=19.940000819941382, 
                     y=50.06197893970872)

point <- st_as_sf(krakow, coords = c("x", "y"))
# Set the CRS of shapefile
st_crs(point) <- "+proj=tmerc +lat_0=0 +lon_0=19 +k=0.9993 +x_0=500000 +y_0=-5300000 +ellps=GRS80
+towgs84=0,0,0,0,0,0,0 +units=m +no_defs " # assign CRS to point

plot(poland_Powiaty[2])
plot(point,col="black",pch=19, cex=3,add=T)

Output

Does anyone know how I can be able to add Krakow to the map?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

源来凯始玺欢你 2025-01-20 11:06:09

你已经很接近了,但 crs 似乎是问题所在。

*编辑完整代表:

library(sf)
library(dplyr) #for the pipe %>%
library(ggplot2)

# data from:  https://gis-support.pl/baza-wiedzy-2/dane-do-pobrania/granice-administracyjne/
# file downloaded:  https://www.gis-support.pl/downloads/Powiaty.zip

# read shapefile, retain only geometry column
poland_Powiaty <- read_sf('Powiaty.shp') %>%  #change filename as needed
                    st_geometry()

# In latitude/longitude
krakow <- data.frame(x=19.940000819941382, 
                     y=50.06197893970872) %>%
  st_as_sf(coords = c('x', 'y'))

# set crs to 4326 for lat/lon
krakow <- st_set_crs(krakow, 4326)
# transform krakow to have same crs as poland_Powiaty
krakow <- st_transform(krakow, st_crs(poland_Powiaty))

# base plot
plot(poland_Powiaty)
plot(krakow, add = T, pch = 15, col = 'red')


##  ggplot2
ggplot() + 
  geom_sf(data = poland_Powiaty) +
  geom_sf(data = krakow, color = 'red', size = 3)

reprex 包于 2022 年 3 月 11 日创建 (v0.3.0)

You're close, but the crs seems to be the problem.

*edited for full reprex:

library(sf)
library(dplyr) #for the pipe %>%
library(ggplot2)

# data from:  https://gis-support.pl/baza-wiedzy-2/dane-do-pobrania/granice-administracyjne/
# file downloaded:  https://www.gis-support.pl/downloads/Powiaty.zip

# read shapefile, retain only geometry column
poland_Powiaty <- read_sf('Powiaty.shp') %>%  #change filename as needed
                    st_geometry()

# In latitude/longitude
krakow <- data.frame(x=19.940000819941382, 
                     y=50.06197893970872) %>%
  st_as_sf(coords = c('x', 'y'))

# set crs to 4326 for lat/lon
krakow <- st_set_crs(krakow, 4326)
# transform krakow to have same crs as poland_Powiaty
krakow <- st_transform(krakow, st_crs(poland_Powiaty))

# base plot
plot(poland_Powiaty)
plot(krakow, add = T, pch = 15, col = 'red')


##  ggplot2
ggplot() + 
  geom_sf(data = poland_Powiaty) +
  geom_sf(data = krakow, color = 'red', size = 3)

Created on 2022-03-11 by the reprex package (v0.3.0)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文