![]() TopologyException: Input geom 1 is invalid: Ring Self-intersection at or near point…īasically, the solution is to make the geometry valid, with a handy function calledĭepending on which sf object is causing the error, either introduce this function above Now and then one might get an error at this point in the workflow, something like Mutate_at(vars(LEVE元:LEVEL1), as.factor) %>% So the first necessary step is to convert to a common CRS, then perform the intersection: sa_epa % The EPA ecoregion data uses the Albers 1967 projection, which is wholly incompatible with the longitude/latitude systems our other objects are in. Note the curved lines of the Albers projection. ![]() with 3,536 more rows, and 2 more variables: Shape_Area , # AREA PERIMETER SA_ECO_ALB SA_ECO_A_1 LEVE元 LEVEL2 LEVEL1 Shape_Leng # projected CRS: International_1967_Albers In sf this action is called an intersection, and we use the st_intersection function.īut to get spatial data objects to work together, they must be in the same projection: EPA_SCA # Simple feature collection with 3546 features and 9 fields It is straightforward to remove extraneous features from one spatial data object, essentially by cropping its outermost boundary to that of another spatial data object’s boundary. One might notice a difference between the ecological data and the political maps: the former includes Central America while the other does not. Sf might return a warning about correct results for long/lat data, but you can ignore it. One can use filter to zoom in on one country, but it must be done to each call to geom_sf when different data objects are involved: ggplot() + Geom_sf(data=sa_countries, color="darkgrey", fill=NA) + We can easily add it to the map geom_sf will automatically take care of the geometries: ggplot() + zip file locally, and unzip it into a folder to which we can direct \(\). Typically we simply follow the URL in a browser, save the. zip file, which is typical for ESRI shapefiles. Countryįinally, use dplyr verbs to focus on one country in a tidy way: sa_countries %įirst, we need to fetch the data, which are stored on the course GitHub page as a. Lo siento para Las Malvinas.") Human population density by country in South America. Pander::pander("Human population density by country in South America. One can still treat them as a tibble for any sort of summary or analysis: sa_countries %>% km)")Ī perk of sf objects is that they aren’t exclusively spatial data. Scale_fill_viridis_c("Human population\ndensity (sq. Here we use the same st_area function as above to calculate human population density for each South American country: sa_countries % Likewise, one can use basic tidyverse data wrangling functions to create new columns based on information available in the dataset. Geom_sf(data=sa_countries, color="darkgrey", fill=NA) The order of the layers determines which features are covered up or sit on top. ![]() Note that each needs to have its own data argument. Multiple layers can be added to the same map with repeated calls to geom_sf. Here is a quick tidy trick to perform a dissolve that uses the st_area function: sa_cont % One could go and find an layer of the continental outline and hope it all lines up.īetter yet, one can just remove the lower-level boundaries in the current data.ĭissolving is the term given to removing feature boundaries to create an ‘empty’ outline. Note how the map above plots country boundaries, but perhaps one wants just the outline of the continent. … then map in ggplot using geom_sf(): ggplot() +ĭata often come with several levels of information that aren’t always necessary to include every time one makes a map. Developing region MULTIPOLYGON (((-59.75828 8. Developed region: nonG7 MULTIPOLYGON (((-61.2 -51.8. Developing region MULTIPOLYGON (((-80.30256. Developing region MULTIPOLYGON (((-75.37322. Emerging region: BRIC MULTIPOLYGON (((-57.62513. Select(name, economy) # Simple feature collection with 13 features and 2 fields Load Natural Earth data for South America as sf object: sa_countries % Packages and data pacman::p_load(lwgeom) # dependency
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |