经纬度查询所在省市(China Only)
By
money
at 2021-06-19 • 0人收藏 • 997人看过
import win; import console; import gdip; console.open(); //chinaArea.tab数据来源:https://geo.datav.aliyun.com/areas_v2/bound/100000_full.json var china = string.load("chinaArea.tab"); china = eval(china); //生成gdip path数组 function createProvinceRgns(){ var paths={}; for(h=1;#china.features;1){ var prov = china.features[h]; var pPath = gdip.assert2( gdip.CreatePath (0 ) ); for(i=1;#prov.geometry.coordinates;1){ var tab = prov.geometry.coordinates[i] if(prov.geometry.type=="MultiPolygon"){ for(j=1;#tab;1){ var tab1 = tab[j]; var pts={} for(k=1;#tab1;1){ var tab2 = tab1[k]; table.push(pts, tab2[1] , tab2[2]) } gdip.assert2( gdip.AddPathPolygon(pPath ,{ float points[] = pts }, #pts/2 ) ); } }else if(prov.geometry.type=="Polygon"){ var pts={} for(j=1;#tab;1){ var tab1 = tab[j]; table.push(pts, tab1[1], tab1[2]) } gdip.assert2( gdip.AddPathPolygon(pPath ,{ float points[] = pts }, #pts/2 ) ); } table.push(paths, {path=pPath; province=prov.properties.name}) } } return paths; } var paths = createProvinceRgns(); var IsVisiblePathPoint = ::Gdiplus.api("GdipIsVisiblePathPoint","int(PTR path, float x, float y, pointer graphics, bool &b)"); //只演示定位省,如需定位市,参考chinaArea.tab数据 var x = 110.322925; var y = 24.930706; for(i=1;#paths;1){ var tab = paths[i]; //console.dump(tab) var b=false; var ret,b = IsVisiblePathPoint(tab.path, x, y) if(b){ console.dump(tab.province) break } } win.loopMessage();
注意事项:坐标保持小数就好,如果坐标*1000000转成整数,数值太大会导致gdip函数卡死
1 个回复 | 最后更新于 2021-06-20
登录后方可回帖
感谢分享