|
|
@@ -0,0 +1,243 @@
|
|
|
+
|
|
|
+let fs = require('fs');
|
|
|
+let params = {
|
|
|
+ type: "FeatureCollection",
|
|
|
+ totalFeatures: 544,
|
|
|
+ features: [
|
|
|
+ ]
|
|
|
+}
|
|
|
+function writeJson(params){
|
|
|
+ //现将json文件读出来
|
|
|
+ fs.readFile('./person.json',function(err,data){
|
|
|
+ console.log('读取文件')
|
|
|
+ if(err){
|
|
|
+ return console.error(err);
|
|
|
+ }
|
|
|
+ console.log('读取文件成功')
|
|
|
+ let bangladesh = data.toString();//将二进制的数据转换为字符串
|
|
|
+ bangladesh = JSON.parse(bangladesh);//将字符串转换为json对象
|
|
|
+
|
|
|
+ let arr2 = [];
|
|
|
+ console.log('开始计算')
|
|
|
+ let i = 0;
|
|
|
+ // let cityName = [];
|
|
|
+ let provinceNameArr = ["Barisal", "Chittagong", "Rajshahi", "Rangpur", "Dhaka", "Sylhet", "Mymensingh", "Khulna"];
|
|
|
+ let provinceNameArrJSON = {
|
|
|
+ Barisal:{
|
|
|
+ type: "FeatureCollection",
|
|
|
+ totalFeatures: 544,
|
|
|
+ features: [
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ Chittagong:{
|
|
|
+ type: "FeatureCollection",
|
|
|
+ totalFeatures: 544,
|
|
|
+ features: [
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ Rajshahi:{
|
|
|
+ type: "FeatureCollection",
|
|
|
+ totalFeatures: 544,
|
|
|
+ features: [
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ Rangpur:{
|
|
|
+ type: "FeatureCollection",
|
|
|
+ totalFeatures: 544,
|
|
|
+ features: [
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ Dhaka:{
|
|
|
+ type: "FeatureCollection",
|
|
|
+ totalFeatures: 544,
|
|
|
+ features: [
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ Sylhet:{
|
|
|
+ type: "FeatureCollection",
|
|
|
+ totalFeatures: 544,
|
|
|
+ features: [
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ Mymensingh:{
|
|
|
+ type: "FeatureCollection",
|
|
|
+ totalFeatures: 544,
|
|
|
+ features: [
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ Khulna:{
|
|
|
+ type: "FeatureCollection",
|
|
|
+ totalFeatures: 544,
|
|
|
+ features: [
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ };
|
|
|
+ let cityName = {
|
|
|
+ Barisal:['Barguna','Barisal','Bhola','Jhalokati','Patuakhali','Pirojpur'],
|
|
|
+ Chittagong:['Bandarban','Brahmanbaria','Chandpur','Chittagong','Khagrachhari','Lakshmipur','Noakhali','Rangamati','Comilla','Cox\'s Bazar','Feni'],
|
|
|
+ Rajshahi:['Naogaon','Natore','Chapai Nawabganj','Pabna','Rajshahi','Sirajganj','Bogra','Joypurhat'],
|
|
|
+ Rangpur:['Dinajpur','Gaibandha','Kurigram','Lalmonirhat','Nilphamari','Panchagarh','Rangpur','Thakurgaon'],
|
|
|
+ Dhaka:[ 'Dhaka','Kishoreganj','Madaripur','Manikganj','Munshiganj','Narayanganj','Narsingdi','Rajbari','Shariatpur','Tangail','Faridpur','Gazipur','Gopalganj'],
|
|
|
+ Sylhet:['Habiganj', 'Maulvibazar', 'Sunamganj', 'Sylhet'],
|
|
|
+ Mymensingh:[ 'Mymensingh', 'Netrakona', 'Sherpur', 'Jamalpur'],
|
|
|
+ Khulna:[ 'Bagerhat','Chuadanga','Jessore','Jhenaidah','Khulna','Kushtia','Magura','Meherpur','Narail','Satkhira']
|
|
|
+ };
|
|
|
+ let arr3Length = 0;
|
|
|
+ let index = 0;
|
|
|
+ let number = 0;
|
|
|
+ let fun = function(arr,provinceName,name,item,cfName){
|
|
|
+ let arr3 = [];
|
|
|
+ // console.log('计算第'+i+'轮开始');
|
|
|
+ // console.log(item)
|
|
|
+ for(let d of arr){
|
|
|
+ // d.properties.name = d.properties.Divi_name+'-'+ d.properties.Dist_name+'-'+ d.properties.Upaz_name;
|
|
|
+ // d.properties.name = d.properties.Divi_name;
|
|
|
+ // d.properties.name = d.properties.Dist_name;
|
|
|
+ // d.properties.name = d.properties.Upaz_name;
|
|
|
+ // console.log(d.properties.Dist_name+' '+name,'----8888888888888888-----')
|
|
|
+ if(d.properties.Divi_name == provinceName){
|
|
|
+ if(d.properties.Dist_name == name){
|
|
|
+ if(d.properties.Upaz_name == 'Manpura Upazila'||d.properties.Upaz_name=='Kala Para Upazila'||d.properties.Upaz_name=='Galachipa Upazila'){
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if(cfName == d.properties.Upaz_name){
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ item.properties.name = d.properties.Dist_name;
|
|
|
+ if(item.geometry.coordinates[0][0].length == 0){
|
|
|
+ number++;
|
|
|
+ item.geometry.coordinates[0][0] = JSON.parse(JSON.stringify(d.geometry.coordinates[0][0]));
|
|
|
+ console.log('已筛选 '+number+' '+d.properties.Upaz_name+'-------------1---------');
|
|
|
+ }else{
|
|
|
+ let x1 = false;
|
|
|
+ let x2 = false;
|
|
|
+ let y1 = false;
|
|
|
+ let y2 = false;
|
|
|
+ for(let j in d.geometry.coordinates[0][0]){
|
|
|
+ for(let key in item.geometry.coordinates[0][0]){
|
|
|
+ if(Math.abs(item.geometry.coordinates[0][0][key][0] - d.geometry.coordinates[0][0][j][0])+Math.abs(item.geometry.coordinates[0][0][key][1] - d.geometry.coordinates[0][0][j][1]) < 0.0000001){
|
|
|
+ if(!x1){
|
|
|
+ x1 = Number(key);
|
|
|
+ }
|
|
|
+ if(!y1){
|
|
|
+ y1 = Number(j);
|
|
|
+ }
|
|
|
+ x2 = Number(key);
|
|
|
+ y2 = Number(j);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(x1||x2||y1||y2){
|
|
|
+ if(y2>y1){
|
|
|
+ arr2 = d.geometry.coordinates[0][0].slice(y2,d.geometry.coordinates[0][0].length-1)
|
|
|
+ arr2.push(...(d.geometry.coordinates[0][0].slice(0,y1)))
|
|
|
+ }else{
|
|
|
+ arr2 = d.geometry.coordinates[0][0].slice(y2,y1)
|
|
|
+ }
|
|
|
+ if(x2>x1){
|
|
|
+ item.geometry.coordinates[0][0].splice(x1,x2-x1,...arr2)
|
|
|
+ }else{
|
|
|
+ item.geometry.coordinates[0][0].splice(x1,item.geometry.coordinates[0][0]-1-x1)
|
|
|
+ item.geometry.coordinates[0][0].splice(0,x2,...arr2)
|
|
|
+ }
|
|
|
+ number++;
|
|
|
+ console.log('已筛选 '+number+' '+d.properties.Upaz_name+'-------------2---------');
|
|
|
+ }else{
|
|
|
+ arr3.push(d)
|
|
|
+ }
|
|
|
+ console.log(provinceName+'-'+name+'-'+d.properties.Upaz_name+' '+arr3.length+'_'+arr3Length+'-'+index);
|
|
|
+ // d.geometry.coordinates[0][0] = arr1
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // console.log('计算第'+i+'轮结束'+' 未对比数'+arr3.length);
|
|
|
+ if(arr3Length == arr3.length){
|
|
|
+ index++;
|
|
|
+ }else{
|
|
|
+ index = 0;
|
|
|
+ arr3Length = 0;
|
|
|
+ }
|
|
|
+ if(arr3.length>0&&index<3){
|
|
|
+ arr3Length = arr3.length;
|
|
|
+ fun(arr3,provinceName,name,item)
|
|
|
+ }else{
|
|
|
+ // console.log(provinceName+' 1')
|
|
|
+ // console.log(provinceNameArrJSON[provinceName]+' 2')
|
|
|
+ // console.log(provinceNameArrJSON[provinceName].features.length+'已计算个数')
|
|
|
+ if(index>=3){
|
|
|
+ item = {
|
|
|
+ type: "Feature",
|
|
|
+ geometry: {
|
|
|
+ type: "MultiPolygon",
|
|
|
+ coordinates: [
|
|
|
+ [
|
|
|
+ arr3[0].geometry.coordinates[0][0]
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ properties: {
|
|
|
+ name:'',
|
|
|
+ }
|
|
|
+ }
|
|
|
+ index = 0;
|
|
|
+ number = 1;
|
|
|
+ arr3Length = 0;
|
|
|
+ console.log('已筛选 '+number+' '+arr3[0].properties.Upaz_name+'-------------3---------');
|
|
|
+ fun(bangladesh.features,'Barisal',name,item,arr3[0].properties.Upaz_name)
|
|
|
+ }else{
|
|
|
+ console.log(item.geometry.coordinates[0][0].length+'-------------')
|
|
|
+ provinceNameArrJSON[provinceName].features.push(item)
|
|
|
+ if(provinceNameArrJSON[provinceName].features.length>0){
|
|
|
+ console.log(provinceName+' '+name+'已计算');
|
|
|
+ console.log(provinceNameArrJSON[provinceName].features.length+'-'+cityName[provinceName].length)
|
|
|
+ if(provinceNameArrJSON[provinceName].features.length == cityName[provinceName].length){
|
|
|
+ let str = JSON.stringify(provinceNameArrJSON[provinceName]);//因为nodejs的写入文件只认识字符串或者二进制数,所以把json对象转换成字符串重新写入json文件中
|
|
|
+ // console.log(str)
|
|
|
+ fs.writeFile('./'+provinceName+'.json',str,function(err){
|
|
|
+ if(err){
|
|
|
+ console.log(err);
|
|
|
+ }
|
|
|
+ console.log('----------'+provinceName+'计算完成-------------');
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // for(let provinceName of provinceNameArr){
|
|
|
+ for(let name of cityName['Barisal']){
|
|
|
+ let item = {
|
|
|
+ type: "Feature",
|
|
|
+ geometry: {
|
|
|
+ type: "MultiPolygon",
|
|
|
+ coordinates: [[[]]]
|
|
|
+ },
|
|
|
+ properties: {
|
|
|
+ name:'',
|
|
|
+ }
|
|
|
+ }
|
|
|
+ index = 0;
|
|
|
+ number = 0;
|
|
|
+ fun(bangladesh.features,'Barisal',name,item)
|
|
|
+ }
|
|
|
+ // fun(bangladesh.features,'Barisal','Bhola',item)
|
|
|
+ // }
|
|
|
+ // fun(bangladesh.features,'Khulna')
|
|
|
+ // console.log(cityName)
|
|
|
+
|
|
|
+ // params.features.push(item);//将传来的对象push进数组对象中
|
|
|
+
|
|
|
+ // var str = JSON.stringify(params);//因为nodejs的写入文件只认识字符串或者二进制数,所以把json对象转换成字符串重新写入json文件中
|
|
|
+ // fs.writeFile('./person.json',str,function(err){
|
|
|
+ // if(err){
|
|
|
+ // console.error(err);
|
|
|
+ // }
|
|
|
+ // console.log('----------计算完成-------------');
|
|
|
+ // })
|
|
|
+ })
|
|
|
+}
|
|
|
+writeJson(params)//执行一下;
|