Support for merging consecutive lines text
This commit is contained in:
parent
750e24503c
commit
0783b00989
2 changed files with 61 additions and 29 deletions
17
src/komap.py
17
src/komap.py
|
@ -183,6 +183,7 @@ for zoom, zsheet in mapniksheet.iteritems():
|
|||
## text pass
|
||||
sql = set()
|
||||
itags = set()
|
||||
ttext = ""
|
||||
xml = xml_style_start()
|
||||
for entry in zsheet[zindex]:
|
||||
if entry["type"] in entry_types:#, "node", "line", "point"):
|
||||
|
@ -195,11 +196,13 @@ for zoom, zsheet in mapniksheet.iteritems():
|
|||
thradius= entry["style"].get("text-halo-radius","0")
|
||||
tplace= entry["style"].get("text-position","center")
|
||||
toffset= entry["style"].get("text-offset","0")
|
||||
toverlap= entry["style"].get("text-allow-overlap",entry["style"].get("allow-overlap","false"))
|
||||
|
||||
xml += xml_rule_start()
|
||||
xml += x_scale
|
||||
rulestring = " or ".join([ "("+ " and ".join([i.get_mapnik_filter() for i in rule]) + ")" for rule in entry["rule"]])
|
||||
xml += xml_filter(rulestring)
|
||||
xml += xml_textsymbolizer(ttext,tface,tsize,tcolor, thcolor, thradius, tplace, toffset)
|
||||
xml += xml_textsymbolizer(ttext,tface,tsize,tcolor, thcolor, thradius, tplace, toffset,toverlap)
|
||||
sql.update(entry["sql"])
|
||||
itags.update(entry["chooser"].get_interesting_tags(entry["type"], zoom))
|
||||
xml += xml_rule_end()
|
||||
|
@ -207,7 +210,17 @@ for zoom, zsheet in mapniksheet.iteritems():
|
|||
xml += xml_style_end()
|
||||
if sql:
|
||||
mfile.write(xml)
|
||||
mfile.write(xml_layer("postgis", layer_type, itags, sql ))
|
||||
if layer_type == "line":
|
||||
sqlz = " OR ".join(sql)
|
||||
itags = "\", \"".join(itags)
|
||||
itags = "\""+ itags+"\""
|
||||
sqlz = """with aaa as (SELECT %s, way FROM planet_osm_line where "%s" is not NULL and (%s)),
|
||||
bbb as (SELECT %s, way from aaa where way && !bbox! )
|
||||
select %s, ST_LineMerge(ST_Union(way)) as way from bbb group by %s
|
||||
"""%(itags,ttext,sqlz,itags,itags,itags)
|
||||
mfile.write(xml_layer("postgis-process", layer_type, itags, sqlz ))
|
||||
else:
|
||||
mfile.write(xml_layer("postgis", layer_type, itags, sql ))
|
||||
else:
|
||||
xml_nolayer()
|
||||
|
||||
|
|
|
@ -92,13 +92,14 @@ def xml_polygonsymbolizer(color="#000000", opacity="1"):
|
|||
<CssParameter name="fill-opacity">%s</CssParameter>
|
||||
</PolygonSymbolizer>"""%(color, float(opacity))
|
||||
|
||||
def xml_textsymbolizer(text="name",face="DejaVu Sans Book",size="10",color="#000000", halo_color="#ffffff", halo_radius="0", placement="line", offset="0"):
|
||||
def xml_textsymbolizer(text="name",face="DejaVu Sans Book",size="10",color="#000000", halo_color="#ffffff", halo_radius="0", placement="line", offset="0", overlap="false"):
|
||||
color = nicecolor(color)
|
||||
halo_color = nicecolor(halo_color)
|
||||
placement = {"center": "point"}.get(placement.lower(), placement)
|
||||
|
||||
return """
|
||||
<TextSymbolizer name="%s" face_name="%s" size="%s" fill="%s" halo_fill= "%s" halo_radius="%s" placement="%s" allow_overlap="false" dy="%s"/>
|
||||
"""%(text,face,size,color,halo_color,halo_radius,placement,offset)
|
||||
<TextSymbolizer name="%s" face_name="%s" size="%s" fill="%s" halo_fill= "%s" halo_radius="%s" placement="%s" dy="%s" max_char_angle_delta="15" allow_overlap="%s"/>
|
||||
"""%(text,face,size,color,halo_color,halo_radius,placement,offset,overlap)
|
||||
|
||||
def xml_filter(string):
|
||||
return """
|
||||
|
@ -144,33 +145,51 @@ def xml_rule_end():
|
|||
|
||||
|
||||
def xml_layer(type="postgis", geom="point", interesting_tags = "*", sql = ["true"] ):
|
||||
layer_id = get_id(1) ## increment by 0 - was incremented in style
|
||||
interesting_tags = "\", \"".join(interesting_tags)
|
||||
interesting_tags = "\""+ interesting_tags+"\""
|
||||
sql = " OR ".join(sql)
|
||||
layer_id = get_id(1)
|
||||
global substyles
|
||||
subs = "\n".join(["<StyleName>s%s</StyleName>"%i for i in substyles])
|
||||
substyles = []
|
||||
|
||||
return """
|
||||
<Layer name="l%s" status="on" srs="%s">
|
||||
%s
|
||||
<Datasource>
|
||||
<Parameter name="table">
|
||||
(select %s, way
|
||||
from %s%s
|
||||
where %s
|
||||
) as text
|
||||
</Parameter>
|
||||
<Parameter name="type">postgis</Parameter>
|
||||
<Parameter name="user">%s</Parameter>
|
||||
<Parameter name="dbname">%s</Parameter>
|
||||
<Parameter name="srid">%s</Parameter>
|
||||
<Parameter name="geometry_field">way</Parameter>
|
||||
<Parameter name="geometry_table">%s%s</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)
|
||||
if type == "postgis":
|
||||
interesting_tags = "\", \"".join(interesting_tags)
|
||||
interesting_tags = "\""+ interesting_tags+"\""
|
||||
sql = " OR ".join(sql)
|
||||
return """
|
||||
<Layer name="l%s" status="on" srs="%s">
|
||||
%s
|
||||
<Datasource>
|
||||
<Parameter name="table">
|
||||
(select %s, way
|
||||
from %s%s
|
||||
where %s
|
||||
) as text
|
||||
</Parameter>
|
||||
<Parameter name="type">postgis</Parameter>
|
||||
<Parameter name="user">%s</Parameter>
|
||||
<Parameter name="dbname">%s</Parameter>
|
||||
<Parameter name="srid">%s</Parameter>
|
||||
<Parameter name="geometry_field">way</Parameter>
|
||||
<Parameter name="geometry_table">%s%s</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)
|
||||
elif type == "postgis-process":
|
||||
return """
|
||||
<Layer name="l%s" status="on" srs="%s">
|
||||
%s
|
||||
<Datasource>
|
||||
<Parameter name="table">
|
||||
(%s
|
||||
) as text
|
||||
</Parameter>
|
||||
<Parameter name="type">postgis</Parameter>
|
||||
<Parameter name="user">%s</Parameter>
|
||||
<Parameter name="dbname">%s</Parameter>
|
||||
<Parameter name="srid">%s</Parameter>
|
||||
<Parameter name="geometry_field">way</Parameter>
|
||||
<Parameter name="geometry_table">%s%s</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)
|
||||
|
||||
def xml_nolayer():
|
||||
global substyles
|
||||
|
|
Loading…
Add table
Reference in a new issue