Make kml with excel file. Specify the location.

Hi Community,

Im want make a KML file with one excel data. I have problem in the final step when I try to save the KML file. The points was show wrong. Some rows are NA in the data.

This points are of South America, Colombia.

library(ggmap)
library(maptools)
library(rgdal)
library(readxl)
library(sp)
library(sf)


coordinates(data4)<-c("LATITUD","LONGITUD")

proj4string(data4)<-CRS("+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6378140 +b=6356750 +units=m +no_defs")

writeOGR(data4, dsn="Productores.kml", layer= "data4", driver="KML") 

Im run the final KML but the result is wrong.

data4<- structure(list(LATITUD = c("2.90198", "3.02982", "2.89649", "2.868617", 
"2.58123", "3.03587", "2.94555", "2.94555", "2.85666", "2.94333", 
"2.89674", "2.98455", "2.93722", "2.96538", "2.94527"), LONGITUD = c("-76.32921", 
"-76.76027", "-76.73383", "-76.333191", "-76.4551", "-76.77712", 
"-76.34722", "-76.34777", "-76.78888", "-76.34416", "-76.35512", 
"-76.79841", "-76.31972", "-76.33370", "-76.33777")), row.names = c(NA, 
-15L), class = c("tbl_df", "tbl", "data.frame"))

Maybe the location step is incorrect

Thanks

LIke this with your data:

library(tidyverse)
library(sf)

points <- data4 %>% 
  mutate_if(is.character, as.numeric) %>% 
  st_as_sf(coords = c("LONGITUD", "LATITUD"))


st_write(points, "points.kml")

image

# viewing
library(tmap)
tmap_mode("view")

tm_shape(points) +
  tm_dots()
1 Like

Hi @williaml , I have an extra problem,

Im make correction with NA values, but don run with the full data.
image

Im put the data for better help me.

Thanks you.

Can you just filter out the missing values?

points <- data4 %>% 
  mutate_if(is.character, as.numeric) %>% 
  filter(!is.na(LONGITUD)) %>% 
  st_as_sf(coords = c("LONGITUD", "LATITUD")) 

1 Like

Appear the same problem when im run all the data.

image

dat5 is all the data share in the before link. Im little confused, because I use na.omit() and drop_na() and na.exclude() but dont run.

Tnks!

You have some weird numbers in that file:

    LATITUD            LONGITUD        
 Min.   :    -3.0   Min.   :-766123.0  
 1st Qu.:     2.9   1st Qu.:    -76.8  
 Median :     2.9   Median :    -76.5  
 Mean   :   375.2   Mean   :   -752.1  
 3rd Qu.:     3.0   3rd Qu.:    -76.3  
 Max.   :420372.9   Max.   :     76.9 

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.