Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_unicode_map():
with open('./tests/samples/unicode.map', "r") as mf_file:
mf = mappyfile.load(mf_file)
print(mappyfile.dumps(mf))
def test_save():
s = """MAP NAME "TEST" END"""
d = mappyfile.loads(s)
output_file = os.path.join(tempfile.mkdtemp(), 'test_mapfile.map')
mappyfile.save(d, output_file)
with open(output_file) as fp:
d = mappyfile.load(fp)
assert d["name"] == "TEST"
def test_include_from_filehandle():
fn = './tests/samples/include1.map'
with open(fn) as f:
d = mappyfile.load(f)
assert d["name"] == "include_test"
print(mappyfile.dumps(d))
def test_dump():
s = """MAP NAME "TEST" END"""
d = mappyfile.loads(s)
with tempfile.NamedTemporaryFile(mode="w+", delete=False) as fp:
mappyfile.dump(d, fp)
with open(fp.name) as fp:
d = mappyfile.load(fp)
assert d["name"] == "TEST"
import mappyfile
# load will accept a filename (loads will accept a string)
mapfile = mappyfile.load("./docs/examples/raster.map")
# print the map name
print(mapfile["name"]) # outputs "MyMap"
# access layers
layers = mapfile["layers"]
layer2 = layers[1] # access by index
# access classes in a layer
classes = layer2["classes"]
for c in classes:
print(c["name"])
def main():
mf = "./docs/examples/animation/animated_buffer.map"
mapfile = mappyfile.load(mf)
img_files = create_frames(mapfile)
create_animation(img_files)
import mappyfile
mapfile = mappyfile.load("./docs/examples/raster.map")
# START OF API EXAMPLE
# update the map name
mapfile["name"] = "MyNewMap"
# update the error file path in the map config section
# note key names will always need to be lower case
mapfile["config"]["ms_errorfile"] = "/ms4w/tmp/ms_error.txt"
mapfile["config"]["ON_MISSING_DATA"] = "IGNORE"
# currently will need to double-quote non-keyword properties
mapfile["web"]["metadata"]["wms_format"] = "'image/png'"
layers = mapfile["layers"]
layer = layers[0]