Label cache #870

Open
artemp opened this Issue Oct 11, 2011 · 8 comments

Projects

None yet

3 participants

@artemp
Member
artemp commented Oct 11, 2011

https://gist.github.com/3842598

Currently, to ensure labels are placed on top of maps, separate layers are usually used.

This can be an optimization in some cases where features that should be rendered may be a very different set than those that should be labeled.

But, in cases like roads where lines features are both rendered visually and labeled, adding a label cache may provide a speed up to avoid the i/o impact of hitting the datasource more than once.

This could work by collecting, and caching all features that have matching text symbolizers, and rendering them after all other passes.

@artemp
Member
artemp commented Oct 11, 2011

[springmeyer] not sure if this should be LIFO or FIFO - I think mapserver does LIFO.

@artemp
Member
artemp commented Oct 11, 2011

[springmeyer] attached patch appears to work in some cases, but is buggy in others (only one feature is rendered). needs testing, not sure yet whether is helps with performance.

@artemp
Member
artemp commented Oct 11, 2011

[artem] Attached patch should fix issues with layer_label_deferred_rendering.diff (apply on top!) - UNTESTED
It uses boost::unordered_multimap to cache 'deferred' text.

@artemp
Member
artemp commented Oct 11, 2011

[springmeyer] artem, awesome work on the fixed up patch. compiles great for me, and works just as I hoped!

And I'm seeing a speedup in a very basic test:

Normal render is:

min: 72.684ms | avg: 73.659ms | total: 0.3682s

Deferred render is:

min: 64.453ms | avg: 66.508ms | total: 0.3323s

This is with the command:

$mapnik-speed-check benchmark/deferred.xml 5

And stylesheets like:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map srs="+init=epsg:3857">

  <Style name="style">
     <Rule>
       <LineSymbolizer rasterizer="fast"/>
     </Rule>    
   </Style>

  <Layer name="layer" srs="+init=epsg:3857">
     <StyleName>style</StyleName>
     <Datasource>
        <Parameter name="type">shape</Parameter>
        <Parameter name="file">data/1aa2d236-10m-admin-0-countries.shp</Parameter>
     </Datasource>
  </Layer>

  <Style name="style">
     <Rule>
       <TextSymbolizer size="15" name="[NAME_FORMA]" face-name="DejaVu Sans Book" halo-radius="1" />
     </Rule>    
   </Style>

  <Layer name="layer" srs="+init=epsg:3857">
     <StyleName>style</StyleName>
     <Datasource>
        <Parameter name="type">shape</Parameter>
        <Parameter name="file">data/1aa2d236-10m-admin-0-countries.shp</Parameter>
     </Datasource>
  </Layer>

</Map>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map srs="+init=epsg:3857">

  <Style name="style">
     <Rule>
       <LineSymbolizer rasterizer="fast"/>
       <TextSymbolizer size="15" name="[NAME_FORMA]" face-name="DejaVu Sans Book" halo-radius="1" />
     </Rule>    
   </Style>

  <Layer name="layer" srs="+init=epsg:3857" deferred-labels="true">
     <StyleName>style</StyleName>
     <Datasource>
        <Parameter name="type">shape</Parameter>
        <Parameter name="file">data/1aa2d236-10m-admin-0-countries.shp</Parameter>
     </Datasource>
  </Layer>

</Map>
@ALDean
ALDean commented Nov 22, 2011

Once the features are cached, I would like to be able to apply custom filtering to the cached features before they are labeled. This would allow aggregation of like named features (such as roads) or sorting based on localized context with the other features in the cache or any of various criteria besides LIFO vs. FIFO. The goal would be that the "FO" would be "the most important" in terms of meaning and context with respect to the other features on the map, and thus get "placement prioritization" So if the design could accommodate some kind of hook for a developer to implement custom "FO" criteria...that would be fantastic. Thanks.

@springmeyer
Member

@ALDean - yeah, could be cool :) We'll get back to this at some point.

@ALDean
ALDean commented Aug 23, 2012

Thanks!  I will watch for anything to develop along those lines. 

I have poked around a bit in the mapnik source weighing the possibilities of doing something in this regard myself.      I concluded (around the time of my original comment) it would be a pretty steep learning curve for anyone (myself), unfamiliar with the code to design a really good feature cache.  It would be too easy to focus on my narrow use requirements and be unaware of other meaningful purposes it could and should support.    And other priorities being what they are :) took precedence for awhile.    Nevertheless,  I may yet get back to it and take a stab at experimenting with personalized customization along these lines of thought.   I am kind of waiting right now for some of the dust to settle from the 2012 Summer of Code work and see if the vertex cache developed in support of some of the text placement improvements may provide better footing for this kind of development. 

Thanks,
Anne-Leslie Dean


From: Dane Springmeyer notifications@github.com
To: mapnik/mapnik mapnik@noreply.github.com
Cc: ALDean AnneLDean@yahoo.com
Sent: Thursday, August 23, 2012 1:19 PM
Subject: Re: [mapnik] Label cache (#870)

@ALDean - yeah, could be cool :) We'll get back to this at some point.

Reply to this email directly or view it on GitHub.

@springmeyer
Member

Anne,

Great, thanks for your interest!

@springmeyer springmeyer self-assigned this Jul 30, 2014
@springmeyer springmeyer added the mustfix label Jul 30, 2014
@springmeyer springmeyer removed this from the Mapnik 3.x milestone Jul 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment