Skip to content

Instantly share code, notes, and snippets.

@teslabs
Last active December 11, 2015 05:29
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 teslabs/33e8803ae41fdaad245d to your computer and use it in GitHub Desktop.
Save teslabs/33e8803ae41fdaad245d to your computer and use it in GitHub Desktop.
Densitat de població a Catalunya, 2014

Mapa que mostra la densitat de població a Catalunya a nivell de municipi (2014). Si poseu el ratolí sobre algun dels municipis podreu veure les xifres.

  • Mapa generat amb cat-topojson, utilitzant dades de l'ICGC (CC-BY).
  • Dades de poblacio obtingudes a traves de l'INE i processades amb el codi que s'adjunta al gist, process.py.
  • Els codis municipals dels mapes són de 6 digits (l'últim és un digit de control que es genera amb l'algoritme "ABC"), mentre que els de les dades de població que publica l'INE són de 5 digits. En el codi sols s'utilitzen 5 digits.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
id pop
08001 12125
08002 251
08014 2498
08003 9651
08004 300
08005 8283
08006 15307
08007 8654
08008 212
08009 11963
08010 5661
08011 2258
08012 2275
08013 1675
08015 217210
08904 13553
08016 2225
08017 3724
08018 3343
08252 32550
08019 1602386
08020 6620
08021 78
08022 16456
08023 8854
08024 540
08025 1991
08026 263
08027 961
08028 1363
08029 4525
08030 7197
08031 3475
08034 949
08033 17156
08032 2738
08035 18307
08037 2429
08038 1985
08036 202
08039 521
08040 14123
08041 15954
08042 2863
08043 4345
08044 5284
08045 88
08046 17698
08047 4921
08048 817
08049 1569
08057 75
08052 159
08050 171
08051 23440
08053 3624
08054 12434
08055 718
08056 63255
08058 2237
08060 177
08059 428
08061 2022
08062 1241
08063 571
08064 2400
08065 1589
08066 1760
08067 7333
08268 1246
08266 57402
08068 8811
08069 4427
08070 338
08071 323
08072 14237
08073 86234
08074 14481
08075 5137
08076 21685
08077 46133
08078 259
08079 407
08134 1096
08080 43
08082 1512
08081 482
08083 2259
08084 1429
08085 1353
08086 19170
08090 163
08087 202
08088 15762
08089 46326
08091 7194
08092 4987
08093 25
08094 2073
08095 80
08096 59930
08097 1429
08099 937
08100 2545
08101 253518
08162 2942
08102 38751
08103 838
08104 906
08105 13430
08107 14696
08108 6354
08106 9536
08109 257
08110 18417
08111 266
08112 20279
08113 75297
08242 297
08114 27895
08115 4783
08116 737
08117 3186
08118 22742
08119 8406
08120 8841
08121 124280
08122 2311
08138 5760
08123 25152
08124 51719
08128 695
08127 2945
08125 34394
08130 117
08131 895
08126 11315
08132 476
08133 164
08135 8863
08136 16217
08137 332
08129 595
08139 211
08140 6003
08141 6117
08142 150
08143 3624
08145 3579
08146 1735
08147 23543
08148 3609
08149 1186
08144 876
08150 303
08151 557
08152 131
08153 690
08154 892
08155 9065
08156 14454
08157 11253
08905 3002
08158 4023
08159 18733
08160 407
08161 15000
08163 25948
08164 1223
08165 2186
08166 1155
08167 8238
08182 3780
08168 477
08169 62866
08171 2624
08170 537
08230 10311
08172 28163
08174 532
08175 4207
08176 198
08177 57
08178 528
08179 726
08180 37233
08181 10518
08183 6124
08184 74353
08185 228
08901 300
08187 207444
08188 149
08190 283
08191 6780
08194 35386
08195 91
08196 27268
08197 10590
08198 5708
08199 875
08200 83107
08201 556
08203 3328
08202 17251
08204 3938
08205 87118
08206 972
08207 2532
08208 7542
08210 5900
08211 43715
08212 626
08209 8666
08213 8243
08215 3446
08193 1304
08216 24
08218 10733
08217 32981
08903 239
08220 3123
08221 16389
08222 2517
08223 2361
08225 106
08224 1093
08226 1175
08227 3130
08228 395
08229 644
08231 29339
08232 2364
08233 2436
08234 4248
08189 162
08235 4997
08236 2101
08237 2148
08238 19549
08239 644
08240 12590
08241 86
08098 3130
08262 9326
08264 6007
08265 1975
08263 28103
08243 173
08244 8038
08245 118738
08246 2233
08247 1259
08248 7114
08249 379
08250 9641
08251 7337
08253 162
08254 2188
08256 851
08255 177
08257 140
08259 9138
08258 1065
08260 25409
08261 3293
08192 7384
08267 8645
08269 3488
08270 28171
08271 83
08272 175
08273 3029
08274 5999
08276 322
08277 141
08278 6219
08275 317
08280 125
08281 6141
08279 215517
08282 8314
08283 8012
08284 16345
08285 13949
08286 3819
08287 1393
08288 2308
08289 5851
08290 2056
08291 6218
08292 1424
08293 258
08294 2699
08295 14612
08296 2519
08297 176
08298 41956
08299 443
08301 65358
08300 7395
08305 39221
08306 706
08303 314
08302 12506
08902 5250
08307 65941
08214 8882
08219 20185
08304 1090
08308 174
17001 826
17002 783
17003 155
17004 727
17006 1661
17007 2281
17008 5606
17009 6481
17010 425
17011 901
17012 1581
17015 19343
17016 949
17013 3994
17018 650
17019 2400
17020 4874
17021 200
17022 10761
17234 245
17023 39293
17029 248
17024 373
17025 1690
17026 728
17027 3751
17028 391
17031 243
17030 921
17032 2820
17033 7130
17034 10541
17035 686
17036 3395
17037 132
17038 515
17039 2359
17040 644
17041 324
17042 612
17044 9922
17046 1013
17047 11473
17048 10721
17189 2071
17049 5053
17050 934
17051 293
17054 532
17055 195
17057 1257
17056 2235
17058 245
17901 1284
17060 534
17061 220
17062 10143
17063 196
17064 417
17065 458
17005 563
17066 45444
17067 1041
17068 320
17069 443
17070 160
17071 1442
17902 1729
17073 2479
17074 710
17075 398
17076 159
17077 857
17078 432
17079 97227
17080 195
17081 362
17082 536
17083 4010
17084 301
17085 396
17086 3115
17087 340
17088 767
17089 8198
17090 738
17091 509
17092 4970
17093 1242
17094 1536
17095 38624
17096 211
17102 781
17103 6963
17097 283
17098 443
17100 284
17101 723
17099 94
17105 326
17106 182
17107 339
17109 970
17110 1739
17111 1262
17112 245
17114 33913
17115 380
17116 452
17117 22763
17118 17805
17119 98
17121 305
17120 1437
17123 474
17124 2533
17125 155
17126 410
17128 569
17129 189
17130 467
17132 1859
17133 1694
17134 300
17135 529
17136 223
17137 4529
17140 980
17138 1214
17139 1772
17141 8761
17142 3441
17043 182
17143 182
17144 291
17145 1859
17146 4000
17147 10751
17148 2148
17149 463
17150 2026
17151 244
17152 19600
17153 246
17154 133
17155 30103
17157 155
17183 351
17158 590
17159 776
17160 21810
17161 1353
17162 240
17163 3464
17164 5681
17165 812
17167 3413
17168 509
17185 2919
17166 708
17169 3434
17903 1264
17171 249
17172 626
17173 242
17174 232
17175 798
17176 177
17177 674
17178 2138
17180 12601
17181 5194
17182 341
17184 1567
17186 4937
17187 815
17188 181
17190 1123
17191 211
17192 195
17193 5851
17052 150
17194 95
17195 454
17196 288
17197 170
17198 704
17199 11381
17200 772
17201 150
17202 5681
17204 1053
17205 289
17203 204
17206 185
17014 86
17208 1305
17207 2965
17170 215
17209 901
17210 836
17211 1195
17212 169
17213 7702
17214 913
17215 2529
17217 440
17216 216
17218 787
17220 1037
17221 5481
17223 1190
17224 421
17225 307
17226 1103
17227 170
17228 399
17230 681
17222 153
17233 3136
17232 209
25001 170
25002 594
25003 5515
25038 2415
25004 769
25005 356
25006 419
25007 2139
25008 1608
25009 834
25010 242
25011 9252
25012 3270
25013 3003
25014 315
25015 423
25016 3093
25017 286
25019 6699
25020 333
25021 3547
25022 126
25023 6297
25024 416
25027 1360
25029 2389
25031 73
25032 81
25033 1508
25034 3656
25036 215
25037 479
25039 361
25040 16485
25041 875
25042 235
25044 244
25045 49
25046 555
25170 307
25047 1305
25048 2351
25049 192
25050 4956
25051 2075
25052 2342
25053 1516
25055 197
25057 234
25058 6088
25059 1140
25056 290
25060 88
25061 98
25062 911
25063 102
25904 163
25064 149
25067 976
25068 740
25069 565
25070 1083
25071 60
25072 9039
25073 708
25074 209
25075 140
25076 190
25077 587
25163 269
25161 443
25078 1400
25079 395
25081 395
25082 357
25088 119
25085 176
25086 866
25087 72
25089 125
25908 260
25092 162
25093 838
25094 182
25096 1294
25097 98
25098 303
25912 1129
25099 1734
25100 216
25101 715
25102 972
25103 147
25105 162
25104 136
25109 295
25903 317
25110 6827
25111 128
25115 1049
25112 350
25113 1607
25114 115
25910 128
25118 438
25119 3497
25121 968
25122 2677
25123 232
25124 195
25125 497
25126 367
25120 139176
25127 260
25128 159
25129 201
25133 959
25130 227
25131 560
25132 196
25134 887
25135 1384
25137 14963
25136 116
25139 623
25140 1027
25138 671
25142 515
25141 193
25143 105
25145 93
25025 1782
25146 280
25148 267
25149 1870
25150 235
25151 902
25152 158
25153 232
25154 141
25155 841
25156 1008
25157 211
25158 2135
25164 504
25165 349
25166 207
25167 302
25911 560
25168 656
25169 220
25171 3012
25030 172
25173 2318
25172 2701
25174 750
25175 248
25176 405
25177 450
25179 209
25180 296
25181 259
25182 1411
25183 667
25905 420
25185 963
25186 281
25913 106
25189 3021
25190 365
25191 423
25196 132
25192 1107
25197 175
25193 993
25902 685
25194 496
25201 124
25200 403
25202 131
25035 467
25204 1887
25203 12366
25205 706
25206 359
25207 9067
25208 377
25209 2237
25210 1754
25211 872
25212 307
25215 413
25216 267
25217 16587
25218 105
25219 173
25220 1536
25221 156
25222 76
25223 1202
25224 148
25225 911
25227 761
25226 291
25228 4512
25907 601
25230 2235
25231 709
25232 2301
25233 388
25234 6305
25043 992
25901 384
25238 262
25240 1888
25906 298
25239 849
25909 210
25242 964
25243 5474
25244 514
25245 563
25247 171
25248 1179
25254 1120
25249 228
25250 422
25251 930
25252 706
25253 188
25255 546
43001 909
43002 2335
43003 458
43004 9637
43005 5131
43904 4376
43006 940
43007 891
43008 395
43009 1859
43010 432
43011 1396
43012 4988
43013 7303
43906 3479
43014 21197
43016 5515
43015 105
43017 146
43018 474
43019 1654
43020 3057
43021 519
43022 1975
43023 307
43024 2174
43025 703
43026 1247
43027 216
43028 3495
43029 413
43030 622
43031 2077
43032 630
43033 1100
43034 660
43035 326
43036 1115
43037 24333
43903 3514
43038 33301
43907 5807
43039 114
43040 411
43041 267
43042 2869
43043 4222
43045 172
43046 122
43047 6539
43048 1136
43049 954
43050 3480
43051 11989
43901 11831
43053 239
43054 3836
43055 2838
43056 1051
43057 40
43058 118
43059 345
43060 3795
43061 46
43062 405
43063 800
43064 3091
43065 559
43066 182
43067 819
43068 673
43069 243
43070 292
43071 1219
43072 110
43073 112
43074 2306
43076 611
43075 108
43077 619
43078 1106
43079 519
43080 288
43081 782
43082 534
43083 174
43084 774
43085 293
43086 7359
43088 2650
43089 369
43090 1418
43091 165
43092 12148
43093 5578
43094 3190
43095 3530
43096 157
43097 548
43098 453
43100 4479
43099 371
43101 154
43102 596
43103 1287
43104 3155
43105 214
43106 1076
43107 480
43108 2344
43109 3420
43110 354
43111 2860
43112 361
43113 561
43141 123
43114 461
43115 181
43116 626
43117 164
43118 685
43119 1083
43120 550
43121 858
43122 141
43123 104962
43124 601
43125 1195
43126 1678
43127 1142
43128 1254
43129 6546
43130 256
43131 6322
43132 513
43133 8287
43134 394
43135 539
43905 26558
43136 15003
43137 2493
43902 3555
43138 3821
43139 2931
43140 3287
43142 1595
43143 65
43144 1665
43145 5598
43146 53
43044 5893
43147 653
43148 132199
43149 876
43150 1760
43151 126
43152 676
43153 15475
43154 160
43155 33932
43156 6904
43157 412
43158 116
43159 99
43160 1670
43161 24570
43162 6047
43163 36719
43164 417
43165 805
43175 682
43166 2229
43168 126
43167 540
43169 630
43170 1264
43171 21923
43172 487
43173 129
43174 202
43176 964
43177 449
43178 1872
43052 1250
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.border {
fill: none;
stroke-linejoin: round;
stroke-linecap: round;
}
.in {
stroke: #fff;
stroke-width: 0.5;
}
.out {
stroke: #333;
stroke-width: 1;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script src="//d3js.org/queue.v1.min.js"></script>
<script>
var width = 500,
height = 500;
// from: colorbrewer2.org
var color = d3.scale.log()
.domain([1, 10, 50, 100, 500, 1000, 2000, 5000, 10000])
.range(["#fff7ec", "#fee8c8", "#fdd49e", "#fdbb84", "#fc8d59", "#ef6548",
"#d7301f", "#b30000", "#7f0000"]);
var path = d3.geo.path()
.projection(null);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var population = d3.map();
queue()
.defer(d3.json, "cat-municipis.json")
.defer(d3.csv, "data.csv", function(d) { population.set(+d.id, +d.pop); })
.await(ready);
function ready(error, cat) {
if (error) throw error;
svg.selectAll("path")
.data(topojson.feature(cat, cat.objects.municipis).features)
.enter().append("path")
.attr("d", path)
.attr("fill", function(d) {
return color(d.density =
population.get(Math.floor(d.id/10)) / d.properties.sup);
})
.append("title")
.text(function(d) {
return d.properties.nom + ": " + d.density.toFixed(0) + " hab/km²";
});
svg.append("path")
.datum(topojson.mesh(cat, cat.objects.municipis,
function (a, b) { return a !== b; }))
.attr("class", "border in")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(cat, cat.objects.municipis,
function (a, b) { return a === b; }))
.attr("class", "border out")
.attr("d", path);
}
</script>
'''
Simple utility to gather data from the INE census files
Usage
-----
python process.py
[-y | --year <year>]
-o | --output <output_file>
Notes
-----
- INE CSV files must be ';' separated (',' will not work, as some
municipalities include a ',' in the name...
- Any tabla_*.csv file will be processed
- Only the total is processed (i.e. sex split is ignored)
Data source
-----------
http://www.ine.es/dynt3/inebase/es/index.html?padre=517&dh=1
'''
import glob
import argparse
import csv
def process(year, output):
f_o = open(output, 'w')
c_o = csv.writer(f_o)
c_o.writerow(['id', 'pop'])
for f_d in glob.glob('tabla_*.csv'):
f_i = open(f_d)
c_i = csv.reader(f_i, delimiter=';')
# skip crap (first 9 lines)
for i in range(8): next(c_i)
# using try because of "notes" at the end...
for entry in c_i:
try:
c_o.writerow([entry[0].split()[0],
entry[(2014 - year) + 1].split('.')[0]])
except:
pass
f_i.close()
f_o.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-y', '--year', type=int, default=2014,
help='year (2014-1996)')
parser.add_argument('-o', '--output', type=str, required=True,
help='output file')
args = parser.parse_args()
process(args.year, args.output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment