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

PolygonPatternSymbolizer metatile alignment #937

Closed
pnorman opened this issue Sep 10, 2014 · 27 comments
Closed

PolygonPatternSymbolizer metatile alignment #937

pnorman opened this issue Sep 10, 2014 · 27 comments

Comments

@pnorman
Copy link
Collaborator

pnorman commented Sep 10, 2014

To use polygon pattern, the pattern either needs to fit into fit into a metatile an integer number of times with polygon-pattern-alignment: global or have polygon-clip: false, or artifacts at meta-tile boundaries will occur.

Without a fixed metatile size, this implies both pattern dimensions should be a multiple of two, and at most 256.

Because the defaults used to be polygon-clip: false, many of the icons do not meet this criteria. We need to check if there is more performance from polygon-clip: false, and if so, set that, otherwise, change the PNGs.

Some shell scripting (./node_modules/.bin/carto -a 3.0.12 project.mml | grep PolygonPatternSymbolizer | sed 's| <PolygonPatternSymbolizer [^>]*file="\([^"]*\)".*/>|\1|' | sort -u | xargs pnginfo | grep -B1 'Image Width') lets us get the image sizes.

The following files are not powers of two

symbols/danger.png...
  Image Width: 30 Image Length: 30
symbols/grave_yard_jewish.png...
  Image Width: 18 Image Length: 18
@matthijsmelissen
Copy link
Collaborator

a multiple of two

A power of two, right?

@pnorman
Copy link
Collaborator Author

pnorman commented Sep 10, 2014

A power of two, right?

Ah, fixed.

@imagico
Copy link
Collaborator

imagico commented Sep 11, 2014

Currently all patterns are very regular with small tile size, most with a square cartesian grid. The most randomized are probably scrub and wetland. The question is if this is a deliberate design decision intended to be kept or if a more randomized pattern would actually be preferred. It is quite easily possible to generate a randomized power-of-two-periodic pattern and with the current symbol sizes and distances and this would mostly work well with a tile size limit of 256 pixel. Here a quick demo for the forest symbol (just a rough imitation, not really an exact reproduction):

randomized periodic forest pattern

A randomized pattern of course requires a relatively large tile size to look good - 256 pixel is already quite the minimum in this case. This might have performance implications.

@pnorman
Copy link
Collaborator Author

pnorman commented Sep 11, 2014

I'd like to keep switching to a randomized pattern as a separate issue.

@pnorman
Copy link
Collaborator Author

pnorman commented Jan 17, 2015

Updated the list.

pnorman added a commit to pnorman/openstreetmap-carto that referenced this issue Jan 18, 2015
This adds a random symbology for forests, lightens forests, and
unifies natural=wood and landuse=forest rendering.

Using http://www.imagico.de/map/jsdotpattern.php a random pattern
was generated from the SVG

    <path d="m 3.5,0 -3.5,3.5 0,0.5 0.5,0 2.5,-2.5 0,2
    -3,3 0,0.5 0.5,0 2.5,-2.5 0,5.5
    1,0 0,-5.5 2.5,2.5 0.5,0 0,-0.5 -3,-3 0,-2
    2.5,2.5 0.5,0 0,-0.5 z" fill="rgb(58,135,39)"/>

    <path d="m 10.5,0 a 2.5,3 0 0,1 0,6 l 0,-1
    a 1.5,2 0 0,0 0,-4
    a 1.5,2 0 0,0 0,4 l 0,1
    a 2.5,3 0 0,1 0,-6
    z" fill="rgb(58,135,39)"/>

This was then converted with GIMP into a PNG which Mapnik can use.

The forest fill was lightened, but there are now darker symbols on.

This necessitated adjusting the text colour for forests, which was
done in Lch colour space. The frequent symbols also required some
halo adjustments.

There are multiple interpretations in use of landuse=forest vs.
natural=wood. Rather than attempt to sort this out when the tagging
has not settled, the same appearance is used for both.

