Search code examples
rshapefilergdal

How to solve problem with reading a shapefile in R


How do I show a map that is in shapefile format that is in a zip file. The file is this:

https://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2015/UFs/PR/pr_municipios.zip

I tried to do the following:

library(rgdal)

temp <- tempfile()
download.file("https://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2015/UFs/PR/pr_municipios.zip",temp)
data <- readOGR(unz(temp, "41MUE250GC_SIR.shp"))

But it did not work.

The map will look like the one below:

enter image description here


Solution

  • Try this

    library(rgdal)
    
    temp <- tempfile()
    temp2 <- tempfile()
    download.file("https://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2015/UFs/PR/pr_municipios.zip",temp)
    
    unzip(zipfile = temp, exdir = temp2)
    shp <- readOGR(temp2)
    
    plot(shp)
    

    enter image description here