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

Add optional but explicit units everywhere #389

Closed
artemp opened this issue Oct 11, 2011 · 2 comments
Closed

Add optional but explicit units everywhere #389

artemp opened this issue Oct 11, 2011 · 2 comments

Comments

@artemp
Copy link
Member

artemp commented Oct 11, 2011

Currently, measurements are specified as simple ints/floats with implied pixel units.

In coordination with recent work on resolution (e.g. ticket:343) it would be worth adding optional units to all measurements, e.g. "pt", "px", "in", "mm", "cm" (this might be a complete list - "em", "ex", and "%" from CSS doesn't make sense in the Mapnik context). Numbers without explicit units would be interpreted as pixels. Pixels (device pixels) would be unaffected by map resolution.

Thoughts?

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[springmeyer] Good thinking, this could be handy. I agree, the resolution/unit assumption currently used in #343 to get things working is not ideal.

My latest thinking is that the Map object should be resolution-agnostic, but perhaps is still a good place to be able to accept one or several raw scale factors that would at render-time apply to line widths, fonts, symbols separately. I could see this list grow however, so this demands more thought about the best long-term way to be able to scale specific parts of symbolizers - maybe some sort of scaling grammer needs to be cooked up to avoid needing to hack at the renderers each time we want to tweak something new. Or we just limit the ability of the Mapnik API to pass one global scale factor and leave it up to client apps to do the heavy lifting (in python or xml) of tweaking and reloading changed/tweaked styles. '''In general within Mapnik, based on the way C++ works, you can't modify symbolizers once they are created. So in C++ they need to be tweaked either at construction or at render time when their attributes are passed to AGG/CAIRO.'''

For resolution and unit assumptions this could also be left to the client application (Cascadenik, QGis, webapp) if accessing the mapnik API, or could be able to be handled within Mapnik when loading XML/CSS.

If I'm thinking clearly all the client application/XML loader needs to know is what Mapnik's assumed pixel size is (0.28 mm or 0.01102 inches), and if it has been changed/calibrated by the user (#196).

Then working out how to convert the units should be fairly easy... pasting here my scratching from http://mapnik-utils.googlecode.com/svn/sandbox/print2pixel as reference of one example px -> inches:

{{{
#!python

from SLD/Symbology encoding spec originally (assumed pixel size, section 10.2)

http://www.opengeospatial.org/standards/symbol

http://trac.mapnik.org/browser/trunk/src/scale_denominator.cpp#L37

OGC_PIXEL = 0.28 # mm

def mm_px_size2ppi(pixel_size):
return 1.0/(pixel_size/25.4)

OGC_PPI = mm_px_size2ppi(OGC_PIXEL) # 90.714285714285708 as 1 'dot'/.011 inches
}}}

@springmeyer
Copy link
Member

not actionable. pixels + scale_factor are working fine

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

2 participants