Skip to content

Instantly share code, notes, and snippets.

@ikashnitsky
Created December 5, 2017 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikashnitsky/776b5c581ebb31a2a70d059638358d93 to your computer and use it in GitHub Desktop.
Save ikashnitsky/776b5c581ebb31a2a70d059638358d93 to your computer and use it in GitHub Desktop.
structure(list(stat_levl = c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L), shape_area = c(0.0653899829698, 1.3762043666,
1.25499783393, 0.93856596625, 0.427473808209, 0.663122706002,
0.396481635382, 0.613580039208, 0.579619503146, 0.841022895036,
0.872238590611, 0.638449668327, 0.489022847964, 0.685501846886
), shape_len = c(1.22710623792, 7.30786673034, 5.79400468308,
4.37316699851, 3.20638532907, 4.88925982656, 3.36453264071, 4.58107671594,
4.02423661604, 4.33880950383, 5.77002769494, 5.08364809113, 3.24035456572,
4.77048859037), id = c("CZ010", "CZ020", "CZ031", "CZ032", "CZ041",
"CZ042", "CZ051", "CZ052", "CZ053", "CZ063", "CZ064", "CZ071",
"CZ072", "CZ080"), geometry = structure(list(structure(list(list(
structure(c(4655437.28511691, 4632200.29874615, 4625030.50399954,
4627955.71992106, 4623056.0341683, 4642934.17466152, 4653954.13746451,
4657274.00758992, 4653064.84567108, 4655437.28511691, 2999966.96864717,
2990966.47736494, 3002796.58431263, 3004798.03535016, 3007656.17085423,
3016783.08867063, 3011695.4276424, 3006339.88808858, 3004338.84024216,
2999966.96864717), .Dim = c(10L, 2L)))), class = c("XY",
"MULTIPOLYGON", "sfg")), structure(list(list(structure(c(4685657.69886849,
4687494.6067129, 4683770.0131678, 4693803.04212316, 4703414.14915815,
4706020.05915348, 4703614.37413313, 4709591.71109085, 4704801.75095158,
4717606.32834278, 4715869.72725903, 4697305.95680054, 4694243.32717128,
4699832.62565783, 4698644.67478578, 4680782.6726564, 4677657.88667428,
4666254.91388058, 4656491.07200527, 4629425.99398041, 4593602.81480802,
4589935.92820451, 4585835.86462806, 4595923.65996026, 4595106.18142317,
4564741.05986513, 4573415.01780687, 4606110.07365944, 4631635.99335029,
4630578.10063604, 4639068.70076642, 4652670.56907963, 4668222.25477277,
4685657.69886849, 3058491.54105416, 3047943.52275587, 3041979.09089221,
3032708.87304468, 3033515.97825605, 3024571.36783688, 3017852.89219915,
3014139.0241898, 3006142.35968384, 2998021.44469592, 2986862.87131573,
2973747.34016169, 2966910.880389, 2961415.69885221, 2958129.63575163,
2955928.66179073, 2949338.39213773, 2954819.14908103, 2944410.0161262,
2948360.62448496, 2940446.06462515, 2958579.00972908, 2960451.99748345,
2967527.52443401, 2985746.64356184, 3003138.0543151, 3014614.71114957,
3033833.93977774, 3035957.56645715, 3044370.36681662, 3053424.892948,
3052229.60982197, 3067615.37128284, 3058491.54105416), .Dim = c(34L,
2L)), structure(c(4655437.28511691, 4653064.84567108, 4657274.00758992,
4653954.13746451, 4642934.17466152, 4623056.0341683, 4627955.71992106,
4625030.50399954, 4632200.29874615, 4655437.28511691, 2999966.96864717,
3004338.84024216, 3006339.88808858, 3011695.4276424, 3016783.08867063,
3007656.17085423, 3004798.03535016, 3002796.58431263, 2990966.47736494,
2999966.96864717), .Dim = c(10L, 2L)))), class = c("XY", "MULTIPOLYGON",
"sfg")), structure(list(list(structure(c(4677657.88667428, 4677201.66553197,
4695131.46868875, 4710149.8006388, 4710978.34267665, 4716454.24541702,
4726992.81391466, 4729641.48966699, 4722227.21140238, 4729896.02731508,
4726983.64024199, 4713489.58944913, 4698782.61311527, 4698187.35905517,
4685871.82256038, 4686807.2728495, 4674244.37150169, 4666960.76301764,
4650267.10629065, 4640108.98824889, 4624573.45337407, 4603174.07535396,
4581003.23099798, 4580133.07986597, 4584538.6264835, 4582901.51380802,
4590219.2596644, 4589977.48161568, 4596263.88164437, 4593602.81480802,
4629425.99398041, 4656491.07200527, 4666254.91388058, 4677657.88667428,
2949338.39213773, 2925232.87472269, 2913973.81294398, 2914517.85369515,
2907805.73428367, 2904765.50174755, 2906003.5791606, 2900373.91497045,
2890927.10135556, 2885955.42219596, 2881333.19285155, 2888585.64550712,
2883069.93428391, 2888613.05204913, 2889754.88378641, 2863367.52880492,
2863250.43435325, 2841107.5928213, 2847214.02869754, 2837017.17862035,
2839115.13289583, 2858273.1190771, 2879001.46663332, 2884558.3194647,
2889926.25218156, 2899125.49111485, 2901993.15370777, 2914103.69426092,
2923838.90537178, 2940446.06462515, 2948360.62448496, 2944410.0161262,
2954819.14908103, 2949338.39213773), .Dim = c(34L, 2L)))), class = c("XY",
"MULTIPOLYGON", "sfg")), structure(list(list(structure(c(4564741.05986513,
4595106.18142317, 4595923.65996026, 4585835.86462806, 4589935.92820451,
4593602.81480802, 4596263.88164437, 4589977.48161568, 4590219.2596644,
4582901.51380802, 4584538.6264835, 4580133.07986597, 4581003.23099798,
4571071.89716693, 4569288.51363986, 4552189.41639872, 4537032.47270209,
4522898.54674596, 4511863.50101466, 4512433.25079095, 4508712.4247691,
4502950.6456015, 4494030.75032839, 4504235.75512796, 4531263.23189085,
4542920.77023561, 4552708.78052065, 4557136.61713735, 4564741.05986513,
3003138.0543151, 2985746.64356184, 2967527.52443401, 2960451.99748345,
2958579.00972908, 2940446.06462515, 2923838.90537178, 2914103.69426092,
2901993.15370777, 2899125.49111485, 2889926.25218156, 2884558.3194647,
2879001.46663332, 2879894.66617503, 2887712.64547312, 2900592.41685591,
2917801.52964134, 2918827.89381209, 2932678.57049417, 2937913.92132675,
2939910.53627734, 2955797.72342612, 2963467.46120099, 2980138.65023878,
2982911.26272877, 2996095.44133847, 2992204.61817621, 3003906.57532981,
3003138.0543151), .Dim = c(29L, 2L)))), class = c("XY", "MULTIPOLYGON",
"sfg")), structure(list(list(structure(c(4530540.39049544, 4550235.10243599,
4550794.936677, 4557136.61713735, 4552708.78052065, 4542920.77023561,
4531263.23189085, 4504235.75512796, 4498310.07647088, 4499563.4650531,
4482881.86966156, 4475191.64706733, 4470101.55611129, 4473526.29639172,
4470617.44355199, 4476551.62122638, 4487803.06659128, 4487267.70658142,
4491757.29831818, 4504645.43725055, 4521211.62848521, 4530540.39049544,
3036694.34024385, 3031727.92707625, 3019469.03750583, 3003906.57532981,
2992204.61817621, 2996095.44133847, 2982911.26272877, 2980138.65023878,
2984380.48263283, 2988511.08074733, 2996472.52229079, 3014233.69022178,
3017706.58157402, 3020624.53827617, 3025026.01444986, 3025677.62895353,
3009296.41280366, 3017148.16522749, 3026022.71834651, 3036024.57531994,
3042500.29862324, 3036694.34024385), .Dim = c(22L, 2L)))), class = c("XY",
"MULTIPOLYGON", "sfg")), structure(list(list(structure(c(4635755.04075108,
4643701.98353207, 4641713.47724854, 4647703.62920579, 4645979.16055403,
4633908.67458032, 4627883.69369161, 4639068.70076642, 4630578.10063604,
4631635.99335029, 4606110.07365944, 4573415.01780687, 4564741.05986513,
4557136.61713735, 4550794.936677, 4550235.10243599, 4530540.39049544,
4538001.71161551, 4547482.13787873, 4551406.49177864, 4568654.60244729,
4569931.87625962, 4578743.54524359, 4593118.3831773, 4595672.56157921,
4629504.97879293, 4619827.12779432, 4623550.10347357, 4635755.04075108,
3113254.65462335, 3107458.89522487, 3099683.92625198, 3101279.50920759,
3093185.02288159, 3087256.22951701, 3070907.43252797, 3053424.892948,
3044370.36681662, 3035957.56645715, 3033833.93977774, 3014614.71114957,
3003138.0543151, 3003906.57532981, 3019469.03750583, 3031727.92707625,
3036694.34024385, 3047770.86249593, 3048412.34066146, 3058844.46261747,
3063911.08056124, 3071854.92589247, 3075177.84085336, 3075577.78818147,
3082935.45857789, 3096906.90979042, 3106108.85249756, 3113763.43202096,
3113254.65462335), .Dim = c(29L, 2L)))), class = c("XY", "MULTIPOLYGON",
"sfg")), structure(list(list(structure(c(4710986.85100885, 4715187.41994266,
4719978.91834445, 4708809.0007905, 4704028.1038125, 4685657.69886849,
4668222.25477277, 4652670.56907963, 4639068.70076642, 4627883.69369161,
4633908.67458032, 4645979.16055403, 4656623.26121214, 4660255.77946421,
4672812.60918444, 4673306.34621239, 4669532.11850419, 4673806.18021034,
4691028.64305957, 4691943.59379696, 4699386.90024166, 4710986.85100885,
3088955.84824018, 3067153.58596647, 3061007.19009356, 3062769.12162079,
3055016.40587222, 3058491.54105416, 3067615.37128284, 3052229.60982197,
3053424.892948, 3070907.43252797, 3087256.22951701, 3093185.02288159,
3089578.94151077, 3095529.14261196, 3096203.63155478, 3107121.59416414,
3109474.65400717, 3113259.68348367, 3109815.44422872, 3100004.37637685,
3088259.03828111, 3088955.84824018), .Dim = c(22L, 2L)))), class = c("XY",
"MULTIPOLYGON", "sfg")), structure(list(list(structure(c(4752267.58395518,
4767379.27815674, 4776676.23051096, 4760637.00413197, 4772835.42239947,
4787562.87206065, 4790698.88332016, 4764128.80211906, 4743240.54526557,
4709591.71109085, 4703614.37413313, 4706020.05915348, 4703414.14915815,
4693803.04212316, 4683770.0131678, 4687494.6067129, 4685657.69886849,
4704028.1038125, 4708809.0007905, 4719978.91834445, 4715187.41994266,
4710986.85100885, 4730944.49951232, 4734798.69684538, 4743876.71746647,
4744175.78746676, 4747034.89869946, 4752267.58395518, 3079151.39223986,
3080927.44217701, 3072780.70893846, 3054175.27005668, 3049314.88779574,
3033918.48207618, 3024479.42770396, 3010836.57786601, 3023540.41905114,
3014139.0241898, 3017852.89219915, 3024571.36783688, 3033515.97825605,
3032708.87304468, 3041979.09089221, 3047943.52275587, 3058491.54105416,
3055016.40587222, 3062769.12162079, 3061007.19009356, 3067153.58596647,
3088955.84824018, 3087822.47837569, 3079153.24371617, 3080839.90020189,
3073196.0312692, 3071630.88010262, 3079151.39223986), .Dim = c(28L,
2L)))), class = c("XY", "MULTIPOLYGON", "sfg")), structure(list(
list(structure(c(4812156.93477204, 4782782.24131612, 4758852.99300718,
4747428.48721027, 4715869.72725903, 4717606.32834278, 4704801.75095158,
4709591.71109085, 4743240.54526557, 4764128.80211906, 4790698.88332016,
4800074.68775799, 4810262.35730499, 4808654.40110398, 4801508.04832533,
4806657.76889767, 4804911.86044425, 4814051.0159463, 4812156.93477204,
2965655.69620239, 2960974.98742188, 2973476.26456436, 2969797.87578421,
2986862.87131573, 2998021.44469592, 3006142.35968384, 3014139.0241898,
3023540.41905114, 3010836.57786601, 3024479.42770396, 3020160.28499942,
3032463.48304909, 3015138.12231772, 3009466.95409292, 2995654.12210572,
2991144.99736409, 2978944.04914899, 2965655.69620239), .Dim = c(19L,
2L)))), class = c("XY", "MULTIPOLYGON", "sfg")), structure(list(
list(structure(c(4782782.24131612, 4784883.55868194, 4782923.35623694,
4772593.50878494, 4776289.95418441, 4776649.48790781, 4729896.02731508,
4722227.21140238, 4729641.48966699, 4726992.81391466, 4716454.24541702,
4710978.34267665, 4710149.8006388, 4695131.46868875, 4677201.66553197,
4677657.88667428, 4680782.6726564, 4698644.67478578, 4699832.62565783,
4694243.32717128, 4697305.95680054, 4715869.72725903, 4747428.48721027,
4758852.99300718, 4782782.24131612, 2960974.98742188, 2955537.24193436,
2946609.27613311, 2939278.87899344, 2931106.03311063, 2906738.98814363,
2885955.42219596, 2890927.10135556, 2900373.91497045, 2906003.5791606,
2904765.50174755, 2907805.73428367, 2914517.85369515, 2913973.81294398,
2925232.87472269, 2949338.39213773, 2955928.66179073, 2958129.63575163,
2961415.69885221, 2966910.880389, 2973747.34016169, 2986862.87131573,
2969797.87578421, 2973476.26456436, 2960974.98742188), .Dim = c(25L,
2L)))), class = c("XY", "MULTIPOLYGON", "sfg")), structure(list(
list(structure(c(4812156.93477204, 4807984.17718625, 4813398.97329866,
4814190.25328251, 4818369.70887373, 4821926.26533562, 4818403.85637867,
4823233.02791397, 4841186.88668974, 4839809.72636969, 4847018.24438456,
4881191.0218301, 4863380.65558338, 4848442.54530457, 4832035.22539413,
4828203.20852721, 4808971.92174449, 4769395.10717486, 4749266.13173575,
4742889.36817913, 4726983.64024199, 4729896.02731508, 4776649.48790781,
4776289.95418441, 4772593.50878494, 4782923.35623694, 4784883.55868194,
4782782.24131612, 4812156.93477204, 2965655.69620239, 2959007.52602399,
2958230.38703889, 2944268.01813747, 2941938.1490959, 2947589.85844589,
2953859.01558278, 2954894.84392587, 2932235.72907995, 2909991.24951012,
2912452.37335851, 2889219.84093686, 2882817.07648173, 2888561.8389832,
2857836.83151578, 2868730.34807818, 2874466.04117312, 2866585.95996911,
2879232.33814724, 2876362.72492668, 2881333.19285155, 2885955.42219596,
2906738.98814363, 2931106.03311063, 2939278.87899344, 2946609.27613311,
2955537.24193436, 2960974.98742188, 2965655.69620239), .Dim = c(29L,
2L)))), class = c("XY", "MULTIPOLYGON", "sfg")), structure(list(
list(structure(c(4849853.54703172, 4838904.1898353, 4833302.69759193,
4833867.03099927, 4839384.62274172, 4849094.43248373, 4851988.37110854,
4856785.50153155, 4862275.46177415, 4872099.65589788, 4875030.29429731,
4892859.22971451, 4863021.33769998, 4854900.1933195, 4852550.75037502,
4854695.33030495, 4841186.88668974, 4823233.02791397, 4818403.85637867,
4821926.26533562, 4818369.70887373, 4814190.25328251, 4813398.97329866,
4807984.17718625, 4812156.93477204, 4814051.0159463, 4804911.86044425,
4806657.76889767, 4801508.04832533, 4808654.40110398, 4810262.35730499,
4821651.6787661, 4807933.84254031, 4810829.48245579, 4849853.54703172,
3042644.75929838, 3029562.85291063, 3010624.81766599, 2998934.86568178,
2992792.9811361, 2998703.75615342, 2990998.73008847, 3000411.81229961,
2989777.70549869, 2989321.34665625, 2980564.2037375, 2966951.68147389,
2943325.1261924, 2949001.04904771, 2945421.53645081, 2941143.40905234,
2932235.72907995, 2954894.84392587, 2953859.01558278, 2947589.85844589,
2941938.1490959, 2944268.01813747, 2958230.38703889, 2959007.52602399,
2965655.69620239, 2978944.04914899, 2991144.99736409, 2995654.12210572,
3009466.95409292, 3015138.12231772, 3032463.48304909, 3037110.12280293,
3055715.92986958, 3060614.48935576, 3042644.75929838), .Dim = c(35L,
2L)))), class = c("XY", "MULTIPOLYGON", "sfg")), structure(list(
list(structure(c(4929608.18401518, 4924768.5993742, 4912898.62456869,
4909847.30139361, 4899495.26795712, 4897693.75227506, 4881191.0218301,
4847018.24438456, 4839809.72636969, 4841186.88668974, 4854695.33030495,
4852550.75037502, 4854900.1933195, 4863021.33769998, 4892859.22971451,
4910845.83685414, 4929608.18401518, 2955255.71598985, 2945551.25376378,
2936624.20968309, 2912803.57045203, 2909711.51701996, 2899190.59393302,
2889219.84093686, 2912452.37335851, 2909991.24951012, 2932235.72907995,
2941143.40905234, 2945421.53645081, 2949001.04904771, 2943325.1261924,
2966951.68147389, 2966611.1707773, 2955255.71598985), .Dim = c(17L,
2L)))), class = c("XY", "MULTIPOLYGON", "sfg")), structure(list(
list(structure(c(4895030.48697087, 4917282.28536065, 4935450.2065429,
4941540.28890759, 4954798.28796702, 4960290.23310086, 4939819.83482428,
4929608.18401518, 4910845.83685414, 4892859.22971451, 4875030.29429731,
4872099.65589788, 4862275.46177415, 4856785.50153155, 4851988.37110854,
4849094.43248373, 4839384.62274172, 4833867.03099927, 4833302.69759193,
4838904.1898353, 4849853.54703172, 4869555.8255705, 4873722.25616374,
4862493.28770809, 4884293.77774443, 4895030.48697087, 3026304.28912109,
3012000.94861155, 3013499.74075466, 2993133.33727183, 2989846.12833918,
2972378.411507, 2968788.32773842, 2955255.71598985, 2966611.1707773,
2966951.68147389, 2980564.2037375, 2989321.34665625, 2989777.70549869,
3000411.81229961, 2990998.73008847, 2998703.75615342, 2992792.9811361,
2998934.86568178, 3010624.81766599, 3029562.85291063, 3042644.75929838,
3052125.19754159, 3039762.88823171, 3033371.16280021, 3014695.77132069,
3026304.28912109), .Dim = c(26L, 2L)))), class = c("XY",
"MULTIPOLYGON", "sfg"))), class = c("sfc_MULTIPOLYGON", "sfc"
), precision = 0, bbox = structure(c(4470101.55611129, 2837017.17862035,
4960290.23310086, 3113763.43202096), .Names = c("xmin", "ymin",
"xmax", "ymax"), class = "bbox"), crs = structure(list(epsg = 3035L,
proj4string = "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"), .Names = c("epsg",
"proj4string"), class = "crs"), n_empty = 0L)), .Names = c("stat_levl",
"shape_area", "shape_len", "id", "geometry"), row.names = c(NA,
-14L), class = c("sf", "data.frame"), sf_column = "geometry", agr = structure(c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_), class = "factor", .Label = c("constant",
"aggregate", "identity"), .Names = c("stat_levl", "shape_area",
"shape_len", "id")))
################################################################################
#
# ikashnitsky.github.io 2017-12-05
# Toy example of gghole
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#
################################################################################
# load required packages
library(tidyverse) # data manipulation and viz
library(sf) # deal with shapefiles
library(janitor) # clean_names()
# geodata will be stored in a directory "geodata"
ifelse(!dir.exists('geodata'),
dir.create('geodata'),
paste("Directory already exists"))
f <- tempfile()
download.file("http://ec.europa.eu/eurostat/cache/GISCO/geodatafiles/NUTS_2013_20M_SH.zip", destfile = f)
unzip(f, exdir = "geodata/.")
NUTS <- st_read("geodata/NUTS_2013_20M_SH/data/.", "NUTS_RG_20M_2013") %>%
clean_names() %>%
st_transform(3035)
# filter Czech republic
CZ <- NUTS %>%
filter(stat_levl == 3,
nuts_id %>% str_sub(1,2)=="CZ") %>%
mutate(id = nuts_id %>% as.character()) %>%
select(-nuts_id)
dput(CZ, file = "CZ.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment