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

Investigate the effects of low topoquantization epsilon values #110

Closed
mattijn opened this issue Aug 23, 2020 · 8 comments · Fixed by #116
Closed

Investigate the effects of low topoquantization epsilon values #110

mattijn opened this issue Aug 23, 2020 · 8 comments · Fixed by #116

Comments

@mattijn
Copy link
Owner

mattijn commented Aug 23, 2020

Given the following behaviour:

import topojson as tp
import geopandas as gpd

world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
tp.Topology(data=world).toposimplify(4).topoquantize(500).to_alt(color='properties.name:N')

image

Are these artifacts explainable by the principles of quantization or is there a certain process that needs improvement?

Help is welcome!

@ljwolf
Copy link

ljwolf commented Dec 1, 2020

We're seeing these issues as well.
Screenshot_20201201_160248

brexit.gpkg.zip

Interested in digging into this...

@mattijn
Copy link
Owner Author

mattijn commented Dec 11, 2020

Thanks for your interest in this issue. At this place in the docs https://mattijn.github.io/topojson/example/settings-tuning.html#prequantize I've worked out the quantization process in 1D.

I see you have linked this issue to another at the geopandas repo. Im still figuring out what is going wrong here. Maybe your usecase is a smaller reproducible example.

@mattijn
Copy link
Owner Author

mattijn commented Dec 11, 2020

Found a use-case small enough for debugging:

import topojson as tp
import geopandas as gpd

gdf = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
gdf = gdf[gdf.name.isin(['France', 'Belgium', 'Netherlands'])]
tp.Topology(data=gdf).toposimplify(4).topoquantize(500).to_alt(color='properties.name:N')

image

@mattijn
Copy link
Owner Author

mattijn commented Dec 12, 2020

Thanks again for commenting in order to bring this issue on my radar again!

This issue is fixed by #116, linestrings which can become points due filtering of repeating coordinates that were not written back to the linestring. After delta-encoding the start-coordinates of quantised linestrings got mixed up with this case.

During debugging I found out that the overal bbox is not regenerated after simplification and quantization. Filled #117 for this.

@mattijn
Copy link
Owner Author

mattijn commented Dec 12, 2020

I'm happy this issue is resolved. Its fun to play with this.

import topojson as tp
import geopandas as gpd

world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
tp.Topology(data=world).toposimplify(4).topoquantize(20).to_alt(color='properties.name:N')

image

@mattijn
Copy link
Owner Author

mattijn commented Dec 12, 2020

I've to admit it's not fast.

import topojson as tp
import geopandas as gpd
import matplotlib.pyplot as plt

brexit = gpd.read_file('/Users/mattijnvanhoek/Downloads/brexit.gpkg')
topo = tp.Topology(brexit)

q100 = topo.topoquantize(100).to_gdf()
q250 = topo.topoquantize(250).to_gdf()
q500 = topo.topoquantize(500).to_gdf()

f, ax = plt.subplots(1, 3, figsize=(10, 10))
q100.plot(ax=ax[0])
q250.plot(ax=ax[1])
q500.plot(ax=ax[2])

image

Would indeed be good to investigate routes for quantization through pygeos as well, like in this comment geopandas/geopandas#1727 (comment)

@ljwolf
Copy link

ljwolf commented Apr 29, 2021

If you're game for a numba implementation, I'm sure that'd help accelerate things? I prefer working on the topojson-style data structure, and numba could work well with ragged arrays stored as lists of tuples.

@mattijn
Copy link
Owner Author

mattijn commented Apr 29, 2021

This is discussed previously with @Casyfill and might be a good method indeed to improve speed further. It might be very simple to get good results, but I've never tried it. Let me open a new issue so it can be tracked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants