Skip to content

Instantly share code, notes, and snippets.

@sjsrey
Last active December 27, 2015 01:19
Show Gist options
  • Save sjsrey/7243763 to your computer and use it in GitHub Desktop.
Save sjsrey/7243763 to your computer and use it in GitHub Desktop.
Folium and PySAL

Folium and PySAL

This gist demonstrates the combined use of the Python Spatial Analysis Library PySAL together with Folium.

Author: Serge Rey

What is demonstrated

  • Creating geojson from a shapefile via a web request
  • Choropleth classification schemes from PySAL
  • Folium for rendering

The data for this example are for homicide rates in 90 counties surrounding Atlanta, GA. The source is the data archive at the GeoDa Center for Geospatial Computation and Analysis.

The gist also includes html files with other classification schemes (can be opened locally). All code to reproduce these files is in the IPython notebook mapping-atlanta.ipynb

<!DOCTYPE html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<style>
.legend {
padding: 0px 0px;
font: 10px sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.key path {
display: none;
}
</style>
</head>
<body>
<div id="map" style="width: 960px; height: 500px"></div>
<script>
queue()
.defer(d3.json, 'atl_hom.json')
.await(makeMap)
function makeMap(error, gjson_1) {
function matchKey(datapoint, key_variable){
return(parseFloat(key_variable[0][datapoint]));
};
var map = L.map('map').setView([33.755, -84.39], 7);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data (c) <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
}).addTo(map);
function style_1(feature) {
return {
fillColor: 'blue',
weight: 1,
opacity: 1,
color: 'black',
fillOpacity: 0.6
};
}
gJson_layer_1 = L.geoJson(gjson_1, {style: style_1}).addTo(map)
};
</script>
</body>
gZ���#�����������������W��NAME�������C���� ���������������STATE_NAME�C�������������������STATE_FIPS�C�������������������CNTY_FIPS��C�������������������FIPS�������C�������������������STFIPS�����N�������������������COFIPS�����N�������������������FIPSNO�����N�������������������HR7983�����N������������������HR8587�����N������������������HR8995�����N������������������HC7983�����N���� ���������������HC8587�����N���� ���������������HC8995�����N���� ���������������PO7983�����N���� ���������������PO8587�����N���� ���������������PO8995�����N���� ���������������PE77�������N����
��������������PE82�������N���� ��������������PE87�������N����
��������������RDAC80�����N����
��������������RDAC85�����N����
��������������RDAC90�����N����
��������������
Cherokee North Carolina 3703937039 37 39 37039 6.298816 6.742065 7.598889 6 4 11 95256 59329 144758 2.933480 1.605377 1.922455 0.897757 0.444341 0.134578 Polk Tennessee 4713947139 47 139 47139 13.271204 9.629968 11.315708 9 4 11 67816 41537 97210 4.422696 3.994711 3.833682 -0.012454 -0.140179 -0.192610 Oconee South Carolina 4507345073 45 73 45073 14.174115 6.246720 7.255753 35 10 30 246929 160084 413465 3.716055 3.635228 3.789255 -0.168537 -0.311719 -0.368479 Rabun Georgia 1324113241 13 241 13241 13.306214 6.038830 10.719135 7 2 9 52607 33119 83962 2.637461 2.625957 4.394626 0.449209 0.058768 -0.229536 Whitfield Georgia 1331313313 13 313 13313 10.274169 6.715627 5.908183 34 14 31 330927 208469 524696 4.099088 2.877935 2.452316 -0.318807 -0.476584 -0.566740 Murray Georgia 1321313213 13 213 13213 13.876912 5.813615 4.127222 14 4 8 100887 68804 193835 4.109589 4.410952 3.494970 -0.485121 -0.685540 -0.835694 Walker Georgia 1329513295 13 295 13295 10.224264 5.230703 5.537778 29 9 23 283639 172061 415329 4.012825 4.529491 4.587005 -0.284244 -0.403109 -0.447148 Towns Georgia 1328113281 13 281 13281 3.416234 5.206164 4.028928 1 1 2 29272 19208 49641 2.404007 2.436975 3.694701 1.182730 0.497340 -0.009981 Union Georgia 1329113291 13 291 13291 4.182613 3.137353 4.434049 2 1 4 47817 31874 90211 1.823109 1.308603 1.247505 1.438772 0.646412 0.098484 Fannin Georgia 1311113111 13 111 13111 14.819405 8.593834 8.647302 11 4 10 74227 46545 115643 3.725347 3.712480 4.116578 0.570016 0.218349 -0.012815 De Kalb Alabama 0104901049 1 49 1049 7.434889 6.817478 8.929551 20 11 35 269002 161350 391957 5.849497 5.583068 6.010943 0.402105 0.136934 -0.065875 Gilmer Georgia 1312313123 13 123 13123 3.563538 0.000000 4.946039 2 0 5 56124 36546 101091 4.122991 4.505256 3.401415 0.440731 0.033060 -0.267303 Habersham Georgia 1313713137 13 137 13137 11.816792 7.551254 2.488342 15 6 5 126938 79457 200937 4.942077 4.368730 2.848849 0.220126 -0.191158 -0.488021 White Georgia 1331113311 13 311 13311 3.853119 8.569470 3.083660 2 3 3 51906 35008 97287 4.831933 5.775344 4.010369 0.408084 -0.067800 -0.447920 Lumpkin Georgia 1318713187 13 187 13187 9.038976 5.264543 8.350421 5 2 9 55316 37990 107779 5.010020 2.993039 3.687892 0.207039 -0.159540 -0.351067 Stephens Georgia 1325713257 13 257 13257 10.006368 10.255809 7.717515 11 7 13 109930 68254 168448 3.048780 3.552568 2.586260 -0.017862 -0.073223 -0.077691 Gordon Georgia 1312913129 13 129 13129 9.836066 5.051679 7.435555 15 5 19 152500 98977 255529 4.274466 5.138858 5.009998 -0.209903 -0.491178 -0.640013 Dawson Georgia 1308513085 13 85 13085 3.926959 9.015100 6.849127 1 2 5 25465 22185 73002 3.827519 6.462953 4.539658 0.157312 -0.233689 -0.419987 Floyd Georgia 1311513115 13 115 13115 13.548742 10.008841 10.577148 54 24 61 398561 239788 576715 4.999027 4.144607 3.153195 0.044529 -0.032006 -0.056005 Chattooga Georgia 1305513055 13 55 13055 12.830853 7.619280 8.886688 14 5 14 109112 65623 157539 4.095292 4.766088 5.848435 0.121619 -0.022029 -0.089995 Pickens Georgia 1322713227 13 227 13227 5.066198 5.077560 7.485240 3 2 8 59216 39389 106877 2.055733 3.889934 4.877852 0.273263 -0.104155 -0.378349 Franklin Georgia 1311913119 13 119 13119 15.596974 12.359157 8.306545 12 6 10 76938 48547 120387 6.455469 6.779240 5.841824 0.493832 0.173629 -0.041490 Cherokee Alabama 0101901019 1 19 1019 8.402302 12.279194 7.141072 8 7 10 95212 57007 140035 2.242729 3.182700 5.356004 0.286548 0.103662 -0.002412 Hall Georgia 1313913139 13 139 13139 11.121946 7.291595 9.893280 43 19 70 386623 260574 707551 3.828217 3.958338 2.976149 -0.169834 -0.401685 -0.562283 Hart Georgia 1314713147 13 147 13147 10.736641 1.728369 3.555556 10 1 5 93139 57858 140625 3.659685 4.585397 4.456594 0.452839 0.254194 0.150012 Banks Georgia 1301113011 13 11 13011 2.292579 3.449822 2.671012 1 1 2 43619 28987 74878 1.863990 4.229780 4.353217 -0.222323 -0.352417 -0.396127 Bartow Georgia 1301513015 13 15 13015 9.609009 13.782268 5.801936 20 20 24 208138 145114 413655 3.220307 3.176138 4.857098 -0.244708 -0.439502 -0.522730 Cherokee Georgia 1305713057 13 57 13057 7.769548 5.547645 2.985283 21 12 21 270286 216308 703451 2.778567 3.314448 3.961731 -0.884394 -1.348245 -1.556684 Forsyth Georgia 1311713117 13 117 13117 4.889429 8.324084 6.476994 7 9 23 143166 108120 355103 7.125024 3.850152 4.460564 -0.600124 -1.138518 -1.445282 Jackson Georgia 1315713157 13 157 13157 13.928978 9.518144 7.679208 18 8 17 129227 84050 221377 5.422544 4.272494 3.367338 0.205892 -0.159261 -0.382726 Elbert Georgia 1310513105 13 105 13105 14.864994 14.104372 18.739787 14 8 25 94181 56720 133406 6.392184 3.930131 4.528220 0.639770 0.722065 0.760144 Madison Georgia 1319513195 13 195 13195 7.948133 5.151010 11.016427 7 3 17 88071 58241 154315 5.611831 3.140689 2.120117 -0.057655 -0.247883 -0.302842 Etowah Alabama 0105501055 1 55 1055 13.417755 11.139323 10.366579 69 34 73 514244 305225 704186 5.283321 6.315855 6.954265 0.360856 0.262993 0.181083 Fulton Georgia 1312113121 13 121 13121 28.693880 27.730722 29.370922 864 533 1382 3011095 1922056 4705334 6.439624 5.566294 4.197333 2.287277 1.964545 1.524987 Gwinnett Georgia 1313513135 13 135 13135 4.208353 5.642975 3.872291 38 47 107 902966 832894 2763222 4.580761 5.377853 3.866283 -1.647628 -1.767002 -1.799208 Barrow Georgia 1301313013 13 13 13013 18.265674 9.063483 11.544473 20 7 26 109495 77233 225216 6.120721 6.488934 5.324384 0.129183 -0.127135 -0.330774 Cobb Georgia 1306713067 13 67 13067 7.971606 5.514976 5.535022 124 65 186 1555521 1178609 3360420 4.852866 5.459033 4.597056 -1.232344 -1.378499 -1.444577 Polk Georgia 1323313233 13 233 13233 12.871827 6.951824 11.235160 21 7 27 163147 100693 240317 4.483247 4.800711 5.497714 0.270717 0.164385 0.118102 Paulding Georgia 1322313223 13 223 13223 8.913252 15.045135 5.285707 12 15 18 134631 99700 340541 4.411622 3.915859 3.011721 -0.581324 -1.016047 -1.270930 Clarke Georgia 1305913059 13 59 13059 9.965697 7.310892 10.645350 38 18 66 381308 246208 619989 5.043474 5.077869 4.955355 0.750520 0.945602 0.998910 Oglethorpe Georgia 1322113221 13 221 13221 13.270520 14.122798 12.608574 6 4 9 45213 28323 71380 2.138643 3.296465 2.444571 0.675604 0.397621 0.169302 Wilkes Georgia 1331713317 13 317 13317 10.913853 9.036417 9.409867 6 3 7 54976 33199 74390 3.419183 3.315714 3.538870 1.721569 1.717281 1.641282 Calhoun Alabama 0101501015 1 15 1015 11.650434 11.280570 13.743560 70 40 111 600836 354592 807651 3.991195 3.584222 3.786775 0.178587 0.080222 0.029961 Oconee Georgia 1321913219 13 219 13219 7.768076 2.210482 5.287129 5 1 7 64366 45239 132397 5.587484 3.961184 3.108634 -0.545097 -0.828758 -1.007987 De Kalb Georgia 1308913089 13 89 13089 11.655774 12.144973 15.537506 285 192 613 2445140 1580901 3945292 3.296870 4.561076 4.572441 -0.230428 -0.082140 -0.002935 Cleburne Alabama 0102901029 1 29 1029 18.881878 10.553811 16.558485 12 4 15 63553 37901 90588 3.041682 3.737433 3.466258 -0.087286 -0.270860 -0.356134 Walton Georgia 1329713297 13 297 13297 12.090129 8.585492 8.217715 19 9 24 157153 104828 292052 4.457012 4.385732 4.433560 0.281444 0.038638 -0.149754 Haralson Georgia 1314313143 13 143 13143 10.641921 8.011793 6.360271 10 5 10 93968 62408 157226 5.417985 4.871606 4.928766 -0.095140 -0.248022 -0.361340 Carroll Georgia 1304513045 13 45 13045 12.027491 10.694697 8.870924 35 21 46 291000 196359 518548 3.353003 3.432090 2.995487 0.118297 -0.006623 -0.118026 Morgan Georgia 1321113211 13 211 13211 15.323583 10.743735 9.630200 9 4 9 58733 37231 93456 5.098789 5.704561 4.274978 1.120607 0.799206 0.552520 Douglas Georgia 1309713097 13 97 13097 9.302292 6.193037 5.854757 26 12 31 279501 193766 529484 2.941696 5.353188 3.021740 -1.322913 -1.351451 -1.289694 Rockdale Georgia 1324713247 13 247 13247 4.789986 8.838802 3.912564 9 12 16 187892 135765 408939 4.765692 4.577791 5.000079 -1.203501 -1.289527 -1.302747 Greene Georgia 1313313133 13 133 13133 17.314218 14.404241 16.330911 10 5 14 57756 34712 85727 4.723376 2.632368 3.957154 1.771326 1.967551 2.059107 Newton Georgia 1321713217 13 217 13217 13.992903 20.508263 9.458859 25 24 30 178662 117026 317163 5.101472 5.183675 3.986803 0.095236 0.018585 0.003761 Taliaferro Georgia 1326513265 13 265 13265 19.349845 16.103060 23.228804 2 1 3 10336 6210 12915 5.895954 5.437100 5.535586 3.309996 2.844978 2.405909 Talladega Alabama 0112101121 1 121 1121 9.945969 9.316357 12.955071 37 21 68 372010 225410 524891 3.839917 4.012136 3.483949 0.910029 0.896945 0.864980 Clayton Georgia 1306313063 13 63 13063 7.822084 9.950467 10.144222 60 50 134 767059 502489 1320949 5.283019 5.915541 5.316768 -1.183199 -0.789391 -0.477559 Henry Georgia 1315113151 13 151 13151 13.447729 8.726194 5.803169 25 12 28 185905 137517 482495 5.999195 4.540127 3.922966 -0.600815 -1.138669 -1.451125 Fayette Georgia 1311313113 13 113 13113 5.731316 3.494964 3.305901 9 5 16 157032 143063 483983 5.185688 5.961913 6.623303 -1.697320 -2.035866 -2.184822 Jasper Georgia 1315913159 13 159 13159 2.607018 21.394035 9.830747 1 5 6 38358 23371 61033 5.260361 5.088031 5.023351 1.020881 0.945797 0.795836 Coweta Georgia 1307713077 13 77 13077 11.480540 15.939834 7.017117 23 22 30 200339 138019 427526 4.398336 4.118176 5.308674 0.490567 0.069622 -0.255120 Randolph Alabama 0111101111 1 111 1111 19.921509 8.468835 14.900592 20 5 21 100394 59040 140934 3.803524 2.313536 2.214669 0.912920 0.718898 0.590663 Clay Alabama 0102701027 1 27 1027 7.244907 2.468039 7.488073 5 1 7 69014 40518 93482 2.447925 2.477615 2.437864 0.780295 0.534350 0.368668 Putnam Georgia 1323713237 13 237 13237 22.511115 0.000000 14.382281 12 0 15 53307 37612 104295 2.990274 8.103834 5.562387 0.811727 0.823842 0.761701 Hancock Georgia 1314113141 13 141 13141 14.822657 14.381764 12.701034 7 4 8 47225 27813 62987 3.676644 4.920971 3.549078 3.664248 3.402196 3.005477 Butts Georgia 1303513035 13 35 13035 9.974494 6.732496 17.363015 7 3 19 70179 44560 109428 6.981204 7.277791 6.856777 0.678874 0.620432 0.545344 Heard Georgia 1314913149 13 149 13149 12.182865 0.000000 4.761073 4 0 3 32833 22703 63011 4.005935 2.802079 4.416584 0.168312 0.241719 0.256674 Spalding Georgia 1325513255 13 255 13255 15.630077 17.374070 13.049018 38 27 51 243121 155404 390834 5.498095 5.405901 6.413676 0.712268 0.625184 0.527349 Meriwether Georgia 1319913199 13 199 13199 19.774011 12.389463 18.911337 21 8 30 106200 64571 158635 5.475315 5.927100 3.244501 1.317521 1.351740 1.322676 Troup Georgia 1328513285 13 285 13285 12.674221 15.478439 12.843889 32 25 51 252481 161515 397076 6.883338 4.560061 3.812650 1.086532 0.819876 0.573770 Lamar Georgia 1317113171 13 171 13171 6.592392 7.878772 7.464119 4 3 7 60676 38077 93782 4.048843 5.690462 5.970874 0.516541 0.743496 0.860858 Monroe Georgia 1320713207 13 207 13207 6.794955 12.527927 9.576404 5 6 12 73584 47893 125308 4.850174 7.660079 5.793786 0.892645 0.427235 0.109093 Pike Georgia 1323113231 13 231 13231 4.524580 14.125291 6.744271 2 4 5 44203 28318 74137 4.111210 4.617444 3.558914 -0.227569 -0.316149 -0.348852 Baldwin Georgia 1300913009 13 9 13009 14.538053 13.815494 7.755080 26 16 22 178841 115812 283685 5.978510 4.215206 3.354801 0.622059 0.922519 1.099701 Jones Georgia 1316913169 13 169 13169 10.554090 8.576476 6.071973 9 5 9 85275 58299 148222 1.800720 3.654066 4.596799 0.134309 -0.010033 -0.106471 Chambers Alabama 0101701017 1 17 1017 15.786606 16.623358 16.584451 31 19 43 196369 114297 259279 4.304015 5.173333 6.079671 0.823855 0.750034 0.698915 Tallapoosa Alabama 0112301123 1 123 1123 14.992736 10.354915 16.740056 29 12 46 193427 115887 274790 4.594574 4.297338 5.660003 0.650857 0.529719 0.459803 Wilkinson Georgia 1331913319 13 319 13319 15.408320 9.621244 17.912257 8 3 13 51920 31181 72576 6.011333 5.186003 5.811701 0.938837 0.698702 0.507253 Upson Georgia 1329313293 13 293 13293 8.390414 8.879305 5.933438 11 7 11 131102 78835 185390 4.049965 3.309141 2.865864 0.726408 0.552252 0.407802 Bibb Georgia 1302113021 13 21 13021 16.901795 14.735541 18.709826 128 67 200 757316 454683 1068957 6.590556 5.979030 5.095766 1.183559 1.266168 1.282627 Twiggs Georgia 1328913289 13 289 13289 12.728314 6.870019 17.490417 6 2 12 47139 29112 68609 4.716007 3.616879 4.064283 0.928311 1.276082 1.521147 Talbot Georgia 1326313263 13 263 13263 3.032692 5.207520 17.218001 1 1 8 32974 19203 46463 4.935370 2.664835 5.102848 1.881499 1.994781 2.024711 Harris Georgia 1314513145 13 145 13145 10.414904 9.905698 9.933522 8 5 13 76813 50476 130870 4.718853 5.251323 4.524469 0.766790 0.379812 0.046540 Crawford Georgia 1307913079 13 79 13079 10.698334 4.126604 6.076349 4 1 4 37389 24233 65829 2.248677 4.859279 5.091650 0.693066 0.314314 0.005875 Lee Alabama 0108101081 1 81 1081 8.235303 4.859224 7.967442 32 12 50 388571 246953 627554 4.777087 4.976995 3.913853 0.562183 0.461834 0.358403 Taylor Georgia 1326913269 13 269 13269 15.164152 25.903380 14.727269 6 6 8 39567 23163 54321 4.064555 6.054323 5.465116 2.439774 2.396404 2.206930 Peach Georgia 1322513225 13 225 13225 15.991471 16.916753 9.093094 15 10 14 93800 59113 153963 5.802087 5.637201 4.677199 2.033021 1.831894 1.573463 Houston Georgia 1315313153 13 153 13153 6.807678 9.506758 8.553431 27 24 56 396611 252452 654708 5.238009 5.109191 4.700373 -0.549791 -0.447774 -0.368629 Muscogee Georgia 1321513215 13 215 13215 15.084969 15.131221 12.477725 130 81 160 861785 535317 1282285 5.072788 3.358564 4.951852 1.074347 1.158498 1.135739 Marion Georgia 1319713197 13 197 13197 14.999813 0.000000 4.859559 4 0 2 26667 16704 41156 1.915125 2.609446 5.247272 2.470440 2.394207 2.219671
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[{"13089": 15.537506, "13085": 6.849127, "13241": 10.719135, "13169": 6.071973, "13247": 3.912564, "13009": 7.75508, "01111": 14.900592, "01121": 12.955071, "47139": 11.315708, "01019": 7.141072, "01123": 16.740056, "13157": 7.679208, "13319": 17.912257, "13151": 5.803169, "01015": 13.74356, "13097": 5.854757, "13317": 9.409867, "13311": 3.08366, "13159": 9.830747, "13015": 5.801936, "13013": 11.544473, "13011": 2.671012, "13255": 13.049018, "13257": 7.717515, "01017": 16.584451, "13153": 8.553431, "13313": 5.908183, "13141": 12.701034, "13143": 6.360271, "13145": 9.933522, "13147": 3.555556, "13149": 4.761073, "13021": 18.709826, "01081": 7.967442, "13221": 12.608574, "13223": 5.285707, "13225": 9.093094, "13227": 7.48524, "37039": 7.598889, "13135": 3.872291, "13137": 2.488342, "13133": 16.330911, "13035": 17.363015, "13231": 6.744271, "13139": 9.89328, "13237": 14.382281, "01027": 7.488073, "13289": 17.490417, "13285": 12.843889, "01029": 16.558485, "13281": 4.028928, "13207": 9.576404, "45073": 7.255753, "13123": 4.946039, "13121": 29.370922, "13045": 8.870924, "13129": 7.435555, "01055": 10.366579, "13291": 4.434049, "13293": 5.933438, "13295": 5.537778, "13297": 8.217715, "13211": 9.6302, "13199": 18.911337, "13213": 4.127222, "13215": 12.477725, "13217": 9.458859, "13219": 5.287129, "13197": 4.859559, "13195": 11.016427, "13113": 3.305901, "13111": 8.647302, "13059": 10.64535, "13117": 6.476994, "13115": 10.577148, "13119": 8.306545, "13057": 2.985283, "13055": 8.886688, "13187": 8.350421, "01049": 8.929551, "13067": 5.535022, "13063": 10.144222, "13265": 23.228804, "13263": 17.218001, "13105": 18.739787, "13269": 14.727269, "13233": 11.23516, "13077": 7.017117, "13079": 6.076349, "13171": 7.464119}]
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<style>
.legend {
padding: 0px 0px;
font: 10px sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.key path {
display: none;
}
</style>
</head>
<body>
<div id="map" style="width: 960px; height: 500px"></div>
<script>
queue()
.defer(d3.json, 'data.json')
.defer(d3.json, 'atl_hom.json')
.await(makeMap)
function makeMap(error, data_1,gjson_1) {
function matchKey(datapoint, key_variable){
return(parseFloat(key_variable[0][datapoint]));
};
var color = d3.scale.threshold()
.domain([2.0, 9.0, 10.0, 20.0, 20.0])
.range(['#FFFFCC', '#D9F0A3', '#ADDD8E', '#78C679', '#41AB5D', '#238443']);
var map = L.map('map').setView([33.755, -84.39], 7);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data (c) <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
}).addTo(map);
function style_1(feature) {
return {
fillColor: color(matchKey(feature.properties.FIPS, data_1)),
weight: 1,
opacity: 0.2,
color: 'black',
fillOpacity: 0.7
};
}
gJson_layer_1 = L.geoJson(gjson_1, {style: style_1}).addTo(map)
var legend = L.control({position: 'topright'});
legend.onAdd = function (map) {var div = L.DomUtil.create('div', 'legend'); return div};
legend.addTo(map);
var x = d3.scale.linear()
.domain([0, 22])
.range([0, 400]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("top")
.tickSize(1)
.tickValues(color.domain())
var svg = d3.select(".legend.leaflet-control").append("svg")
.attr("id", 'legend')
.attr("width", 450)
.attr("height", 40);
var g = svg.append("g")
.attr("class", "key")
.attr("transform", "translate(25,16)");
g.selectAll("rect")
.data(color.range().map(function(d, i) {
return {
x0: i ? x(color.domain()[i - 1]) : x.range()[0],
x1: i < color.domain().length ? x(color.domain()[i]) : x.range()[1],
z: d
};
}))
.enter().append("rect")
.attr("height", 10)
.attr("x", function(d) { return d.x0; })
.attr("width", function(d) { return d.x1 - d.x0; })
.style("fill", function(d) { return d.z; });
g.call(xAxis).append("text")
.attr("class", "caption")
.attr("y", 21)
.text('Homicide Rate HR8995');
};
</script>
</body>
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<style>
.legend {
padding: 0px 0px;
font: 10px sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.key path {
display: none;
}
</style>
</head>
<body>
<div id="map" style="width: 960px; height: 500px"></div>
<script>
queue()
.defer(d3.json, 'data.json')
.defer(d3.json, 'atl_hom.json')
.await(makeMap)
function makeMap(error, data_1,gjson_1) {
function matchKey(datapoint, key_variable){
return(parseFloat(key_variable[0][datapoint]));
};
var color = d3.scale.threshold()
.domain([12.011099, 18.3110415, 21.0700705, 26.299863000000002])
.range(['#FFFFCC', '#D9F0A3', '#ADDD8E', '#78C679', '#41AB5D']);
var map = L.map('map').setView([33.755, -84.39], 7);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data (c) <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
}).addTo(map);
function style_1(feature) {
return {
fillColor: color(matchKey(feature.properties.FIPS, data_1)),
weight: 1,
opacity: 0.2,
color: 'black',
fillOpacity: 0.7
};
}
gJson_layer_1 = L.geoJson(gjson_1, {style: style_1}).addTo(map)
var legend = L.control({position: 'topright'});
legend.onAdd = function (map) {var div = L.DomUtil.create('div', 'legend'); return div};
legend.addTo(map);
var x = d3.scale.linear()
.domain([0, 28])
.range([0, 400]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("top")
.tickSize(1)
.tickValues(color.domain())
var svg = d3.select(".legend.leaflet-control").append("svg")
.attr("id", 'legend')
.attr("width", 450)
.attr("height", 40);
var g = svg.append("g")
.attr("class", "key")
.attr("transform", "translate(25,16)");
g.selectAll("rect")
.data(color.range().map(function(d, i) {
return {
x0: i ? x(color.domain()[i - 1]) : x.range()[0],
x1: i < color.domain().length ? x(color.domain()[i]) : x.range()[1],
z: d
};
}))
.enter().append("rect")
.attr("height", 10)
.attr("x", function(d) { return d.x0; })
.attr("width", function(d) { return d.x1 - d.x0; })
.style("fill", function(d) { return d.z; });
g.call(xAxis).append("text")
.attr("class", "caption")
.attr("y", 21)
.text('Homicide Rate HR8995 (Maximum Breaks)');
};
</script>
</body>
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<style>
.legend {
padding: 0px 0px;
font: 10px sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.key path {
display: none;
}
</style>
</head>
<body>
<div id="map" style="width: 960px; height: 500px"></div>
<script>
queue()
.defer(d3.json, 'data.json')
.defer(d3.json, 'atl_hom.json')
.await(makeMap)
function makeMap(error, data_1,gjson_1) {
function matchKey(datapoint, key_variable){
return(parseFloat(key_variable[0][datapoint]));
};
var color = d3.scale.threshold()
.domain([5.7491044, 7.5545626, 9.7104188, 13.187926400000002])
.range(['#FFFFCC', '#D9F0A3', '#ADDD8E', '#78C679', '#41AB5D']);
var map = L.map('map').setView([33.755, -84.39], 7);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data (c) <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
}).addTo(map);
function style_1(feature) {
return {
fillColor: color(matchKey(feature.properties.FIPS, data_1)),
weight: 1,
opacity: 0.2,
color: 'black',
fillOpacity: 0.7
};
}
gJson_layer_1 = L.geoJson(gjson_1, {style: style_1}).addTo(map)
var legend = L.control({position: 'topright'});
legend.onAdd = function (map) {var div = L.DomUtil.create('div', 'legend'); return div};
legend.addTo(map);
var x = d3.scale.linear()
.domain([0, 14])
.range([0, 400]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("top")
.tickSize(1)
.tickValues(color.domain())
var svg = d3.select(".legend.leaflet-control").append("svg")
.attr("id", 'legend')
.attr("width", 450)
.attr("height", 40);
var g = svg.append("g")
.attr("class", "key")
.attr("transform", "translate(25,16)");
g.selectAll("rect")
.data(color.range().map(function(d, i) {
return {
x0: i ? x(color.domain()[i - 1]) : x.range()[0],
x1: i < color.domain().length ? x(color.domain()[i]) : x.range()[1],
z: d
};
}))
.enter().append("rect")
.attr("height", 10)
.attr("x", function(d) { return d.x0; })
.attr("width", function(d) { return d.x1 - d.x0; })
.style("fill", function(d) { return d.z; });
g.call(xAxis).append("text")
.attr("class", "caption")
.attr("y", 21)
.text('Homicide Rate HR8995 (Quintiles)');
};
</script>
</body>
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<style>
.legend {
padding: 0px 0px;
font: 10px sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.key path {
display: none;
}
</style>
</head>
<body>
<div id="map" style="width: 960px; height: 500px"></div>
<script>
queue()
.defer(d3.json, 'data.json')
.defer(d3.json, 'atl_hom.json')
.await(makeMap)
function makeMap(error, data_1,gjson_1) {
function matchKey(datapoint, key_variable){
return(parseFloat(key_variable[0][datapoint]));
};
var color = d3.scale.threshold()
.domain([6.4769940000000004, 9.933522, 13.74356, 18.911337])
.range(['#FFFFCC', '#D9F0A3', '#ADDD8E', '#78C679', '#41AB5D']);
var map = L.map('map').setView([33.755, -84.39], 7);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data (c) <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
}).addTo(map);
function style_1(feature) {
return {
fillColor: color(matchKey(feature.properties.FIPS, data_1)),
weight: 1,
opacity: 0.2,
color: 'black',
fillOpacity: 0.7
};
}
gJson_layer_1 = L.geoJson(gjson_1, {style: style_1}).addTo(map)
var legend = L.control({position: 'topright'});
legend.onAdd = function (map) {var div = L.DomUtil.create('div', 'legend'); return div};
legend.addTo(map);
var x = d3.scale.linear()
.domain([0, 20])
.range([0, 400]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("top")
.tickSize(1)
.tickValues(color.domain())
var svg = d3.select(".legend.leaflet-control").append("svg")
.attr("id", 'legend')
.attr("width", 450)
.attr("height", 40);
var g = svg.append("g")
.attr("class", "key")
.attr("transform", "translate(25,16)");
g.selectAll("rect")
.data(color.range().map(function(d, i) {
return {
x0: i ? x(color.domain()[i - 1]) : x.range()[0],
x1: i < color.domain().length ? x(color.domain()[i]) : x.range()[1],
z: d
};
}))
.enter().append("rect")
.attr("height", 10)
.attr("x", function(d) { return d.x0; })
.attr("width", function(d) { return d.x1 - d.x0; })
.style("fill", function(d) { return d.z; });
g.call(xAxis).append("text")
.attr("class", "caption")
.attr("y", 21)
.text('Homicide Rate HR8995 (Fisher Jenks)');
};
</script>
</body>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment