Misunderstand extent property and performance problem

37 views
Skip to first unread message

Cường Văn

unread,
Mar 1, 2017, 2:50:32 AM3/1/17
to mapnik
Hello everyone,
Good news is I've already run successful mapnik nodejs with postgis.
I set Map projection is: +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over
Layer projection is: +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
and no extent value in postgis setting.

In the code sample, both map and layer projection is the same and equal: +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over
with extent value is: -20005048.4188,-9039211.13765,19907487.2779,17096598.5401

to be honest, I do not understand the role of extent in postgis configuration, the explanation in https://github.com/mapnik/mapnik/wiki/PostGIS is insufficient for me (a newbie to geographic area), whether this property affect to rendering performance or not and how I can get the suitable value for extent, in my case, I just render tile for specific area on the map.

Really appreciate to receive any feedback from you guys, Thank you in advance.

Regard.

Jukka Rahkonen

unread,
Mar 1, 2017, 3:18:50 AM3/1/17
to map...@googlegroups.com, Cường Văn
Cường Văn kirjoitti 2017-03-01 09:50:
Hi,

My understanding is that Mapnik does not even try to read data if it is
rendering something that is not at least partly inside the layer extent.
It saves a little bit time but how much depends on the datasource and
how expensive it is to make a connention or take one from connection
pool, fetch data from an area that does not have data, and get back an
empty result. If you are rendering an area where you have data it is
just the same if you define layer extent or not. I feel, but I do not
have real measurements, that PostGIS and shapefiles are returning empty
result set very fast if spatial indexes are present and using tight
extent would not give any huge speed-up. It is still a speed-up and thus
positive. The negative side is that if you give wrong extent and you
actually have some data beyound that then some features will be missing
from your maps. That happens in real life if you create new layers with
copy-paste and you forget to check that extent suits with the new data.

-Jukka Rahkonen-
> --
> You received this message because you are subscribed to the Google
> Groups "mapnik" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to mapnik+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Cường Văn

unread,
Mar 1, 2017, 3:56:06 AM3/1/17
to mapnik, bavuon...@gmail.com, jukka.r...@latuviitta.fi
Thank you Jukka, let's me clarify what I understand from your answer:

- Mapnik does not even try to read data: for example, postgis return some data, which includes some redundant value from Norway, and I define extent value belong to Switzerland, the area I want tiles are rendered, so mapnik will base on extent value and skip reading data from Norway.
- Extent value is defined to limit the area on map for rendering tile, so it just affects on rendering time, not fetching data from db time. It leads to that if I do not provide extent value, mapnik will draw whole map, even if some tiles is transparent due to no data. so I should provide suitable extent value to optimize rendering time.

Please let's me know if I'm wrong

Regard,
Cuong.

Jukka Rahkonen

unread,
Mar 1, 2017, 4:42:09 AM3/1/17
to map...@googlegroups.com, bavuon...@gmail.com
Cường Văn kirjoitti 2017-03-01 10:56:
> Thank you Jukka, let's me clarify what I understand from your answer:
>
> - Mapnik does not even try to read data: for example, postgis return
> some data, which includes some redundant value from Norway, and I
> define extent value belong to Switzerland, the area I want tiles are
> rendered, so mapnik will base on extent value and skip reading data
> from Norway.

Not quite so. Mapnik will never read data (features) from Norway if you
render Switzerland because it knows by the spatial index which features
it must read for rendering the desired tile. But if you define that
extent is bounding box of Switzerland and you render tiles from Norway,
then Mapnik skips the whole layer without communicating with PostGIS at
all. The saving is that there is no need to make a query from spatial
index which is fast but still takes some time.

Actually, by reading the documentation Mapnik is using the default
extent "determined by querying the metadata for the table" so not even a
query from the spatial index is performed. Thus the saving that is left
comes from taking a connection from pool and readin one line from the
metadata which means that it is very fast. I would guess that in normal
cases it is not worth the trouble to play with extent setting at all.
Rendering itself is the heavy part and most time is spent for that.

> - Extent value is defined to limit the area on map for rendering tile,
> so it just affects on rendering time, not fetching data from db time.
> It leads to that if I do not provide extent value, mapnik will draw
> whole map, even if some tiles is transparent due to no data. so I
> should provide suitable extent value to optimize rendering time.

Extent has no effect on what area will be rendered. It is only a
shortcut for Mapnik to deside if it simply skips the layer or if it will
try to find data for the tile from the database. It is a layerwise
setting, so if you have some global layers like shoreline they will be
rendered to the tiles of Norway even if some layer containing data
merely from Switzerland is skipped.

-Jukka-
>>> https://github.com/mapnik/mapnik/wiki/PostGIS [1] is insufficient
>> for me
>>> (a newbie to geographic area), whether this property affect to
>>> rendering performance or not and how I can get the suitable value
>> for
>>> extent, in my case, I just render tile for specific area on the
>> map.
>>>
>>> Really appreciate to receive any feedback from you guys, Thank you
>> in
>>> advance.
>>>
>>> Regard.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>
>>> Groups "mapnik" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>> send
>>> an email to mapnik+un...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout [2].
>
> --
> You received this message because you are subscribed to the Google
> Groups "mapnik" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to mapnik+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> Links:
> ------
> [1] https://github.com/mapnik/mapnik/wiki/PostGIS
> [2] https://groups.google.com/d/optout
Reply all
Reply to author
Forward
0 new messages