How to use mappyfile - 10 common examples

To help you get started, we’ve selected a few mappyfile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geographika / mappyfile / tests / test_parser.py View on Github external
def output(s):
    p = Parser()
    m = MapfileToDict()
    
    ast = p.parse(s)
    print(ast)
    d = m.transform(ast)
    pp = PrettyPrinter(indent=0, newlinechar=" ")
    return pp.pprint(d)
github geographika / mappyfile / mappyfile / test_transformer.py View on Github external
import os
from pprint import pprint
from collections import defaultdict
from plyplus import STransformer, is_stree

from mappyfile.tokens import ATTRIBUTE_NAMES, COMPOSITE_NAMES
from mappyfile.parser import Parser

from mappyfile.transformer import MapFile2Dict__Transformer

parser = Parser(try_ply=False)
ast = parser.parse_file('./tests/sample_maps/labels-bitmap-multiline.map')

m = MapFile2Dict__Transformer()
pprint (m.transform(ast))

def main():
    DIR = './tests/sample_maps/'
    for fn in os.listdir(DIR):
        print fn
        ast = parser.parse_file(DIR+fn)
        (m.transform(ast))


if __name__ == '__main__':
    main()
github geographika / mappyfile / tests / test_pprint3.py View on Github external
#ast = parser.parse_file('./tests/sample_maps/256_overlay_res.map')
    #ast = parser.parse_file('./tests/sample_maps/class16_oddscale.map')
    #ast = parser.parse_file('./tests/sample_maps/class16_range.map')
    #ast = parser.parse_file('./tests/sample_maps/wmsclient_3543.map')
    #ast = parser.parse_file('./tests/sample_maps/heat.map')

    #ast = parser.parse_file('./tests/sample_maps/labelpnt.map')
    #ast = parser.parse_file('./tests/sample_maps/maxfeatures.map')

    #ast = parser.parse_file(r'C:\Temp\msautotest\query\include\bdry_counpy2_shapefile.map', is_subcomponent=True)


    #print ast.tail[0]
    #return
    cwd = r"C:\Temp\msautotest\query"
    parser = Parser(try_ply=True, cwd=cwd)

    ast = parser.parse_file('./tests/sample_maps/query.map')


    m = MapFile2Dict__Transformer()

    d = (m.transform(ast)) # works

    dpp = pprint.PrettyPrinter()
    print dpp.pprint(d)

    pp = PrettyPrinter()
    print pp.pprint(d)
github geographika / mappyfile / tests / test_pprint.py View on Github external
EXTENT 0 0 100 100
        DEBUG on
        NAME Test
        shapepath "test/path"
        LAYER
            CLASSITEM "Test"
            CLASS
                EXPRESSION "Field"
                STYLE
                    SIZE [sizefield]
                END
            END
        END
    END
    """
    p = Parser()
    m = MapfileToDict()
    ast = p.parse(s)
    d = m.transform(ast)
    print(d)
    logging.debug(json.dumps(d, indent=4))
    pp = PrettyPrinter(indent=4, quote="'", newlinechar="\n")
    res = pp.pprint(d)
    print(res)
github geographika / mappyfile / tests / test_sample_maps.py View on Github external
def test_non_ascii():
    p = Parser()

    ast = p.parse_file('./tests/samples/non_ascii.map')
    m = MapfileToDict()

    d = (m.transform(ast))  # works
    print(mappyfile.dumps(d))
github geographika / mappyfile / tests / test_transformer.py View on Github external
def test_expression():

    s = """
    CLASS
        TEXT ([area])
        EXPRESSION ([area])
    END
    CLASS
        TEXT ("[area]")
        EXPRESSION ("[area]")
    END
    """
    p = Parser()
    ast = p.parse(s)
    t = MapfileToDict()
    d = t.transform(ast)
    print(d)
    print(json.dumps(d, indent=4))
    assert(d[0]["text"] == "([area])")
    assert(d[0]["expression"] == "([area])")
    assert(d[1]["text"] == "(\"[area]\")")
    assert(d[1]["expression"] == "(\"[area]\")")
github geographika / mappyfile / tests / test_validation.py View on Github external
def to_dict(s):
    p = Parser()
    m = MapfileToDict()
    ast = p.parse(s)
    d = m.transform(ast)
    print(json.dumps(d, indent=4))
    return d
github geographika / mappyfile / tests / test_errors.py View on Github external
def output(s):
    """
    Parse, transform, and pretty print
    the result
    """
    p = Parser()
    m = MapfileToDict()

    # https://stackoverflow.com/questions/900392/getting-the-caller-function-name-inside-another-function-in-python
    logging.info(inspect.stack()[1][3])

    ast = p.parse(s)
    logging.debug(ast)
    d = m.transform(ast)
    logging.debug(json.dumps(d, indent=4))
    pp = PrettyPrinter(indent=0, newlinechar=" ", quote="'")
    s = pp.pprint(d)
    logging.debug(s)
    return s
github geographika / mappyfile / tests / test_includes.py View on Github external
def test_includes_max_recursion():
    p = Parser()

    with pytest.raises(Exception) as excinfo:
        p.parse_file('./tests/samples/include1_recursive.map')

    assert('Maximum nested include exceeded' in str(excinfo.value))
github geographika / mappyfile / tests / test_pprint.py View on Github external
def test_join():
    d = {
        "__type__": "layer",
        "name": "Joined",
        "joins": [{
            "__type__": "join",
            "name": "table_join"
        }]
        }

    pp = PrettyPrinter(indent=0, quote="'", newlinechar=" ")
    d = collections.OrderedDict(sorted(d.items()))
    s = pp.pprint(d)
    assert(s == "LAYER JOIN NAME 'table_join' END NAME 'Joined' END")