0

Cropping geodata world map across Greenwich (not exactly though) or close to the poles gives a "Topology Exception" error on RStudio (Posit) cloud, although not on RStudio desktop. Also, the extent of the original geodata map does not reach the north pole on either system, which may be a related issue.

The script is below with details in comments, what could be the issue?

# Load required libraries
library(terra)
library(geodata)

# Decide on the map extent
# (the problem will start later, depending on which extent here is chosen)
cropping_extent <- ext(x = c(-180, 180, -90, 90)) # This is the main problem
cropping_extent <- ext(x = c(-180, 0, -80, 80)) # This is a problem too
cropping_extent <- ext(x = c(0, 180, -80, 80)) # This is a problem too
cropping_extent <- ext(x = c(20, 180, -70, 70)) # This works
cropping_extent <- ext(x = c(-180, 5, -70, 70)) # This works

# Download base map outlines with geodata's world function
dir.create(path = "data") # make a folder to download it
world_map <- world(resolution = 3, path = "data/") # download the map
ext(world_map) # check the extent

# This is (maybe) where the problem is. The extent check above shows this:
# > SpatExtent : -180, 180, -90, 83.65625 (xmin, xmax, ymin, ymax)
# But, that 83.65625 does not seem to be the only limitation, 
# based on the above attempts to crop.

# Crop the map to the area of interest
crop_map  <- crop(x = world_map, y = cropping_extent)

# This cropping command does indeed work on 
# RStudio 2023.09.1 Build 494 under Win 10, 
# but on RStudio (Posit) cloud it gives the following error:
# > Error: TopologyException: Input geom 0 is invalid: 
# Ring Self-intersection at or near point 10.454459190368652 
# 47.555736541748047 at 10.454459190368652 47.555736541748047

# Plot the map
plot(crop_map)

# The End
1
  • 1
    You seem to have generated two logins. This will prevent you from editing your own post or voting on any a answer. Please use this Meta SE post to reconcile your accounts.
    – Vince
    Dec 3, 2023 at 17:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.