This commit doesn't use different symbologies for different types
of forests (mixed/coniferous/broad_leaved/palm) (gravitystorm#822), but that
can be considered later.

Fixes gravitystorm#938
Fixes forest part of gravitystorm#937
pnorman added a commit to pnorman/openstreetmap-carto that referenced this issue Jan 18, 2015
This adds a random symbology for forests, lightens forests, and
unifies natural=wood and landuse=forest rendering.

Using http://www.imagico.de/map/jsdotpattern.php a random pattern
was generated from the SVG

    <path d="m 3.5,0 -3.5,3.5 0,0.5 0.5,0 2.5,-2.5 0,2
    -3,3 0,0.5 0.5,0 2.5,-2.5 0,5.5
    1,0 0,-5.5 2.5,2.5 0.5,0 0,-0.5 -3,-3 0,-2
    2.5,2.5 0.5,0 0,-0.5 z" fill="rgb(58,135,39)"/>

    <path d="m 10.5,0 a 2.5,3 0 0,1 0,6 l 0,-1
    a 1.5,2 0 0,0 0,-4
    a 1.5,2 0 0,0 0,4 l 0,1
    a 2.5,3 0 0,1 0,-6
    z" fill="rgb(58,135,39)"/>

This was then converted with GIMP into a PNG which Mapnik can use.

The forest fill was lightened, but there are now darker symbols on.

This necessitated adjusting the text colour for forests, which was
done in Lch colour space. The frequent symbols also required some
halo adjustments.

There are multiple interpretations in use of landuse=forest vs.
natural=wood. Rather than attempt to sort this out when the tagging
has not settled, the same appearance is used for both.

This commit doesn't use different symbologies for different types
of forests (mixed/coniferous/broad_leaved/palm) (gravitystorm#822), but that
can be considered later.

Fixes gravitystorm#938
Fixes forest part of gravitystorm#937
Closes #6
@pnorman
Copy link
Collaborator Author

pnorman commented Mar 14, 2015

Updated, including a minor shell script change.

@pnorman
Copy link
Collaborator Author

pnorman commented Aug 8, 2015

Updated

@pnorman
Copy link
Collaborator Author

pnorman commented Jan 30, 2017

Updated, we're close

@kocio-pl
Copy link
Collaborator

We have the last one which is still not power of two:

symbols/danger.png...
  Image Width: 30 Image Length: 30
--

but we have more above 256 px:

symbols/wetland_bog.png...
  Image Width: 512 Image Length: 512
--
symbols/wetland_mangrove.png...
  Image Width: 512 Image Length: 512
--
symbols/wetland_marsh.png...
  Image Width: 512 Image Length: 512
--
symbols/wetland_reed.png...
  Image Width: 512 Image Length: 512
--
symbols/wetland_swamp.png...
  Image Width: 512 Image Length: 512

Why would they be a problem?

@pnorman
Copy link
Collaborator Author

pnorman commented Aug 12, 2017

Why would they be a problem?

Because they won't align when rendering tile by tile

@kocio-pl
Copy link
Collaborator

Should we recreate them all in 256 px then?

@pnorman
Copy link
Collaborator Author

pnorman commented Aug 12, 2017

Because they won't align when rendering tile by tile

They also won't align with some metatiling systems when taking into account buffer.

Should we recreate them all in 256 px then?

Yes.

@sommerluk
Copy link
Collaborator

SVG polygon pattern files currently > 256 px:

quarry.svg
scrub.svg
forest.svg

All others are ≤ 256 px and a power of 2.

@imagico
Copy link
Collaborator

imagico commented Aug 15, 2017

For all of these there were good reasons to make them 512 pixel in size (as well as for the wetland patterns which are also 512 pixel). In case of relaxed random patterns there are the following requirements for a good quality irregular pattern:

  • The relaxation radius should be at least about 3 times the minimum symbol distance.
  • The relaxation radius should be less than half the pattern size (otherwise jsdotpattern can produce weird results).
  • The pattern size should be large compared to the correlation length of the pattern, otherwise you have trouble properly relaxing the positions without running into resonance effects due to the periodic boundary conditions.

This does not mean you cannot create a decent random pattern with 256 pixel size for scrub and forest but it is significantly more difficult.

@kocio-pl
Copy link
Collaborator

With #2739 being merged now, and all the others being deliberately 512 px, I guess we can close this issue.

@pnorman
Copy link
Collaborator Author

pnorman commented Aug 16, 2017

Are we sure we're not running into any issues in production or with Kosmtik with the 512px patterns?

@imagico
Copy link
Collaborator

imagico commented Aug 23, 2017

I would assume that through

we define a minimum metatile size of 512 pixel. But if there are reasons to allow 256 pixel metatiles this would of course be possible. There would be some constraints design wise - see above - but it would be manageable.

@pnorman
Copy link
Collaborator Author

pnorman commented Aug 27, 2017

we define a minimum metatile size of 512 pixel. But if there are reasons to allow 256 pixel metatiles this would of course be possible. There would be some constraints design wise - see above - but it would be manageable.

Is the origin of the pattern at the edge of the rendering, or the edge of the metatile? I don't know the answer to this, and I wouldn't assume everything is the same.

@imagico
Copy link
Collaborator

imagico commented Aug 28, 2017

Is the origin of the pattern at the edge of the rendering, or the edge of the metatile?

In a tiled rendering the edge of the metatile is also the edge of the rendering (at least from the point of view of mapnik).

polygon-pattern-alignment: global is actually a misleading identifier. local means the pattern is aligned to the geometry it is applied to. global should better be renamed render_area and means the pattern is aligned to the top left corner of whatever area mapnik is instructed to render. Real global alignment would mean the pattern is aligned to the map coordinate system origin (i.e. null island) and periodically repeated globally no matter what bounding box you render. This is what you'd normally want, it would also allow using arbitrarily sized patterns. But you don't get this with mapnik.

@pnorman
Copy link
Collaborator Author

pnorman commented Aug 29, 2017

In a tiled rendering the edge of the metatile is also the edge of the rendering (at least from the point of view of mapnik).

No, things are buffered beyond the metatile.

@imagico
Copy link
Collaborator

imagico commented Aug 29, 2017

Ok, but then the alignment appears to be independent of the buffer - both in kosmtik and on the OSMF servers.

@dieterdreist
Copy link

dieterdreist commented Aug 31, 2017 via email

@kocio-pl
Copy link
Collaborator

Related to what @sommerluk told in #2748 (comment) - there's a need to decide how do we want to go on with patterns currently? We can leave the things as they are and suspend changes for some time, but even such solution needs a deadline and decision at the end - no matter if we know all the side effects of tiling, because patterns are important tool we use.

@kocio-pl
Copy link
Collaborator

kocio-pl commented Nov 3, 2018

Looks like the Mapnik solution is getting ready - mapnik/mapnik#3989 is merged now, next thing would be 3.0.x port and release.

@sommerluk
Copy link
Collaborator

The Mapnik solution will bring us true global alignment of pattern, so we could use even pattern with arbitrary size (113 × 113 or whatever), which is really great.

An open pull request for the backport is at mapnik/mapnik#4005

@sommerluk
Copy link
Collaborator

True global alignment is part of Mapnik 3.0.22 release. Should this issue be closed now?

@sommerluk
Copy link
Collaborator

Closing this issue.

This has been fixed at the Mapnik side and also backported to the 3.0.x series. Now polygon-pattern-alignment: global means really true global alignment. So starting with Mapnik 3.0.22, now we can use polygon patterns with arbitrary sizes like 113 × 113, and also non-square values like 113 × 59.

I’ve verified this with python-mapnik 3.0.22, and it works correctly. (However, the current node-mapnik still hasn’t this fix, but I think it will be part of the next release.)

Note that currently we do not require Mapnik 3.0.22 in our INSTALLmd, so we can only rely on this feature if we also bump our requiered Mapnik version to at least 3.0.22.

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

No branches or pull requests

6 participants