kandi background
kandi background
Explore Kits
kandi background
Explore Kits
kandi background
Explore Kits
kandi background
Explore Kits
Explore all Meteor open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in Meteor

v6.18

4.0.1

v7.0.0

v2.0.1

3.4.0

wekan

v6.18

nosqlclient

4.0.1

meteor-autoform

v7.0.0

Meteor-Files

v2.0.1

meteor-collection2

3.4.0

Popular Libraries in Meteor

Trending New libraries in Meteor

Top Authors in Meteor

1

35 Libraries

47148

2

32 Libraries

432

3

25 Libraries

3640

4

25 Libraries

853

5

25 Libraries

1469

6

25 Libraries

1158

7

24 Libraries

5371

8

23 Libraries

1826

9

18 Libraries

219

10

18 Libraries

1299

1

35 Libraries

47148

2

32 Libraries

432

3

25 Libraries

3640

4

25 Libraries

853

5

25 Libraries

1469

6

25 Libraries

1158

7

24 Libraries

5371

8

23 Libraries

1826

9

18 Libraries

219

10

18 Libraries

1299

Trending Kits in Meteor

No Trending Kits are available at this moment for Meteor

Trending Discussions on Meteor

    R - Converting Coordinates to Countries? (Large quantity)
    Meteor build fails when run back to back
    What is the use for the special "public" folder in a Meteor app?
    Meteor + Semantic React
    How to await future in global main dart of flutter?
    Tone.PitchShift and Howler.js issues
    How to access attributes [e.g. time] of terra raster in R?
    Collection update Meteor failure from failed regex validation but no regex
    Meteor global version is different than project's
    Typescript - Extending existing module declarations

QUESTION

R - Converting Coordinates to Countries? (Large quantity)

Asked 2022-Apr-15 at 20:05

I have a data set that includes meteorite landings. It is really cool to see, but it only has coordinates for location data: latitude, longitude, and another variable that includes both of those in a coordinate format.

Is there a way I can convert these into a new variable for the country in which they are located? I have heard of geonames, but that only does one at a time, and I am looking at over 30,000 locations (haha). I could also potentially use a function to go through it, but I've heard it will run into errors with points in the ocean, which there are some here.

My goal here is to create a cartogram. If I can do that with the coordinates instead of making the country names for the entire world, please let me know.

Any help with this is appreciated.

The data set can be downloaded at https://www.kaggle.com/datasets/nasa/meteorite-landings, and the code can be filtered with this code:

1meteor.original <- read_csv("meteorite-landings.csv")
2meteor <- meteor.original %>%
3  filter(year >= 860 & year <= 2016) %>%
4  filter(reclong >= -180 & reclong <= 180 & (reclat != 0 | reclong != 0))
5head(meteor)
6

ANSWER

Answered 2022-Apr-15 at 20:05

Although it's possible to do this with several different online APIs, the free reverse geocoding APIs tend to handle only one point at a time, and a large data frame like yours could take hours to work through.

I would be tempted to use an R package with country info and map the points to countries using sf or sp.

The following function returns a vector of country names given a vector of latitudes and a vector of longitudes:

copy icondownload icon

1meteor.original <- read_csv("meteorite-landings.csv")
2meteor <- meteor.original %>%
3  filter(year >= 860 & year <= 2016) %>%
4  filter(reclong >= -180 & reclong <= 180 & (reclat != 0 | reclong != 0))
5head(meteor)
6get_countries <-  function(long, lat)
7{ 
8  points <- cbind(long, lat)
9  countriesSP <- rworldmap::getMap(resolution = 'low')
10  pointsSP = sp::SpatialPoints(points, sp::CRS(sp::proj4string(countriesSP)))  
11  sp::over(pointsSP, countriesSP)$ADMIN
12}
13

So your code could be something like:

copy icondownload icon

1meteor.original <- read_csv("meteorite-landings.csv")
2meteor <- meteor.original %>%
3  filter(year >= 860 & year <= 2016) %>%
4  filter(reclong >= -180 & reclong <= 180 & (reclat != 0 | reclong != 0))
5head(meteor)
6get_countries <-  function(long, lat)
7{ 
8  points <- cbind(long, lat)
9  countriesSP <- rworldmap::getMap(resolution = 'low')
10  pointsSP = sp::SpatialPoints(points, sp::CRS(sp::proj4string(countriesSP)))  
11  sp::over(pointsSP, countriesSP)$ADMIN
12}
13library(tidyverse)
14
15meteor.original <- read_csv("../meteorite-landings.csv")
16
17# Get meteor counts per country
18meteor <- meteor.original %>%
19  filter(year >= 860 & year <= 2016) %>%
20  filter(reclong >= -180 & reclong <= 180 & (reclat != 0 | reclong != 0)) %>%
21  mutate(latitude = as.numeric(gsub("^\\((.*), .*$", "\\1", GeoLocation)),
22         longitude = as.numeric(gsub("^.*, (.*)\\)$", "\\1", GeoLocation)),
23         country = get_countries(longitude, latitude)) %>%
24  group_by(country) %>%
25  count()
26
27# Get a world map, left join the meteor counts and plot
28sf::st_as_sf(rworldmap::getMap(res = "li")) %>%
29  rename(country = ADMIN.1) %>%
30  left_join(meteor, by = "country") %>%
31  ggplot() +
32  geom_sf(aes(fill = log(n)), colour = NA) +
33  scale_fill_viridis_c(na.value = "black", 
34                       breaks = log(c(1, 10, 100, 1000, 20000)),
35                       labels = exp,
36                       name = "Meteorite\nCount") +
37  theme_void()
38

