forked from foktitus-star/xinyi-water-map
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessTrees.js
More file actions
42 lines (34 loc) · 1.42 KB
/
Copy pathprocessTrees.js
File metadata and controls
42 lines (34 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const fs = require('fs');
const proj4 = require('proj4');
proj4.defs(
'EPSG:3826',
'+proj=tmerc +lat_0=0 +lon_0=121 +k=0.9999 +x_0=250000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'
);
const inputFile = 'C:\\Users\\samli\\Antigravity-智慧城市\\TaipeiTree.json';
const outputFile = 'C:\\Users\\samli\\Antigravity-智慧城市\\xinyi-water-map-main\\xinyi-water-map-main\\public\\TaipeiTree_filtered.json';
console.log('Reading input file...');
const rawData = fs.readFileSync(inputFile, 'utf-8');
const trees = JSON.parse(rawData);
const filteredTrees = [];
console.log(`Processing ${trees.length} trees...`);
for (const t of trees) {
const x = parseFloat(t.TWD97X || t.X || t.TWD97_X || t.x);
const y = parseFloat(t.TWD97Y || t.Y || t.TWD97_Y || t.y);
if (!isNaN(x) && !isNaN(y)) {
const [lng, lat] = proj4('EPSG:3826', 'EPSG:4326', [x, y]);
if (lat >= 25.012777 && lat <= 25.051619 && lng >= 121.549092 && lng <= 121.592334) {
// Create a clean version of the object with only necessary fields to save space
filteredTrees.push({
lat: Number(lat.toFixed(6)),
lng: Number(lng.toFixed(6)),
TreeID: t.TreeID,
TreeType: t.TreeType,
TreeHeight: t.TreeHeight,
Diameter: t.Diameter
});
}
}
}
console.log(`Filtered trees: ${filteredTrees.length}`);
fs.writeFileSync(outputFile, JSON.stringify(filteredTrees));
console.log('Saved to', outputFile);