1

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.

The documentation indicates that this should be possible if the vector layer is configured with the option renderMode: 'image'. However, when the raster layer attempts to run I get a 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. However, when I add the "town_layer" to the raster source I get the aforementioned TypeError: h.getImage is not a function. How can I "rasterize" this vector layer and use it as in input to the raster source?

  • There is a problem with the full build, using a vector layer a source only works when using modules https://codesandbox.io/s/image-vector-layer-pd6is – Mike Sep 11 '19 at 20:51
  • Even using modules seems to work only intermittently with codesandbox. Replacing `ol.layer.Vector` with `ol.layer.VectorImage` and using OL version 6 beta looks like the only reliable way of getting it to work. – Mike Sep 12 '19 at 10:56
  • I've switched to modules, which didn't work by itself as you've noted. I changed my install with `npm install ol@6.0.0-beta.15`, and used `ol/layer/VectorImage`. There are no errors in the console, but the map fails to render entirely. Do you have any recommendations on what to do to get this working? – Zach Balleisen Sep 13 '19 at 19:29

1 Answers1

0

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. And it worked for me.(I used a openlayers v6.0) Please try with v6.0 it may work for you too.

Bikuz
  • 36
  • 3