一種改進後的turf.idw演算法

來源:互聯網
上載者:User

標籤:瀏覽器   pre   contain   sea   定義   console   sid   img   cti   

 

 

turf 是Advanced geospatial analysis geojson data in javascript.

官網:http://turfjs.org/

 

針對github 中的源碼。

記得在以前使用arcgis 的反距離插值的時候有搜尋半徑和剪下範圍定義。

於是就增加了這兩個參數。

可在瀏覽器端使用的IDW演算法就最佳化到相對適合使用了。

 

  /**     * idwPolygon - 反距離插值產生格網面集     *     * @param {type} controlPoints   離散點     * @param {type} valueField      計算屬性值z     * @param {type} b               反距離冪值     * @param {type} cellWidth       儲存格寬     * @param {type} SearchR         搜尋半徑     * @param {type} units           單位km     * @param {type} boundaryPolygon 剪裁範圍     *     * @return {type} Description     */    var idwPolygon = function(controlPoints, valueField, b, cellWidth, SearchR, units, boundaryPolygon) {        var distance = turf.distance;        var squareGrid = turf.squareGrid;        var centroid = turf.centroid;        var bbox = turf.bbox;        var inside = turf.inside;        var featureCollection = turf.featureCollection;        // check if field containing data exists..        var filtered = controlPoints.features.filter(function(feature) {            return feature.properties &&                feature.properties.hasOwnProperty(valueField);        });        if (filtered.length !== 0) {            // create a sample square grid            // compared to a point grid helps visualizing the output (like a raster..)            var resultGrid = [];            var bbbox = boundaryPolygon ? bbox(boundaryPolygon) : bbox(controlPoints);//剪下範圍增加            var samplingGrid = squareGrid(bbbox, cellWidth, units);            var N = samplingGrid.features.length;            for (var i = 0; i < N; i++) {                var cpointi = centroid(samplingGrid.features[i]);                if (!inside(cpointi, boundaryPolygon)) { //如果在面外,不參與計算                    continue;                }                var zw = 0;                var sw = 0;                // calculate the distance from each control point to cell‘s centroid                 for (var j = 0; j < controlPoints.features.length; j++) {                    var d = distance(cpointi, controlPoints.features[j], units);                    if (d > SearchR) {                        continue;                    }                    if (d === 0) {                        zw = controlPoints.features[j].properties[valueField];                    }                    var w = 1.0 / Math.pow(d, b);                    sw += w;                    zw += w * controlPoints.features[j].properties[valueField];                }                // write IDW value for each grid cell                var zvalue = zw / sw; //如果都在影響半徑外,那麼可能為非數字,賦值為0                samplingGrid.features[i].properties.z = zvalue ? zvalue : 0;                resultGrid.push(samplingGrid.features[i]);            }            return featureCollection(resultGrid);        } else {            console.log(‘Specified Data Field is Missing‘);        }    };

  

:

 

一種改進後的turf.idw演算法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.