Support for polygons in Komap

This commit is contained in:
Komяpa 2010-09-28 17:10:54 +03:00
parent ed609237c9
commit 8167dec572
3 changed files with 74 additions and 14 deletions

View file

@ -20,6 +20,13 @@ from debug import debug, Timer
from mapcss import MapCSS
import sys
from libkomapnik import *
try:
import psyco
psyco.full()
except ImportError:
pass
minzoom = 10
maxzoom = 11
@ -67,9 +74,15 @@ for zoom, zsheet in mapniksheet.iteritems():
mfile.write(xml_style_start())
for entry in zsheet[zindex]:
if entry["type"] in ("way", "area", "polygon"):
sql.update(entry["sql"])
itags.update(entry["chooser"].get_interesting_tags(entry["type"], zoom))
if "fill-color" in entry["style"]:
mfile.write(xml_rule_start())
mfile.write(x_scale)
rulestring = " or ".join([rule[0].get_mapnik_filter() for rule in entry["rule"]])
mfile.write(xml_filter(rulestring))
mfile.write(xml_polygonsymbolizer(entry["style"].get("fill-color", "black"), entry["style"].get("fill-opacity", "1")))
sql.update(entry["sql"])
itags.update(entry["chooser"].get_interesting_tags(entry["type"], zoom))
mfile.write(xml_rule_end())
sql = [i[1] for i in sql]
#print sql, itags
mfile.write(xml_style_end())

View file

@ -28,6 +28,8 @@ db_user = "mapz"
db_name = "gis"
substyles = []
last_id = 0
@ -55,7 +57,8 @@ def xml_linesymbolizer(color="#000000", width="1", opacity="1", linecap="butt",
return """
<LineSymbolizer>
<CssParameter name="stroke">%s</CssParameter>
<CssParameter name="stroke-width">%f</CssParameter>
<CssParameter name="stroke-width">%s</CssParameter>
<CssParameter name="stroke-opacity">%s</CssParameter>
<CssParameter name="stroke-linejoin">%s</CssParameter>
<CssParameter name="stroke-linecap">%s</CssParameter>
</LineSymbolizer>"""(color, float(width), float(opacity), linejoin, linecap)
@ -63,15 +66,16 @@ def xml_linesymbolizer(color="#000000", width="1", opacity="1", linecap="butt",
def xml_polygonsymbolizer(color="#000000", opacity="1"):
color = nicecolor(color)
linecap = {"none":"butt",}.get(linecap.lower(), linecap)
return """
<LineSymbolizer>
<CssParameter name="stroke">%s</CssParameter>
<CssParameter name="stroke-width">%f</CssParameter>
</LineSymbolizer>"""(color, float(width), float(opacity), linejoin, linecap)
<PolygonSymbolizer>
<CssParameter name="fill">%s</CssParameter>
<CssParameter name="fill-opacity">%s</CssParameter>
</PolygonSymbolizer>"""%(color, float(opacity))
def xml_filter(string):
return """
<Filter>%s</Filter>"""%string
def xml_scaledenominator(z1, z2=False):
z1, z2 = zoom_to_scaledenom(z1,z2)
@ -92,7 +96,9 @@ def xml_end():
def xml_style_start():
global substyles
layer_id = get_id(1)
substyles.append(layer_id)
return """
<Style name="s%s">"""%(layer_id)
@ -101,15 +107,27 @@ def xml_style_end():
return """
</Style>"""
def xml_rule_start():
return """
<Rule>"""
def xml_rule_end():
return """
</Rule>"""
def xml_layer(type="postgis", geom="point", interesting_tags = "*", sql = ["true","d"] ):
layer_id = get_id() ## increment by 0 - was incremented in style
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)
global substyles
subs = "\n".join(["<StyleName>s%s</StyleName>"%i for i in substyles])
substyles = []
return """
<Layer name="l%s" status="on" srs="%s">
<StyleName>s%s</StyleName>
%s
<Datasource>
<Parameter name="table">
(select %s, way
@ -121,4 +139,4 @@ def xml_layer(type="postgis", geom="point", interesting_tags = "*", sql = ["true
<Parameter name="user">%s</Parameter>
<Parameter name="dbname">%s</Parameter>
</Datasource>
</Layer>"""%(layer_id, db_proj, layer_id, interesting_tags, table_prefix, geom, sql, db_user, db_name)
</Layer>"""%(layer_id, db_proj, subs, interesting_tags, table_prefix, geom, sql, db_user, db_name)

View file

@ -101,6 +101,35 @@ class Condition:
return params[0], '"%s" IS NOT NULL'%(params[0])
except KeyError:
pass
def get_mapnik_filter(self):
params = [re.escape(x) for x in self.params]
t = self.type
try:
if t == 'eq':
return '[%s] = \'%s\''%(params[0], params[1])
if t == 'ne':
return 'not([%s] = \'%s\')'%(params[0], params[1])
if t == 'regex':
return '[%s].match(%s)'%(params[0], params[1])
if t == 'true':
return '[%s] = \'yes\''%(params[0])
if t == 'untrue':
return '[%s] = \'no\''%(params[0])
if t == 'set':
return 'not([%s] = \'\')'%(params[0])
if t == 'unset':
return '[%s] = \'\''%(params[0])
if t == '<':
return '"%s" &lt; %s'%(params[0], float(params[1]))
if t == '<=':
return '"%s" &lt;= %s'%(params[0], float(params[1]))
if t == '>':
return '"%s" &gt; %s'%(params[0], float(params[1]))
if t == '>=':
return '"%s" &gt;= %s'%(params[0], float(params[1]))
except KeyError:
pass
def __repr__(self):
return "%s %s "%(self.type, repr(self.params))
def Number(tt):