一、行政区边线绘制
步骤:1、获取行政区边线点的经纬度数据,越多越精确。2、python调用folium模块进行绘制
1、获取行政区边线点的经纬度数据
(1)网页搜索“高德地图API”,进入官网(高德开放平台 | 高德地图API (amap.com)),找到网页上方开发支持,点击web服务API,进入后在网页左侧找到“行政区域查询”并点击进入。
网页界面如下
将网页拉至最下面找到“服务示例”,在参数keywords的值中输入要绘制的行政区名称如历城区。在参数extensions的值中输入值“all”。点击运行。
点击运行结果中“districts”左边的加号,再点击“0”左边的加号,所显示的结果中,“polyline”后对应的数据即为所查找区域边界点的经纬度坐标。
注:若不确定所查找的区域是否在全国范围内有重名的,可以百度查找所要查找区域的"citycode",济南市历城区的"citycode"为0531,与查找结果一致。若有重名,点击“districts”的加号后出现的不止有“0”,需自行对应"citycode"值找到要找的结果。
(2)数据处理
python中定义一个变量a,将上述结果双引号中的所有值以字符串形式赋予a
a='117.130703,36.592404;117.131943,36.592259;117.133876,36.593159;117.138164,36.597533;117.138757,36.598603;117.138998,36.604235;117.13872,36.608435;117.138387,36.608925;117.139201,36.611973;117.138786,36.615641;117.139996,36.61942;117.142819,36.621264;117.143592,36.621488;117.146414,36.621987;117.147212,36.622422;117.14724,36.623519;117.146644,36.623714;117.146145,36.624235;117.140203,36.626076;117.136834,36.62772;117.135579,36.629563;117.135484,36.631016;117.134075,36.631854;117.134046,36.633264;117.134558,36.633713;117.134418,36.634462;117.135513,36.634789;117.134796,36.635083;117.134765,36.636604;117.135473,36.637241;117.13484,36.638834;117.134946,36.642615;117.135011,36.644757;117.134571,36.646435;117.134946,36.648071;117.138408,36.649344;117.138433,36.649354;117.137443,36.64992;117.13829,36.651504;117.138057,36.651558;117.136985,36.651652;117.134519,36.651737;117.135016,36.652833;117.135202,36.653773;117.135269,36.654488;117.135278,36.655341;117.137167,36.655309;117.137183,36.656126;117.137194,36.657133;117.137194,36.657477;117.137215,36.65851;117.137613,36.658915;117.137619,36.658918;117.137565,36.659581;117.140499,36.660542;117.141904,36.661007;117.142019,36.661118;117.142025,36.661244;117.141903,36.66127;117.141887,36.66142;117.136486,36.668305;117.136337,36.668809;117.137374,36.669229;117.138266,36.669656;117.137935,36.670169;117.138129,36.670405;117.138429,36.670662;117.138729,36.670934;117.138962,36.671432;117.139846,36.671248;117.140231,36.671359;117.140516,36.671436;117.140473,36.671806;117.140404,36.672382;117.14105,36.672267;117.141659,36.671299;117.141981,36.670567;117.143384,36.670891;117.14431,36.67068;117.14506,36.670558;117.145053,36.669181;117.145738,36.669174;117.145807,36.66842;117.146012,36.667879;117.149294,36.668489;117.149404,36.66768;117.151213,36.667927;117.151429,36.666984;117.153171,36.667201;117.153572,36.667249;117.153835,36.66728;117.154146,36.667315;117.154408,36.666129;117.154467,36.665819;117.155566,36.666059;117.155581,36.666059;117.155951,36.665819;117.156203,36.665663;117.15659,36.665421;117.156622,36.665104;117.156783,36.665035;117.157266,36.665095;117.157882,36.665505;117.158166,36.665698;117.158493,36.665728;117.158815,36.665753;117.15903,36.665771;117.159219,36.664724;117.159491,36.664773;117.161901,36.665164;117.162348,36.664656;117.163281,36.663593;117.164435,36.662251;117.164467,36.661122;117.165755,36.660881;117.167212,36.659233;117.17039,36.659036;117.172461,36.658007;117.174719,36.658739;117.176007,36.658837;117.179366,36.659081;117.180644,36.661177;117.179636,36.662786;117.179861,36.663638;117.177554,36.664206;117.177565,36.664817;117.177479,36.666547;117.176695,36.666529;117.176673,36.667114;117.176566,36.667519;117.176567,36.667525;117.176437,36.668431;117.176887,36.668782;117.176975,36.668827;117.175462,36.669111;117.175441,36.670462;117.17442,36.670477;117.174356,36.670891;117.174028,36.670955;117.17354,36.671047;117.173079,36.67114;117.172446,36.671923;117.172227,36.672384;117.171924,36.673997;117.171905,36.6741;117.171602,36.675715;117.172908,36.67582;117.173136,36.677376;117.173295,36.678239;117.173045,36.678374;117.172995,36.679305;117.173006,36.680037;117.171836,36.680801;117.171739,36.681137;117.171622,36.681491;117.170946,36.681447;117.171053,36.680776;117.170668,36.680656;117.170496,36.680191;117.16997,36.680182;117.170045,36.680663;117.170335,36.680734;117.170495,36.6823;117.170011,36.682423;117.168468,36.682041;117.167898,36.683644;117.16887,36.685306;117.169146,36.685772;117.169353,36.686124;117.170046,36.687632;117.168892,36.688473;117.168639,36.688657;117.168618,36.689956;117.168665,36.691026;117.169744,36.690989;117.169798,36.691377;117.170134,36.691471;117.169872,36.692123;117.169871,36.692129;117.169909,36.693619;117.169957,36.695332;117.166887,36.69697;117.166297,36.697684;117.165832,36.69825;117.167222,36.708086;117.164304,36.708147;117.164324,36.707458;117.16426,36.706513;117.163244,36.706513;117.163176,36.706254;117.163012,36.705958;117.162781,36.705576;117.163446,36.705531;117.163489,36.705351;117.163141,36.705364;117.162781,36.704766;117.16336,36.704799;117.163379,36.703792;117.163329,36.701865;117.163623,36.701129;117.162167,36.701163;117.160996,36.701203;117.159847,36.701228;117.159865,36.701776;117.159811,36.702751;117.159796,36.702882;117.159786,36.70293;117.159055,36.70417;117.158894,36.704491;117.158753,36.706134;117.156069,36.706095;117.156419,36.704181;117.155661,36.704146;117.155654,36.704147;117.15578,36.702144;117.155818,36.701034;117.156696,36.700114;117.156248,36.699458;117.156106,36.699987;117.155686,36.700082;117.155732,36.701384;117.155729,36.701389;117.155376,36.701571;117.155086,36.701424;117.155466,36.699323;117.155701,36.698916;117.155086,36.698481;117.154672,36.698251;117.154206,36.69829;117.153981,36.698239;117.153684,36.698168;117.152951,36.698017;117.152726,36.697862;117.152639,36.697613;117.151974,36.697639;117.152033,36.696057;117.150343,36.695107;117.150257,36.696134;117.150717,36.696147;117.150706,36.697292;117.151254,36.69739;117.151227,36.69764;117.151147,36.698568;117.151049,36.700596;117.150835,36.700685;117.150649,36.70026;117.150632,36.699661;117.150799,36.698287;117.150311,36.698225;117.150031,36.698939;117.149776,36.699224;117.149454,36.700682;117.149525,36.701125;117.149016,36.701211;117.148668,36.701422;117.148636,36.702354;117.149359,36.70248;117.149841,36.702484;117.149837,36.702837;117.149301,36.702716;117.149294,36.702719;117.149258,36.70281;117.149059,36.702771;117.149086,36.702672;117.148221,36.702498;117.148251,36.702716;117.148146,36.704023;117.146133,36.704002;117.146122,36.703882;117.145429,36.703747;117.144699,36.70598;117.144092,36.707071;117.143459,36.707706;117.142349,36.708264;117.140928,36.708266;117.12954,36.706972;117.126383,36.706579;117.124162,36.70682;117.111108,36.707617;117.108182,36.707618;117.106202,36.70738;117.102163,36.70655;117.101467,36.706874;117.100304,36.706579;117.101008,36.702747;117.100985,36.702558;117.100703,36.700212;117.100391,36.698105;117.100375,36.697719;117.100314,36.696622;117.10037,36.694947;117.100395,36.69445;117.100066,36.694485;117.100056,36.694485;117.09984,36.694356;117.099676,36.694221;117.099669,36.694218;117.099334,36.694136;117.099342,36.693616;117.099333,36.69362;117.098819,36.693646;117.098549,36.693622;117.098214,36.693614;117.098113,36.694433;117.097817,36.694375;117.097074,36.694366;117.096996,36.694844;117.096574,36.694561;117.096593,36.693873;117.095663,36.69382;117.095587,36.694158;117.094173,36.693776;117.093855,36.693728;117.093871,36.692846;117.093792,36.692747;117.093622,36.692758;117.093241,36.692788;117.092481,36.69284;117.092165,36.692928;117.091972,36.692971;117.091365,36.693106;117.090174,36.69353;117.090364,36.692271;117.089145,36.692117;117.089204,36.690844;117.090647,36.690976;117.090691,36.690174;117.090759,36.689664;117.090441,36.689453;117.090475,36.689251;117.090523,36.689015;117.090603,36.688727;117.090501,36.688466;117.090508,36.688463;117.091059,36.688394;117.090914,36.687652;117.090887,36.687472;117.090868,36.68688;117.090501,36.686586;117.089841,36.685953;117.09053,36.685931;117.090496,36.685701;117.090508,36.685441;117.089872,36.685423;117.08984,36.685417;117.089024,36.685439;117.088981,36.685551;117.088194,36.685426;117.088238,36.684945;117.089595,36.684961;117.089631,36.682803;117.091204,36.682707;117.093003,36.682649;117.093035,36.680632;117.093025,36.679615;117.092996,36.679353;117.093032,36.679129;117.09227,36.679159;117.092263,36.67916;117.091814,36.679383;117.091801,36.679392;117.090307,36.679396;117.090299,36.679392;117.089547,36.68007;117.089556,36.680671;117.087274,36.680567;117.087263,36.680567;117.085738,36.680538;117.084987,36.679013;117.084909,36.678137;117.084896,36.676745;117.084826,36.674344;117.084894,36.674194;117.08362,36.673637;117.082297,36.673043;117.080548,36.672237;117.080483,36.672317;117.080578,36.672469;117.080455,36.672488;117.08039,36.673054;117.080369,36.673675;117.079806,36.673662;117.07933,36.673482;117.078658,36.673124;117.078658,36.672948;117.078659,36.672937;117.078942,36.672771;117.079646,36.671834;117.07854,36.671119;117.078557,36.670923;117.078582,36.670582;117.07859,36.670466;117.078595,36.670458;117.078646,36.669011;117.078023,36.668564;117.077072,36.668506;117.076099,36.668446;117.076091,36.668446;117.07579,36.668149;117.075786,36.668136;117.075533,36.667788;117.075528,36.667779;117.075468,36.667538;117.075476,36.667113;117.075378,36.666945;117.075211,36.666686;117.075206,36.666678;117.075027,36.666342;117.073959,36.666347;117.073934,36.667097;117.073896,36.667538;117.073763,36.667647;117.073339,36.667955;117.071431,36.66818;117.071232,36.667412;117.071071,36.666745;117.070568,36.666758;117.070787,36.668324;117.069827,36.668436;117.068796,36.668606;117.068781,36.669294;117.068708,36.669619;117.067701,36.669616;117.067709,36.66945;117.066715,36.66944;117.066108,36.669447;117.06592,36.669381;117.064964,36.669376;117.064978,36.669055;117.064907,36.669066;117.063984,36.669329;117.063975,36.669332;117.064082,36.669654;117.063834,36.669672;117.063831,36.66968;117.063825,36.670007;117.063814,36.670007;117.062488,36.670051;117.062469,36.669747;117.062466,36.669736;117.061952,36.669733;117.061377,36.669745;117.061361,36.669745;117.058438,36.669732;117.058447,36.669887;117.058436,36.669893;117.058198,36.670009;117.058195,36.670003;117.057985,36.670003;117.057874,36.670491;117.057862,36.670546;117.057862,36.670554;117.057508,36.670731;117.057503,36.670731;117.05681,36.670791;117.056805,36.670787;117.056773,36.671071;117.056043,36.671109;117.055978,36.671791;117.055975,36.671999;117.055967,36.672239;117.055962,36.672428;117.055936,36.673091;117.055216,36.67303;117.054664,36.673011;117.054654,36.67301;117.054642,36.673136;117.054638,36.673143;117.054134,36.673134;117.054145,36.673496;117.053976,36.673632;117.053803,36.674776;117.05433,36.674866;117.054132,36.675816;117.054648,36.675856;117.054662,36.67586;117.054812,36.67456;117.055086,36.674597;117.055122,36.674396;117.055906,36.67444;117.056016,36.674973;117.056016,36.676656;117.056011,36.678108;117.056011,36.679138;117.05596,36.679312;117.055955,36.679326;117.055952,36.679338;117.055619,36.680483;117.054955,36.68209;117.054939,36.682104;117.054942,36.682121;117.053323,36.686042;117.053319,36.686059;117.053311,36.686072;117.052847,36.687213;117.052638,36.687618;117.052744,36.687761;117.052401,36.688144;117.052132,36.688089;117.052003,36.6883;117.051842,36.68827;117.051772,36.688403;117.052112,36.688787;117.052924,36.689728;117.053181,36.690025;117.054223,36.691849;117.054232,36.691866;117.054114,36.69254;117.054114,36.692864;117.052631,36.693218;117.052366,36.693281;117.051984,36.692853;117.05153,36.692431;117.050914,36.693314;117.05027,36.694131;117.049831,36.69386;117.049744,36.693826;117.048412,36.693498;117.048871,36.694088;117.048333,36.695238;117.047918,36.695939;117.047237,36.697517;117.047953,36.697884;117.049347,36.698482;117.050522,36.699511;117.050731,36.699627;117.050994,36.699369;117.051337,36.700083;117.051539,36.699497;117.052314,36.699864;117.051687,36.70051;117.052187,36.700987;117.052556,36.701473;117.052999,36.701639;117.053756,36.700331;117.053858,36.700318;117.054193,36.700614;117.054664,36.701805;117.054901,36.702425;117.054899,36.702471;117.054928,36.702495;117.055143,36.703052;117.055465,36.703409;117.056135,36.703845;117.05725,36.704521;117.058243,36.705434;117.059192,36.706383;117.060106,36.707019;117.061299,36.707772;117.06237,36.708569;117.064189,36.70948;117.064468,36.70988;117.064468,36.710197;117.064276,36.710471;117.063554,36.710591;117.063162,36.710946;117.062292,36.71233;117.061769,36.712646;117.061177,36.712645;117.060307,36.712049;117.059784,36.711652;117.059706,36.711257;117.060028,36.710662;117.06062,36.709356;117.06062,36.708805;117.060306,36.708487;117.059035,36.707768;117.057921,36.70741;117.057529,36.707609;117.057325,36.707834;117.057313,36.707847;117.057299,36.707863;117.057207,36.707964;117.057187,36.708009;117.057179,36.708039;117.057153,36.708081;117.056258,36.71006;117.0555,36.710949;117.054786,36.711264;117.053916,36.711384;117.052522,36.711381;117.050223,36.711849;117.047836,36.712834;117.047166,36.713306;117.046852,36.713744;117.046765,36.714217;117.046451,36.714494;117.04538,36.714731;117.044265,36.714806;117.043794,36.714805;117.043315,36.714626;117.042357,36.714107;117.040927,36.713312;117.040292,36.713311;117.039342,36.713864;117.038392,36.714018;117.035368,36.713854;117.034976,36.713453;117.034976,36.711558;117.034985,36.711529;117.034976,36.711519;117.034976,36.710682;117.034622,36.710333;117.034611,36.710277;117.034575,36.710286;117.032989,36.710282;117.032353,36.710519;117.032196,36.710835;117.03208,36.712116;117.032114,36.712149;117.032074,36.712176;117.031795,36.715269;117.03156,36.716849;117.031002,36.717799;117.029416,36.719614;117.027186,36.722144;117.027029,36.722934;117.027186,36.724124;117.027822,36.725868;117.028615,36.727451;117.028616,36.728324;117.027431,36.729906;117.026163,36.731472;117.026061,36.731955;117.025923,36.73224;117.025104,36.733158;117.021992,36.738301;117.020501,36.741588;117.02046,36.743249;117.020873,36.746023;117.022051,36.747778;117.023159,36.749647;117.024489,36.751161;117.026706,36.753033;117.028036,36.754014;117.029366,36.754728;117.032025,36.755535;117.035459,36.756076;117.03978,36.756353;117.050522,36.756642;117.052183,36.75709;117.054288,36.757982;117.057942,36.760654;117.063368,36.764038;117.06753,36.766481;117.074425,36.76987;117.081601,36.77373;117.082657,36.775899;117.083184,36.779159;117.083739,36.781292;117.084439,36.782789;117.084726,36.782936;117.086494,36.784452;117.091819,36.787637;117.095983,36.789243;117.100125,36.790061;117.105602,36.790899;117.111023,36.790969;117.114059,36.791877;117.115127,36.792376;117.115928,36.793019;117.117532,36.795021;117.119404,36.797953;117.12226,36.804605;117.123153,36.806965;117.126718,36.812542;117.130105,36.817545;117.132333,36.821119;117.134383,36.823763;117.138478,36.827691;117.141343,36.829922;117.147516,36.834224;117.148492,36.836731;117.146764,36.843788;117.146144,36.850239;117.147049,36.855655;117.148484,36.858078;117.150415,36.860277;117.151572,36.860795;117.15365,36.860911;117.158424,36.860749;117.161827,36.86098;117.165293,36.861399;117.166893,36.861823;117.169385,36.863533;117.171077,36.865389;117.172059,36.867175;117.176172,36.878256;117.182332,36.89026;117.183469,36.892266;117.183561,36.891603;117.185804,36.888428;117.207157,36.8883;117.211041,36.883204;117.210615,36.876103;117.209054,36.869478;117.209521,36.86466;117.219431,36.861311;117.225414,36.861226;117.231391,36.861146;117.24025,36.862169;117.247706,36.863899;117.254878,36.865639;117.262799,36.862326;117.266688,36.855628;117.268009,36.856381;117.269472,36.857552;117.271791,36.858634;117.273177,36.858897;117.274861,36.859924;117.281537,36.863447;117.295911,36.872239;117.300282,36.874811;117.302581,36.875939;117.307949,36.878865;117.309699,36.879501;117.311081,36.879895;117.320251,36.882689;117.320773,36.881755;117.321074,36.872259;117.328179,36.872966;117.328434,36.877429;117.329249,36.877724;117.331705,36.876789;117.332062,36.872821;117.331369,36.866216;117.328813,36.86388;117.328626,36.858703;117.328385,36.858062;117.327506,36.857677;117.328009,36.856088;117.331656,36.855426;117.333942,36.84998;117.336406,36.850377;117.336946,36.850862;117.337123,36.851261;117.339613,36.851486;117.338773,36.847148;117.335785,36.846806;117.336269,36.843729;117.338732,36.843975;117.338905,36.843166;117.339121,36.843184;117.339881,36.843249;117.341143,36.843014;117.345636,36.839483;117.34728,36.832454;117.347418,36.831733;117.34771,36.82745;117.348446,36.824955;117.348149,36.816389;117.347758,36.816164;117.346758,36.807864;117.344183,36.806452;117.341846,36.805819;117.338344,36.807815;117.335965,36.807823;117.336403,36.805957;117.331544,36.801474;117.330888,36.797511;117.328366,36.796834;117.328399,36.796258;117.32841,36.794583;117.32842,36.79313;117.322524,36.791424;117.31423,36.789074;117.314303,36.787585;117.314189,36.786738;117.316834,36.785889;117.318869,36.785008;117.32044,36.784238;117.323978,36.783799;117.326,36.783576;117.328851,36.783491;117.328851,36.780801;117.332799,36.780527;117.332791,36.780221;117.332761,36.779142;117.332747,36.778609;117.332574,36.775627;117.332576,36.772391;117.332486,36.769345;117.33281,36.767298;117.334024,36.766319;117.335437,36.765679;117.335784,36.765442;117.336256,36.765467;117.336534,36.765018;117.33644,36.763991;117.336621,36.761817;117.336856,36.761619;117.337303,36.761499;117.338854,36.761274;117.33956,36.761012;117.340324,36.760966;117.340604,36.760822;117.340659,36.760587;117.340272,36.75956;117.340123,36.758757;117.340395,36.758333;117.340406,36.758316;117.340287,36.75406;117.340454,36.753569;117.341218,36.75363;117.341394,36.753262;117.342261,36.748077;117.342205,36.747811;117.342273,36.747578;117.342548,36.747561;117.343039,36.747766;117.343336,36.747737;117.343767,36.747045;117.344166,36.746751;117.345994,36.746943;117.347023,36.746934;117.347155,36.745784;117.34693,36.744875;117.34639,36.744488;117.344306,36.744235;117.341671,36.744237;117.34127,36.743917;117.341663,36.742354;117.343808,36.740889;117.344136,36.740103;117.343996,36.739748;117.343293,36.739804;117.342026,36.740359;117.341943,36.740353;117.344537,36.733225;117.349793,36.725829;117.356475,36.718184;117.360581,36.710339;117.36152,36.701164;117.362467,36.692674;117.363476,36.686701;117.366955,36.676804;117.372425,36.666193;117.375598,36.655614;117.375719,36.648053;117.374162,36.64234;117.370082,36.638039;117.36367,36.631937;117.360703,36.626699;117.360798,36.617996;117.362676,36.612927;117.362736,36.602843;117.362508,36.598704;117.361887,36.598202;117.360246,36.597331;117.357378,36.596899;117.352915,36.597503;117.351042,36.597181;117.351609,36.593695;117.354054,36.590151;117.356059,36.588578;117.357769,36.581364;117.35779,36.579711;117.356525,36.579517;117.355723,36.578647;117.349478,36.575038;117.343174,36.572947;117.342842,36.571864;117.344099,36.567123;117.340205,36.564939;117.336349,36.562913;117.333296,36.561897;117.331491,36.562192;117.330592,36.563542;117.329109,36.564152;117.327934,36.564194;117.325566,36.563167;117.324004,36.560996;117.329628,36.559983;117.329387,36.558535;117.333519,36.553056;117.325428,36.547429;117.319645,36.541814;117.317283,36.539918;117.314722,36.538196;117.313028,36.533473;117.313187,36.531901;117.313972,36.531408;117.317326,36.532025;117.315327,36.529912;117.314939,36.528933;117.31675,36.528382;117.318109,36.528602;117.319343,36.529552;117.319451,36.525633;117.318673,36.521585;117.319458,36.519704;117.328314,36.51931;117.332639,36.516503;117.332807,36.511736;117.331428,36.509383;117.326123,36.507499;117.325624,36.505505;117.325322,36.503765;117.32401,36.502788;117.318374,36.5048;117.316303,36.505181;117.315856,36.504901;117.315642,36.503369;117.317813,36.50085;117.312584,36.494872;117.310908,36.493223;117.309772,36.492986;117.307681,36.49373;117.305517,36.493352;117.307009,36.492226;117.309649,36.491949;117.309403,36.486967;117.313258,36.48526;117.311328,36.479337;117.307716,36.475817;117.30621,36.472405;117.304148,36.472335;117.30219,36.473521;117.300592,36.473008;117.299376,36.473112;117.296382,36.473692;117.29502,36.474613;117.292299,36.475906;117.288208,36.476049;117.28824,36.475166;117.289698,36.472935;117.288978,36.468716;117.286644,36.465308;117.282901,36.461304;117.280278,36.460055;117.27765,36.455622;117.275795,36.451226;117.263841,36.449225;117.260772,36.445947;117.259071,36.442472;117.255198,36.441496;117.251741,36.438079;117.2497,36.436746;117.248106,36.433968;117.247801,36.429537;117.246533,36.427288;117.24541,36.423148;117.241762,36.417783;117.241507,36.416598;117.242106,36.415298;117.240668,36.413474;117.237688,36.411101;117.235839,36.411292;117.234138,36.412557;117.231377,36.412772;117.225238,36.410329;117.221462,36.407322;117.218315,36.406172;117.208751,36.405306;117.208091,36.401868;117.205313,36.398993;117.203235,36.398361;117.202693,36.396912;117.201957,36.391884;117.200939,36.389768;117.191659,36.378758;117.18974,36.377693;117.183673,36.37369;117.180976,36.372546;117.178713,36.367978;117.178836,36.365355;117.179714,36.364021;117.181503,36.363423;117.182958,36.360815;117.179626,36.353128;117.169416,36.351715;117.161389,36.351879;117.149427,36.346303;117.146724,36.345601;117.143764,36.346014;117.142554,36.345728;117.135485,36.339594;117.137029,36.335146;117.133871,36.334722;117.131995,36.334625;117.129851,36.335145;117.127789,36.336896;117.125392,36.338027;117.111723,36.340429;117.109588,36.339343;117.107329,36.338893;117.10688,36.339134;117.106647,36.339631;117.105567,36.340741;117.104721,36.341084;117.103629,36.341238;117.10325,36.341427;117.102063,36.341449;117.101221,36.341663;117.100664,36.341817;117.100141,36.342313;117.098447,36.342846;117.097968,36.343269;117.0975,36.343423;117.096843,36.344028;117.096085,36.34437;117.095457,36.34463;117.094853,36.34567;117.09323,36.346341;117.092749,36.346191;117.091818,36.345814;117.090134,36.34603;117.089632,36.346757;117.088727,36.346003;117.089164,36.341602;117.087694,36.33688;117.084459,36.335564;117.083834,36.33341;117.080892,36.330329;117.079695,36.330457;117.078185,36.331387;117.069819,36.341709;117.067117,36.340771;117.064998,36.340868;117.064684,36.343649;117.062035,36.34676;117.059354,36.34785;117.057042,36.346543;117.056186,36.346743;117.055193,36.347267;117.055125,36.348701;117.057604,36.351822;117.060584,36.352714;117.062102,36.354067;117.062451,36.355042;117.058984,36.357674;117.051312,36.361277;117.043404,36.364022;117.031729,36.365953;117.024433,36.365539;117.023657,36.365253;117.014925,36.365714;117.015739,36.367565;117.018465,36.370961;117.018155,36.372723;117.016601,36.375763;117.018312,36.378561;117.01755,36.380906;117.014598,36.382986;117.015114,36.384264;117.017275,36.385806;117.019384,36.392125;117.019307,36.392793;117.017223,36.393437;117.013517,36.399286;117.011352,36.40157;117.011039,36.410986;117.011508,36.415832;117.0099,36.419719;117.011129,36.422121;117.007989,36.425065;117.006774,36.425219;117.006121,36.425602;117.003235,36.428099;116.995275,36.431883;116.995142,36.433222;116.991856,36.437459;116.989815,36.439184;116.987214,36.440326;116.984053,36.441082;116.981212,36.441097;116.978829,36.440583;116.974397,36.440594;116.966161,36.442361;116.964317,36.44363;116.961547,36.4479;116.961313,36.449457;116.963309,36.450111;116.965638,36.451836;116.964399,36.466132;116.959906,36.470379;116.951416,36.477117;116.94888,36.478197;116.946021,36.477816;116.942293,36.478119;116.941003,36.478652;116.939536,36.479462;116.939682,36.48203;116.938291,36.48439;116.93369,36.485469;116.933406,36.489734;116.934113,36.49802;116.938418,36.499979;116.942998,36.499547;116.944406,36.501312;116.944647,36.50209;116.943839,36.505168;116.945237,36.508171;116.949593,36.511548;116.950099,36.511436;116.950733,36.510134;116.951753,36.511551;116.951799,36.51308;116.950877,36.515028;116.952039,36.5151;116.95633,36.517059;116.959258,36.519551;116.964391,36.521119;116.977257,36.518673;116.979896,36.518727;116.979999,36.521376;116.980919,36.521817;116.983549,36.521844;116.984678,36.51955;116.985376,36.519656;116.984891,36.523018;116.981655,36.526807;116.982327,36.528782;116.986194,36.532714;116.994746,36.535573;116.994283,36.536636;116.996395,36.538107;117.001757,36.539644;117.002797,36.539464;117.00744,36.541806;117.011449,36.542606;117.016077,36.545615;117.023016,36.546449;117.02378,36.545345;117.024412,36.545428;117.026929,36.549976;117.028692,36.554218;117.027324,36.554904;117.026788,36.555773;117.023293,36.560513;117.023299,36.560531;117.02384,36.560678;117.025983,36.560756;117.027217,36.562933;117.026836,36.563391;117.026836,36.563851;117.027352,36.56397;117.027689,36.564656;117.028306,36.565072;117.029024,36.566264;117.029114,36.566679;117.034428,36.563888;117.036532,36.563715;117.039879,36.569778;117.041023,36.572846;117.044461,36.575085;117.045616,36.575178;117.045546,36.572418;117.045636,36.571419;117.047045,36.570963;117.050257,36.57139;117.053488,36.568204;117.054596,36.567967;117.065324,36.570056;117.068029,36.572143;117.068201,36.572759;117.068588,36.573533;117.070084,36.573626;117.078528,36.572747;117.08067,36.570935;117.081131,36.56979;117.079991,36.566162;117.079103,36.565185;117.078615,36.560331;117.07894,36.559396;117.08253,36.560955;117.085461,36.558389;117.085559,36.556557;117.087007,36.552297;117.090024,36.551092;117.091139,36.550019;117.091486,36.547745;117.09912,36.540383;117.100537,36.539655;117.113244,36.536187;117.116915,36.538622;117.121872,36.54088;117.123026,36.542531;117.126917,36.543175;117.128834,36.542822;117.130846,36.540899;117.129814,36.540402;117.12965,36.538502;117.135364,36.537127;117.141234,36.539884;117.146905,36.540215;117.14935,36.540975;117.153453,36.540636;117.159913,36.545592;117.161777,36.550531;117.1607,36.552516;117.160447,36.554579;117.157697,36.555773;117.159413,36.560622;117.158272,36.566929;117.155534,36.568459;117.149992,36.567067;117.149804,36.565921;117.147218,36.565884;117.142254,36.567391;117.138692,36.575603;117.139646,36.576863;117.139511,36.577352;117.137042,36.579696;117.135572,36.578657;117.13482,36.578424;117.135118,36.581655;117.132013,36.584274;117.126096,36.586087;117.127631,36.59121;117.130703,36.592404'
对字符串进行分割,将每个点的经纬度以字符串形式存放在一个列表中。
b=a.split(';')
以字典形式作为过渡并最终以数组形式存放所有坐标点的数据。
c={}
for i in b:
b1=i.split(',')
c[b.index(i)]={'lat':float(b1[1]),'lng':float(b1[0])}
polyline_licheng=[]
for i in range(len(c)):
polyline_licheng.append([c[i]['lat'],c[i]['lng']])
2、python调用folium模块绘制
程序开头引入模块folium
import folium
根据上述数据绘图
m = folium.Map([36.700472,117.242344] #图片显示的中心点坐标
zoom_start=9, # 默认放大倍数
)
route = folium.PolyLine(
polyline_licheng, # 坐标点列表,列表内每个小列表元素先纬度再经度
weight=3, # 线宽
color='blue', # 线条颜色
opacity=0.8, # 透明度
).add_to(m)
m.save( '历城区.html') #网页存储,在对应文件夹内直接打开即可查看
效果图:
如需同时画多个行政区域,只需重复上述步骤,最后一块用m.save( '区域.html')保存即可。
同时画济南五个区的边界图如下:
二、网格化
网格化的步骤一个是用一个矩形把研究区域框起来,另一个是画横竖线分格。
首先是画矩形,画矩形需要知道矩形四个顶点的坐标,也就是需要知道所有边界点的经纬度组成的(最大经度,最大纬度),(最大经度,最小纬度),(最小经度,最小纬度)以及(最小经度,最大纬度)这四个点。因此我们需要先找出所有坐标中的最大和最小经纬度。
#寻找所有坐标点中最大的经度或纬度
def max(k): #k的值为 'lat' 或 'lng'
max1=0
for i in range(len(c)):
if c[i][k]>max1:
max1=c[i][k]
return max1
#寻找所有坐标点中最小的经度或纬度
def min(k):
min1=float('inf')
for i in range(len(c)):
if c[i][k]<min1:
min1=c[i][k]
return min1
longitude_max=max('lng')
latitude_max=max('lat')
longitude_min=min('lng')
latitude_min=min('lat')
接下来我们就可以把矩形画出来
rectangle=[[latitude_max,longitude_max],[latitude_max,longitude_min],[latitude_min,longitude_min],[latitude_min,longitude_max],[latitude_max,longitude_max]]
def draw_m(locations,weight,color,opacity):
route = folium.PolyLine(
locations,
weight=weight,
color=color,
opacity=opacity
).add_to(m)
draw_m(rectangle,3,'black',0.8)
第二步开始画线,以10×10的网格规模为例,画线其实画的是线段,只需知道每条线段两端的端点坐标即可。
def get_polygons(latitude_num,longitude_num):
latitude_step = (latitude_max - latitude_min)/latitude_num #每两条横线之间的间隔
longitude_step = (longitude_max - longitude_min)/longitude_num #每两条竖线之间的间隔
polygons = []
for i in range(latitude_num):
latitude_up = latitude_min + latitude_step * (i+1)
polygons.append([[latitude_up,longitude_max],[latitude_up,longitude_min]]) #横线两端坐标存储
for j in range(longitude_num):
longitude_left = longitude_max - longitude_step * (j+1)
polygons.append([[latitude_min,longitude_left],[latitude_max,longitude_left]]) #竖线两端坐标存储
return polygons
polygons = get_polygons(10,10)
for polygon in polygons:
draw_m(polygon,1,'black',0.8)
m.save( '历城区.html')
效果图如下:
同样,如果是同时画多个行政区域,只需要在本节开头的求最大最小经纬度函数里把对应的坐标点数据也加进去比较即可。
同时画五个区域的网格图如下:
如果需要判断某个点在哪一个网格当中,只需要计算出每个网格的经纬度范围即可,附代码如下。
def classify1(latitude_num,longitude_num):
latitude_step = (latitude_max - latitude_min)/latitude_num
longitude_step = (longitude_max - longitude_min)/longitude_num
classify={}
for i in range(latitude_num*longitude_num):
latminus=math.ceil((i+1)/longitude_num)
k=math.floor((i+1)/longitude_num)
lngplus=math.ceil((i+1)-k*longitude_num)
classify[(i+1)]={'lat':[latitude_max-latitude_step*(latminus-1),latitude_max-latitude_step*(latminus)],'lng':[longitude_min+longitude_step*(lngplus-1),longitude_min+longitude_step*(lngplus)]}
return classify
classify=classify1(10,10)
计算结果及储存格式如图,若需判断某个点在哪个单元格内,只需用if语句判断经纬度范围即可。
三、网页打开显示空白问题解决
本节是在写该文章时发现保存的文件打开时看不了图,网页显示一片空白,如下图显示,在网上搜索了一番之后找到了问题解决方法,如果有相同情况可按此方法解决。
首先在上面的空白页中鼠标单击右键,点击“查看页面源代码”,然后将所有代码复制粘贴到word。在word中选中全文,进行替换操作,将所有的“cdn”替换为“fastly”,然后复制全文,新建文本文档,将复制内容粘贴至此,点击另存为,文件名加后缀“.html”,保存后在存储位置打开即可。