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

Allow ignore small geometries #792

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sharkAndshark
Copy link
Collaborator

@sharkAndshark sharkAndshark commented Aug 2, 2023

Implements #756

@sharkAndshark sharkAndshark changed the title Add exclude small geometries CLI arg Allow ignore small geometries Aug 2, 2023
@nyurik
Copy link
Member

nyurik commented Aug 3, 2023

just to clarify - do you plan to make this PR remove polygons that are too small for a given zoom level, or do you want to deal with merging "polygon dust" as discussed in #756? Please update the PR description. Thx!

@sharkAndshark
Copy link
Collaborator Author

sharkAndshark commented Aug 4, 2023

Hi @nyurik  :)  
I'm still thinking of these things and it would be better to build the talk based on code and test so I make this draft PR. Sorry for this late description.
The basic idea is something like impose a  random number to make the cluster of small buildings still can be seen on screen.

...
WHERE 
ST_TRANSFORM("geom",3857) && ST_TileEnvelope(3, 1, 1) 
AND  ( ST_AREA ( ST_TRANSFORM ( geom, 3857 ) ) >= ( ( 40075016.68 / ( 2 ^ z * 512 ) ) ^ 2 ) )   
AND RANDOM() > 0.3  
-- the random threshold should be from config maybe
...

Yes,It's for #756  
let's talk and test more on this PR :)

@sharkAndshark sharkAndshark force-pushed the smallgeoms branch 4 times, most recently from d7ff0fd to 045a0b5 Compare August 4, 2023 06:46
Copy link
Member

@nyurik nyurik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the current SQL changes - I looked at ST_AsMVTGeom -- and it has this text:

From 3.0, Wagyu can be chosen at configure time to clip and validate MVT polygons. This library is faster and produces more correct results than the GEOS default, but it might drop small polygons.

Which means that exactly the same filtering is already being done by SQL?

Note that this is different from merging tiny chunks

@sharkAndshark
Copy link
Collaborator Author

I think you are right @nyurik
The code in st_asmvtgeom related to this PR is here:

/* If possible, peek into the bounding box before deserializing it to discard small geometries
	 * We don't check COLLECTIONTYPE since that might be a collection of points */
	if (type == LINETYPE || type == POLYGONTYPE || type == MULTILINETYPE || type == MULTIPOLYGONTYPE)
	{
		GBOX gserialized_box;
		/* We only apply the optimization if the bounding box is available */
		if (gserialized_fast_gbox_p(geom_in, &gserialized_box) == LW_SUCCESS)
		{
			/* Shortcut to drop geometries smaller than the resolution */
			double geom_width = gserialized_box.xmax - gserialized_box.xmin;
			double geom_height = gserialized_box.ymax - gserialized_box.ymin;

			/* We use half of the square height and width as limit: We use this
			 * and not area so it works properly with lines */
			double bounds_width = ((bounds->xmax - bounds->xmin) / extent) / 2.0;
			double bounds_height = ((bounds->ymax - bounds->ymin) / extent) / 2.0;
			if (geom_width < bounds_width && geom_height < bounds_height)
			{
				PG_RETURN_NULL();
			}
		}
	}

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 this pull request may close these issues.

None yet

2 participants