Skip to content

Commit

Permalink
changed defination difference in crs
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnumds committed Dec 13, 2024
1 parent 1eea0a2 commit aff1d30
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,19 @@ Adding country information to earthquake data involves performing a spatial join

```{r}
Sys.setenv(PROJ_LIB = "/opt/homebrew/Cellar/proj/9.5.1/share/proj")
# Load world country boundaries (spData package provides 'world' dataset)
# Load world country boundaries
data(world, package = "spData")
# Ensure 'world' has a CRS
if (is.na(st_crs(world))) {
st_crs(world) <- 4326 # Assign WGS84 CRS
}
# Standardize CRS for 'world' and 'quake_sf'
world <- st_transform(world, crs = 4326)
# Check and fix CRS and geometry issues in 'quake_sf'
if (is.na(st_crs(quake_sf))) {
st_crs(quake_sf) <- 4326 # Assign WGS84 CRS
st_crs(quake_sf) <- 4326 # Assign CRS if missing
}
quake_sf <- st_transform(quake_sf, crs = 4326) # Transform to match 'world'
# Validate and fix geometries if needed
if (!all(st_is_valid(quake_sf))) {
quake_sf <- st_make_valid(quake_sf)
Expand All @@ -264,7 +264,7 @@ if (!all(st_is_valid(quake_sf))) {
# Remove rows with empty geometries
quake_sf <- quake_sf[!st_is_empty(quake_sf), ]
# Perform spatial join between earthquake points and country polygons
# Perform spatial join
quake_with_countries <- st_join(quake_sf, world["name_long"])
# Summarize earthquake data by country
Expand Down

0 comments on commit aff1d30

Please sign in to comment.