简体   繁体   English

使用矢量层作为openlayers中栅格源的输入

[英]Using a vector layer as an input to a raster source in openlayers

I'm trying to use vector features as a mask for a raster source in Openlayers 5. (I want to do calculations on raster data only within specific jurisdictions, which are dynamically selectable by the user.) To do this, I tried to use the vector layer with my features as an input to the raster source, and then test each pixel to see if the mask is present. 我正在尝试将矢量要素用作Openlayers 5中栅格源的遮罩。(我只想对用户可以动态选择的特定管辖范围内的栅格数据进行计算。)为此,我尝试使用将具有我的特征的矢量层作为栅格源的输入,然后测试每个像素以查看是否存在遮罩。

The documentation indicates that this should be possible if the vector layer is configured with the option renderMode: 'image' . 文档指出,如果将矢量层配置为选项renderMode: 'image' ,则应该可行。 However, when the raster layer attempts to run I get a TypeError: h.getImage is not a function . 但是,当栅格图层尝试运行时,出现TypeError: h.getImage is not a function

My code is as follows: 我的代码如下:

// The base raster data
var arc = new TileArcGISRest({
    params: {
        'LAYERS': "view:0"
    },
    url: myDataURL,
    crossOrigin: 'anonymous',
});

// The vector mask in GeoJSON format
var town_vector = new ol.source.Vector({
    url: 'towns.json',
    format: new ol.format.GeoJSON(),
});

// The layer based on that vector
var town_layer = new ol.layer.Vector({
    title: 'added Layer',
    source: town_vector,
    renderMode: 'image',
    style: interest_style,
});

// The raster source that attempts the analysis
var summary_raster = new RasterSource({
    sources: [arc, town_layer],
    operation: function (pixels, data) {
        var pixel = pixels[0];
        var mask_pixel = pixels[1];
        if (mask_pixel[0] == mask_value) {
            run_calculation(pixel)
        }
    },
    lib: {
        run_calculation: run_calculation,
    }
});

It works perfectly when I remove the "town_layer" from the source, and eliminate the masking logic. 当我从源代码中删除“ town_layer”并消除掩蔽逻辑时,它可以完美工作。 However, when I add the "town_layer" to the raster source I get the aforementioned TypeError: h.getImage is not a function . 但是,当我将“ town_layer”添加到栅格源时,会出现上述TypeError: h.getImage is not a function How can I "rasterize" this vector layer and use it as in input to the raster source? 如何“栅格化”此矢量图层并将其用作栅格源的输入?

please check a this link which refers to a link 请检查此链接指的是一个链接

It states that ol.source.ImageVector has been deprecated from v4.5.0 and suggested to use ol.layer.Vector. 它指出ol.source.ImageVector已从v4.5.0中弃用,建议使用ol.layer.Vector。 And it worked for me.(I used a openlayers v6.0 ) Please try with v6.0 it may work for you too. 它对我有用。(我使用的是openlayers v6.0 )请尝试使用v6.0,它也可能对您有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM