-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Postgresql provider - Use ST_RemoveRepeatedPoints instead of ST_SnapToGrid #2410
Conversation
+1, great! But the ST_RemoveRepeatedPoints method can break the topology between adjacent polygons? |
Does the topology also matter when using sub-pixel optimization? |
@m-kuhn I do not think so. I think simplified data is only used for rendering. Whenever you need to modify a feature (or snap), I remember previous discussions about using un-simplified versions for data interactions. Perhaps someone can confirm this. It leads to another question. I think this ST_RemoveRepeatedPoints function is equivalent to ST_SnapToGrid when used for sub-pixel (or pixel) optimization. But I think also it will provide better rendering when using a higher tolerance (like 5 pixels), so it would be great to have. |
Yes, it's only used for rendering (in core, plugins may use it differently). I think it may introduce some offsets between polygons which are supposed to be adjacent. But this only applies if
For other circumstances, ST_Simplify in combination with ST_RemoveRepeatedPoints would give great performance with no trade-off. Maybe topological simplification should be an option (and a hint in the gui that with tolerance <= 1 pixel there's no real reason to do this)? |
Hi, there is an old pull with comments about this. Simply it commented that ST_Simplify postgis function could cause empty pixels. Now, I guess this error is already fixed. @palmerj detected the issue: |
1fe72af
to
21a2a49
Compare
I have just updated (forced) my branch with 2 goals:
I also added a message in QGIS log to get the PostGis method used, which I would remove after enough checking have been done |
Any objections to merging this? |
It needs some testing first. I have not yet tested it with PostGIS 2.2 (since my laptop is under ubuntu and postgis 2.2 cannot be installed easily. I need to use docker to have a testing database... |
What did you test? |
@jef-n I will fix this. This pull-request is here for discussion and testing by devs. I will be happy to make any needed modifications, and close it if our tests show no real performance gain. |
@mdouchin any feedback on the speed difference? |
@m-kuhn I have juste tested, and I have good results ( ex: 10s for snaptogrid, and 6s for remoterepeatedpoints ). |
21a2a49
to
976d7db
Compare
Hi all ! They look really promising, so I would ask for some volunteers to test this PR too, and report here. Data testA polygon layer from Corine Land Cover data (39726 adjacent polygons).
Then I import this data via DBManager into a database with PostGIS 2.2, and use this layer as a test layer. IntroWhen working with adjacent polygons, if tolerance is above 1px, ST_RemoveRepeatedPoints method creates some tiny (but visible) holes. So I will just use ST_SnapToGrid when tolerance is > 1px. The following results have been made with a 1px tolerance, with simplification done server-side. ResultsNo simplification
ST_SnapToGrid
ST_RemoveRepeatedPoints
Quick comparisonWhen summing up only the time fetching data for the ten first lines, I get these times in ms:
|
Interesting, good work. If I read Paul Ramsey's article it seems as if this is done as a pre-filtering step and ST_Simplify is still applied on top. Does this make sense? |
@m-kuhn I have not yet figured out what ST_Simplify would add here. If anyone knows... I think the main improvement for QGIS would be to use TinyWKB instead of WKB to decrease the data size. But this is beyond my QGIS knowledge at the moment... |
It seems travis CI build failed. Ayn Travis "guru" to help me find out what is going on here ? I will also test soon the use of ST_Simplify( "geomSimplifiedByRemoveRepeatedPoints" , tolerance, True) to compare the results |
The sip bindings for the new methods are missing. No big issue. |
ok @m-kuhn I will add them then. Thanks |
Yep - imagine a section of a geometry which consists of lots little details but appears as a straight line when zoomed out sufficiently. ST_RemoveRepeatedPoints will remove vertices which are <= 1px from each other, but (at worst) this section of the geometry will still include vertices corresponding to each pixel along the line. Calling ST_Simplify on the geometry with a suitable tolerance will strip out all these additional vertices and result in just a start & end vertex for the section of geometry. It would be a big improvement for certain geometries. Note that you'll need to use the extra parameter to preserve collapsed geometries described by Paul here: http://blog.cartodb.com/smaller-faster/.
returns null, but
returns the input polygon untouched. Not sure why this parameter is undocumented (or why passing false to it also results in persistence of collapsed geometries. @strk? |
/** Sets the simplification threshold of the vector layer managed */ | ||
void setThreshold( float threshold ) { mThreshold = threshold; } | ||
/** Gets the simplification threshold of the vector layer managed */ | ||
inline float threshold() const { return mThreshold; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not immediately clear what the difference between threshold and tolerance is here. This could get quite confusing in future if threshold is used in a different way by another provider. Can you expand these doc strings to describe exactly what the difference is?
(also, why float here?)
@mdouchin this sounds great... can't wait for this to land! Fantastic work :) |
New in 2.2.0
Best asked to Paul who did introduce the change:
https://trac.osgeo.org/postgis/ticket/2093#comment:38
|
Thanks all for your review.
It helps to decrease again the weight of fetched geometrie, but creates some very small but visible artefacts (holes) in the sample data (adjacent polygons). It is visible if the layer symbology consists in a simple symbol with border and background of the same color. At present I have only tested with adjacent polygons (not lines) and with a ST_Simplify 2nd parameter equal to the one used in ST_RemoveRepeatedPoints. I will try with another geometry type and to decrease the ST_simplify tolerance. |
976d7db
to
706e651
Compare
Hi all. Thanks for your review ! New version pushed with the use of pre-filtering ST_simplify, which decreases the number of vertexes to download. For ST_Simplify, I chose to use a tolerance smaller than the one used in pre-filtering with ST_RemoveRepeatedPoints, just to be one the safe side. Please test and report if anything must be changed I also added the new methods in the SIP bindings, but travis is still complaining ( but the only errors I see are about DBManager ) |
Some quick results, with the same data and query as mentioned above, to show how the number of vertexes decreases. It would lead to best performance also because the data will be downloaded from the PostGIS faster
|
@m-kuhn @ahuarte47 @jef-n @nyalldawson @strk Any objection to merge it as is, to let more people test it, and modify behaviour afterwards if necessary ? I have no answer about it in qgis-dev mailing list. Which core dev is in charge of this part of the code ? Please assign her/him (I have no github rights to add tags or assignees to an issue for QGIS repository ) |
Postgresql provider - Use ST_RemoveRepeatedPoints instead of ST_SnapToGrid
Thank you @mdouchin ! |
Thanks to all reviewers, and for accepting this PR |
Thank you @mdouchin ! great work! |
When using a PostGIS 2.2 instance, we can now use the ST_RemoveRepeatedPoints function instead of the ST_SnapToGrid function, as described by Paul Ramsey : http://blog.cartodb.com/smaller-faster/