[R-sig-Geo] extract lat-long pairs from sf::st_read MULTIPOLYGON format

Roman Luštrik roman.lustrik at gmail.com
Sun May 7 09:49:29 CEST 2017


After downloading
https://github.com/trulia/choroplethrAdmin1/blob/master/data/admin1.map.rdata
and

load("admin1.map.rdata")
ilmap<-admin1.map[which(admin1.map$admin == "slovenia"), ]


I get a data.frame

> names(ilmap)
 [1] "long"       "lat"        "order"      "hole"       "piece"
 "group"
 [7] "id"         "adm1_code"  "OBJECTID_1" "diss_me"    "adm1_cod_1"
"iso_3166_2"
[13] "wikipedia"  "iso_a2"     "adm0_sr"    "name"       "name_alt"
"name_local"
[19] "type"       "type_en"    "code_local" "code_hasc"  "note"
"hasc_maybe"
[25] "region"     "region_cod" "provnum_ne" "gadm_level" "check_me"
"scalerank"
[31] "datarank"   "abbrev"     "postal"     "area_sqkm"  "sameascity"
"labelrank"
[37] "featurecla" "name_len"   "mapcolor9"  "mapcolor13" "fips"
"fips_alt"
[43] "woe_id"     "woe_label"  "woe_name"   "latitude"   "longitude"
 "sov_a3"
[49] "adm0_a3"    "adm0_label" "admin"      "geonunit"   "gu_a3"
 "gn_id"
[55] "gn_name"    "gns_id"     "gns_name"   "gn_level"   "gn_region"
 "gn_a1_code"
[61] "region_sub" "sub_code"   "gns_level"  "gns_lang"   "gns_adm1"
"gns_region"


Notice the first two columns. If this isn't what you're after, perhaps try
coordinates().

Cheers,
Roman


On Sat, May 6, 2017 at 10:56 PM, Brandon Payne <payneb at post.bgu.ac.il>
wrote:

>
> ## I am trying to modify the
>
> install_github("choroplethrAdmin1", "arilamstein")
>
> package.  It can show a map by
>
> choroplethrAdmin1::admin1_map("israel")
>
> The shape data is hidden in .Rdata, (principle of encapsulation)
> so to get at it I had to
>
> ```{bash}
> git clone git at github.com:arilamstein/choroplethrAdmin1.git
> cd chor*
> ```
> ```{r}
> load("/Users/AbuDavid/scratch/R/choroplethrAdmin1/data/
> admin1.regions.rdata")
> ilmap<-admin1.map[which(admin1.map$admin == name), ]
> View(ilmap)
> #write.csv(ilmap, file = "israel.csv", row.names=FALSE)
>
> ```
>
> the format of this data looks like
>
> 35.13070357     32.70585928     israel  haifa district  1879.1  272218
> FALSE   1       1879
> 35.12837813     32.70314627     israel  haifa district  1879.1  272219
> FALSE   1       1879
> 35.12574263     32.7008725      israel  haifa district  1879.1  272220
> FALSE   1       1879
> 35.12419234     32.69989065     israel  haifa district  1879.1  272221
> FALSE   1       1879
> 35.12248701     32.69919302     israel  haifa district  1879.1  272222
> FALSE   1       1879
> 35.12078169     32.69911551     israel  haifa district  1879.1  272223
> FALSE   1       1879
> 35.02130456     32.38117626     israel  central district        1880.1
> 272295  FALSE   1       1880
> 35.0327303      32.38220026     israel  central district        1880.1
> 272296  FALSE   1       1880
> 35.02879684     32.36515737     israel  central district        1880.1
> 272297  FALSE   1       1880
> 35.02156213     32.34459015     israel  central district        1880.1
> 272298  FALSE   1       1880
> 35.01784143     32.34221303     israel  central district        1880.1
> 272299  FALSE
> 1       1880
>
> ## Question:
>
> How can I get the data from my shape file as 2 columns: c(lat, long) ?
>
> I don't mind using something other than sf:st_read.
>
> ```{r importshapes}
> editedmap <- sf::st_read("../includes/ISR_adm_edited/ISR_adm1.shp")
> golan <- editedmap[which(editedmap$NAME_1 == "Golan"), ]
> names(editedmap)
> ```
>
> > names(editedmap)
>  [1] "ID_0"      "ISO"       "NAME_0"    "ID_1"      "NAME_1"    "TYPE_1"
>
>  [7] "ENGTYPE_1" "NL_NAME_1" "VARNAME_1" "geometry"
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
In God we trust, all others bring data.

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list