enter image description here

Source https://stackoverflow.com/questions/71887566

Community Discussions contain sources that include Stack Exchange Network

    R - Converting Coordinates to Countries? (Large quantity)
    Meteor build fails when run back to back
    What is the use for the special "public" folder in a Meteor app?
    Meteor + Semantic React
    How to await future in global main dart of flutter?
    Tone.PitchShift and Howler.js issues
    How to access attributes [e.g. time] of terra raster in R?
    Collection update Meteor failure from failed regex validation but no regex
    Meteor global version is different than project's
    Typescript - Extending existing module declarations

QUESTION

R - Converting Coordinates to Countries? (Large quantity)

Asked 2022-Apr-15 at 20:05

I have a data set that includes meteorite landings. It is really cool to see, but it only has coordinates for location data: latitude, longitude, and another variable that includes both of those in a coordinate format.

Is there a way I can convert these into a new variable for the country in which they are located? I have heard of geonames, but that only does one at a time, and I am looking at over 30,000 locations (haha). I could also potentially use a function to go through it, but I've heard it will run into errors with points in the ocean, which there are some here.

My goal here is to create a cartogram. If I can do that with the coordinates instead of making the country names for the entire world, please let me know.

Any help with this is appreciated.

The data set can be downloaded at https://www.kaggle.com/datasets/nasa/meteorite-landings, and the code can be filtered with this code:

1meteor.original <- read_csv("meteorite-landings.csv")
2meteor <- meteor.original %>%
3  filter(year >= 860 & year <= 2016) %>%
4  filter(reclong >= -180 & reclong <= 180 & (reclat != 0 | reclong != 0))
5head(meteor)
6

ANSWER

Answered 2022-Apr-15 at 20:05

Although it's possible to do this with several different online APIs, the free reverse geocoding APIs tend to handle only one point at a time, and a large data frame like yours could take hours to work through.

I would be tempted to use an R package with country info and map the points to countries using sf or sp.

The following function returns a vector of country names given a vector of latitudes and a vector of longitudes:

copy icondownload icon

1meteor.original <- read_csv("meteorite-landings.csv")
2meteor <- meteor.original %>%
3  filter(year >= 860 & year <= 2016) %>%
4  filter(reclong >= -180 & reclong <= 180 & (reclat != 0 | reclong != 0))
5head(meteor)
6get_countries <-  function(long, lat)
7{ 
8  points <- cbind(long, lat)
9  countriesSP <- rworldmap::getMap(resolution = 'low')
10  pointsSP = sp::SpatialPoints(points, sp::CRS(sp::proj4string(countriesSP)))  
11  sp::over(pointsSP, countriesSP)$ADMIN
12}
13

So your code could be something like:

copy icondownload icon

1meteor.original <- read_csv("meteorite-landings.csv")
2meteor <- meteor.original %>%
3  filter(year >= 860 & year <= 2016) %>%
4  filter(reclong >= -180 & reclong <= 180 & (reclat != 0 | reclong != 0))
5head(meteor)
6get_countries <-  function(long, lat)
7{ 
8  points <- cbind(long, lat)
9  countriesSP <- rworldmap::getMap(resolution = 'low')
10  pointsSP = sp::SpatialPoints(points, sp::CRS(sp::proj4string(countriesSP)))  
11  sp::over(pointsSP, countriesSP)$ADMIN
12}
13library(tidyverse)
14
15meteor.original <- read_csv("../meteorite-landings.csv")
16
17# Get meteor counts per country
18meteor <- meteor.original %>%
19  filter(year >= 860 & year <= 2016) %>%
20  filter(reclong >= -180 & reclong <= 180 & (reclat != 0 | reclong != 0)) %>%
21  mutate(latitude = as.numeric(gsub("^\\((.*), .*$", "\\1", GeoLocation)),
22         longitude = as.numeric(gsub("^.*, (.*)\\)$", "\\1", GeoLocation)),
23         country = get_countries(longitude, latitude)) %>%
24  group_by(country) %>%
25  count()
26
27# Get a world map, left join the meteor counts and plot
28sf::st_as_sf(rworldmap::getMap(res = "li")) %>%
29  rename(country = ADMIN.1) %>%
30  left_join(meteor, by = "country") %>%
31  ggplot() +
32  geom_sf(aes(fill = log(n)), colour = NA) +
33  scale_fill_viridis_c(na.value = "black", 
34                       breaks = log(c(1, 10, 100, 1000, 20000)),
35                       labels = exp,
36                       name = "Meteorite\nCount") +
37  theme_void()
38

enter image description here

Source https://stackoverflow.com/questions/71887566