'plotting two shape file with the same CRS
I have two shape files.
polygon: https://www.dropbox.com/scl/fo/79tv08fp55ebibt6asz9c/h?dl=0&rlkey=ku6dlhidxkhc2n4hhi20vpr41
points:https://www.dropbox.com/scl/fo/3ss0ca930jcg9jzbsmuej/h?dl=0&rlkey=vbp7kpnho7p3rdw79mtere8ry
When I read these files using sf package, they seem to have the same CRS.
polygon
Simple feature collection with 2587 features and 1 field
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 131.6679 ymin: 34.30244 xmax: 133.3907 ymax: 37.24427
Projected CRS: JGD2011 / UTM zone 53N
points
Simple feature collection with 573 features and 1 field
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 131.6875 ymin: 34.6641 xmax: 133.3849 ymax: 36.34877
Projected CRS: JGD2011 / UTM zone 53N
I tried to plot the two files, but it failed.
plot(polygon, col = "lightgrey", border = "grey")
plot(points, pch = "x", add = TRUE)
And, I tried to set the same CRS manually, but plotting still failed.
polygon_proj = st_transform(polygon, crs = st_crs("EPSG:6690"))
points_proj = st_transform(points, crs = st_crs("EPSG:6690"))
Any advices are welcome, thanks a lot in advance.
Solution 1:[1]
"plotting fails" probably means that points and polygon are offset horizontally when calling base plot on the objects. The features have different bounding boxes, and adding a feature to an existing plot apparently doesn't scale it to fit the existing plot's limits, hence the shift.
You can check that the features' geometries are actually OK by using another map function, e.g. geom_sf() of {ggplot2}:
library(ggplot2)
library(sf)
points <- read_sf("path_to_points_shape")
polygons <- read_sf("path_to_polygon_shape")
ggplot() +
geom_sf(data = points) +
geom_sf(data = polygons)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | I_O |
