【GIS】d3-contour、geojson转换

        function XY2YX(coordinates, convert, xmin, ymin, xmax, ymax, width, height) {
            var yx = []
            for (let i = 0; i < coordinates.length; i++) {
                var yxChild = []
                for (let j = 0; j < coordinates[i].length; j++) {
                    var yxChild2 = []
                    for (let z = 0; z < coordinates[i][j].length; z++) {

                        let x = coordinates[i][j][z][0];
                        let y = coordinates[i][j][z][1];
                        if (convert) {
                            x = (x / width) * (xmax - xmin) + xmin;
                            y = ((height - y) / height) * (ymax - ymin) + ymin;
                            console.log(x, y);
                            yxChild2.push([x, y]);
                        } else {
                            yxChild2.push([x, y])
                        }
                    }
                    yxChild.push(yxChild2)
                }
                yx.push(yxChild)
            }
            return yx;
        }
原文地址:https://www.cnblogs.com/defineconst/p/13805019.html