Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of vector simulation feature #3274

Open
iferencik opened this issue Apr 11, 2024 · 0 comments
Open

Improve performance of vector simulation feature #3274

iferencik opened this issue Apr 11, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@iferencik
Copy link
Contributor

iferencik commented Apr 11, 2024

Feature Description

The dynamic vector layers represents a special type of vector analytics where the MVT data is generated on the fly through a PostgreSQL function. This makes it possible to create simulation by adjusting/changing specific input parameters.

The whole concept of dynamic vector layers of function layers in MVT servers is to generate the data on the fly and this is very expensive, mainly because of simplification and other aspects defined through postgis MVT functions.

An alternative idea is to generate static MVT as a materialized view in postgis and then retried the MVT encoded tile data through a subquery. Next, a PLV8 Javascript or python fucntion could be used to to decode, update and encode back the tile data.

-- Create the materialized view with MVT data for the entire layer
CREATE MATERIALIZED VIEW mvt_layer_view AS
SELECT
ST_AsMVTGeom(geom, ST_TileEnvelope(0, 0, 0), 4096, 256, true) AS geom,
attribute1, attribute2, ...  -- Add other attributes as needed
FROM
your_layer_table;



-- Create the SQL function to retrieve tile data using XYZ coordinates
CREATE OR REPLACE FUNCTION get_tile_data(x integer, y integer, z integer)
RETURNS bytea AS $$
DECLARE
tile_data bytea;
BEGIN
-- Retrieve tile data from the materialized view into a variable
SELECT mvt_data INTO tile_data
FROM mvt_layer_view
WHERE x = $1 AND y = $2 AND z = $3;

-- Call the PL/v8 function to add a property to the tile data
tile_data := add_property_to_tile(tile_data, 'new_property', 'new_value');

-- Return the modified tile data
RETURN tile_data;
END;
$$ LANGUAGE plpgsql;

This approach will probably work well form higher zoom levels where tiles will have fewer features.

And alternative implementatino is to create a nodejs or fastAPI MVT enpoint wich will read binary tile data from a static MVT, decode it, compute dynamically various other props and append the props back to the tile.

Most probably this endpoint will also connect topostgres to fetch data for the enw props from various tables.

Essentially this would be an alterbnative to MVT function layer

Feature Implementation

No response

Feature Alternatives

No response

Feature Impact

No response

Feature Rationale

No response

Feature Considerations

No response

Feature Requirements

No response

┆Issue is synchronized with this Wrike task by Unito

@iferencik iferencik added the enhancement New feature or request label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant