Transforming place into zip code

Asked

Viewed 604 times

5

Does anyone know a script on R, or could help me assemble one, take the name of a location and look for the zip code of this?

  • By "name" you mean the name of any establishment (like "Shopping ABC")? Or an address? In both cases you will have to implement your own solution, but the second case is much easier (there are already web services exposing data from the Funds).

  • It was address. Below already helped me. Thank you!

  • It is possible to "spatialize the CEP" as per demonstrated in "stackoverflow of GIS", allowing both the spatial refinement of very broad CEP areas and the correlation with other spatial data. Users of R in database can fully explore the resources of geoprocessing and spatial analysis through the Postgis.

2 answers

6


Google provides the zip code in some cases and there are already packages with functions to access the google API, the ggmap is one of them.

For example:

library(ggmap)
end <- geocode("Avenida das Americas, 4666 - Barra da Tijuca, Rio de Janeiro", output="more")
end$postal_code
[1] "22640-102"

However you have to keep in mind that this uses Google Maps, which is quite sensitive to the way you query and will not necessarily have everything you want to search for.

  • 1

    Thank you so much! That’s just what I needed!

3

An alternative to Carlos' answer is for you to load a (acquired) ZIP database and search directly into it.

I used the example CSV file from the site Qualocep (I do not know the site, and I believe that ideally it should be more guaranteed to buy this data directly from the Post Office)

> cep_data = read.table('cepbr_texto_exemplo.csv', header=TRUE, sep=';')
> query = subset(cep_data, Logradouro=="Max William Silva Gomes")
> cep = query[1]
> query
  CEP Tipo_Logradouro              Logradouro Complemento Local
  1 8382342             Rua Max William Silva Gomes                  
  Bairro     Cidade UF     Estado
  1 Recanto Verde do Sol São Paulo SP São Paulo
> cep
  1 8382342
  • 1

    Great alternative! Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.