planetfederal / qgis-suite-plugin

GNU General Public License v2.0
25 stars 17 forks source link

SLD stroke-width is not converted to 'pixels' on layer publishing #183

Open kitzilla opened 9 years ago

kitzilla commented 9 years ago

When publishing a layer to GeoServer through Opengeo Explorer, some css parameters like stroke-width and stroke-dasharray are not converted from QGIS's unit system (millimeters) to GeoServer's (pixels).

Since I am new to git and I could not push my fixes to this repo, I would paste them here as a suggestion,

To opengeo/qgis/sldadapter.py _1. Add the following function

def convertMMtoPx(regexPattern, string):
    for m in re.finditer(regexPattern, string):
        if m.lastindex < 1:
            continue
        string = '%s%s%s' % (string[:m.start(1)], float(m.group(1)) * SIZE_FACTOR, string[m.end(1):])
    return string

_2. Insert the following lines to adaptQgsToGs function (between line 40 and 41)

    sld = convertMMtoPx(r'<CssParameter name="stroke-width">\s*(\d+\.?\d*|\d*\.\d+)\s*</CssParameter>', sld)
    sld = convertMMtoPx(r'<CssParameter name="stroke-dashoffset">\s*(\d+\.?\d*|\d*\.\d+)\s*</CssParameter>', sld)
    for m in re.finditer(r'<CssParameter name="stroke-dasharray">([\s\d\.]+)</CssParameter>', sld):
        if m.lastindex > 0:
            nums = [ str(float(n) * SIZE_FACTOR) for n in re.split(r'\s+', m.group(1)) ] 
            sld = '%s<CssParameter name="stroke-dasharray">%s</CssParameter>%s' % (sld[:m.start()], ' '.join(nums), sld[m.end():])