orb icon indicating copy to clipboard operation
orb copied to clipboard

copy the original mvt.Layers for reuse

Open SulimanLab opened this issue 2 years ago • 3 comments

Hi there,

I am trying to build a tileserver that reads geojson and serve tiles

I started by reading the json file:

geojsonData, err := ioutil.ReadFile("./data/large_data.geojson")

then I unmarshal the file to go object:

r = map[string]*geojson.FeatureCollection{}
err = json.Unmarshal(geojsonData, &r)

layers := mvt.NewLayers(r)

when serving the tiles the original values of the layers gets mutated, which force me to read and unmarshal the geojson again,

I tried to copy layers so I don't modify the original layers, but still changing one changes the other.

How I can copy the layers by value?

SulimanLab avatar May 25 '22 06:05 SulimanLab

full example can be found here: playground

SulimanLab avatar May 25 '22 06:05 SulimanLab

The answer for your tool it to load the file for every request.

The layers.ProjectToTile, layers.Clip and layers.Simplify commands modify the layer data. This is by design for performance reasons. It's expected the feature collection/layers are loaded newly from a database on every request.

It possible we could add a Clone method to geojson features and feature collections so you could do that instead for just reloading the file.

paulmach avatar May 26 '22 21:05 paulmach

I have wrote a function that's deep copy the features collections, but I am not sure about the performance.

If you will do it at your end that would be great.

SulimanLab avatar May 27 '22 10:05 SulimanLab