mapnik ST_Intrersects and other SQL optimization
This commit is contained in:
parent
4f62910d7d
commit
041fcbcd51
2 changed files with 18 additions and 11 deletions
18
src/komap.py
18
src/komap.py
|
@ -262,7 +262,7 @@ if options.renderer == "mapnik":
|
|||
mfile.write(xml_g)
|
||||
sql = "(" + " OR ".join(sql) + ") and way && !bbox!"
|
||||
itags = add_numerics_to_itags(itags)
|
||||
mfile.write(xml_layer("postgis", "polygon", itags, sql ))
|
||||
mfile.write(xml_layer("postgis", "polygon", itags, sql, zoom=zoom ))
|
||||
else:
|
||||
xml_nolayer()
|
||||
for layer_type, entry_types in [("polygon",("way","area")),("line",("way", "line"))]:
|
||||
|
@ -330,7 +330,7 @@ if options.renderer == "mapnik":
|
|||
elif zlayer <=5 and zlayer >= -5 and full_layering:
|
||||
sql = "("+ sql +') and "layer" = \'%s\''%zlayer
|
||||
itags = add_numerics_to_itags(itags)
|
||||
mfile.write(xml_layer("postgis", layer_type, itags, sql ))
|
||||
mfile.write(xml_layer("postgis", layer_type, itags, sql, zoom=zoom ))
|
||||
else:
|
||||
xml_nolayer()
|
||||
|
||||
|
@ -439,7 +439,7 @@ if options.renderer == "mapnik":
|
|||
itags = ", ".join(itags)
|
||||
oitags = '"'+ "\", \"".join(oitags) +'"'
|
||||
sqlz = """SELECT %s, ST_ForceRHR(way) as way from planet_osm_polygon where (%s) and way && !bbox! and ST_IsValid(way)"""%(itags,sql)
|
||||
mfile.write(xml_layer("postgis-process", layer_type, itags, sqlz ))
|
||||
mfile.write(xml_layer("postgis-process", layer_type, itags, sqlz, zoom=zoom ))
|
||||
|
||||
|
||||
#### FIXME: Performance degrades painfully on large lines ST_Union. Gotta find workaround :(
|
||||
|
@ -454,9 +454,9 @@ if options.renderer == "mapnik":
|
|||
## sqlz = """select %s, ST_Union(way) as way from (SELECT * from planet_osm_line where way && !bbox! #and (%s)) as tex
|
||||
## group by %s
|
||||
## """%(itags,sql,oitags)
|
||||
#mfile.write(xml_layer("postgis-process", layer_type, itags, sqlz ))
|
||||
#mfile.write(xml_layer("postgis-process", layer_type, itags, sqlz, zoom=zoom ))
|
||||
else:
|
||||
mfile.write(xml_layer("postgis", layer_type, itags, sql ))
|
||||
mfile.write(xml_layer("postgis", layer_type, itags, sql, zoom=zoom ))
|
||||
else:
|
||||
xml_nolayer()
|
||||
|
||||
|
@ -499,7 +499,7 @@ if options.renderer == "mapnik":
|
|||
mfile.write(xml_g)
|
||||
sql = "(" + " OR ".join(sql) + ") and way && !bbox!"
|
||||
itags = add_numerics_to_itags(itags)
|
||||
mfile.write(xml_layer("postgis", layer_type, itags, sql ))
|
||||
mfile.write(xml_layer("postgis", layer_type, itags, sql, zoom=zoom ))
|
||||
else:
|
||||
xml_nolayer()
|
||||
ta.reverse()
|
||||
|
@ -601,7 +601,7 @@ if options.renderer == "mapnik":
|
|||
where (%s) and way_area > %s and p.way && ST_Expand(!bbox!,%s) and (%s)) p
|
||||
group by %s) p %s ST_Area(p.way) desc
|
||||
"""%(itags,oitags,pixel_size_at_zoom(zoom,10),oitags,layer_type,ttext,pixel_size_at_zoom(zoom,5)**2,max(pixel_size_at_zoom(zoom,20),3000),sqlz,oitags,order)
|
||||
mfile.write(xml_layer("postgis-process", layer_type, itags, sqlz, oitags ))
|
||||
mfile.write(xml_layer("postgis-process", layer_type, itags, sqlz, oitags, zoom=zoom ))
|
||||
elif layer_type == "line" and zoom < 15:
|
||||
sqlz = " OR ".join(sql)
|
||||
itags = ", ".join(itags)
|
||||
|
@ -610,10 +610,10 @@ if options.renderer == "mapnik":
|
|||
group by %s
|
||||
%s
|
||||
"""%(itags,max(pixel_size_at_zoom(zoom,20),3000),ttext,sqlz,oitags,order)
|
||||
mfile.write(xml_layer("postgis-process", layer_type, itags, sqlz ))
|
||||
mfile.write(xml_layer("postgis-process", layer_type, itags, sqlz, zoom=zoom ))
|
||||
else:
|
||||
sql = "(" + " OR ".join(sql) + ") and way && ST_Expand(!bbox!,%s) %s"%(max(pixel_size_at_zoom(zoom,20),3000),order)
|
||||
mfile.write(xml_layer("postgis", layer_type, itags, sql ))
|
||||
mfile.write(xml_layer("postgis", layer_type, itags, sql, zoom=zoom ))
|
||||
else:
|
||||
xml_nolayer()
|
||||
|
||||
|
|
|
@ -230,6 +230,11 @@ def xml_layer(type="postgis", geom="point", interesting_tags = "*", sql = "true"
|
|||
global substyles
|
||||
subs = "\n".join(["<StyleName>s%s</StyleName>"%i for i in substyles])
|
||||
substyles = []
|
||||
intersection_SQL = ""
|
||||
if zoom < 4:
|
||||
intersection_SQL = '<Parameter name="intersect_max_scale">1</Parameter>'
|
||||
elif zoom > 16:
|
||||
intersection_SQL = '<Parameter name="intersect_min_scale">500000000000</Parameter>'
|
||||
if type == "postgis":
|
||||
interesting_tags = list(interesting_tags)
|
||||
if '"' not in "".join(interesting_tags):
|
||||
|
@ -249,6 +254,7 @@ def xml_layer(type="postgis", geom="point", interesting_tags = "*", sql = "true"
|
|||
where %s
|
||||
) as text
|
||||
</Parameter>
|
||||
%s
|
||||
<Parameter name="type">postgis</Parameter>
|
||||
<Parameter name="user">%s</Parameter>
|
||||
<Parameter name="dbname">%s</Parameter>
|
||||
|
@ -258,7 +264,7 @@ def xml_layer(type="postgis", geom="point", interesting_tags = "*", sql = "true"
|
|||
<Parameter name="estimate_extent">false</Parameter>
|
||||
<Parameter name="extent">-20037508.342789244, -20037508.342780735, 20037508.342789244, 20037508.342780709</Parameter>
|
||||
</Datasource>
|
||||
</Layer>"""%(layer_id, db_proj, subs, interesting_tags, table_prefix, geom, sql, db_user, db_name, db_srid, table_prefix, geom)
|
||||
</Layer>"""%(layer_id, db_proj, subs, interesting_tags, table_prefix, geom, sql, intersection_SQL, db_user, db_name, db_srid, table_prefix, geom)
|
||||
elif type == "postgis-process":
|
||||
return """
|
||||
<Layer name="l%s" status="on" srs="%s">
|
||||
|
@ -268,6 +274,7 @@ def xml_layer(type="postgis", geom="point", interesting_tags = "*", sql = "true"
|
|||
(%s
|
||||
) as text
|
||||
</Parameter>
|
||||
%s
|
||||
<Parameter name="type">postgis</Parameter>
|
||||
<Parameter name="user">%s</Parameter>
|
||||
<Parameter name="dbname">%s</Parameter>
|
||||
|
@ -277,7 +284,7 @@ def xml_layer(type="postgis", geom="point", interesting_tags = "*", sql = "true"
|
|||
<Parameter name="estimate_extent">false</Parameter>
|
||||
<Parameter name="extent">-20037508.342789244, -20037508.342780735, 20037508.342789244, 20037508.342780709</Parameter>
|
||||
</Datasource>
|
||||
</Layer>"""%(layer_id, db_proj, subs, sql, db_user, db_name, db_srid, table_prefix, geom)
|
||||
</Layer>"""%(layer_id, db_proj, subs, sql, intersection_SQL, db_user, db_name, db_srid, table_prefix, geom)
|
||||
elif type == "coast":
|
||||
if zoom < 9:
|
||||
return """
|
||||
|
|
Loading…
Add table
Reference in a new issue