Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
NAME "Layer1"
TYPE POLYGON
END
LAYER
NAME "Layer2"
TYPE POLYGON
CLASS
NAME "Class1"
COLOR 0 0 -8
END
END
END
"""
d = mappyfile.loads(s)
cmp = mappyfile.find(d["layers"], "name", "Layer2")
assert cmp["name"] == "Layer2"
def dilation(mapfile):
line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])
ll = mappyfile.find(mapfile["layers"], "name", "line")
ll["features"][0]["wkt"] = "'%s'" % line.wkt
dilated = line.buffer(0.5, cap_style=3)
pl = mappyfile.find(mapfile["layers"], "name", "polygon")
pl["features"][0]["wkt"] = "'%s'" % dilated.wkt
mapfile["extent"] = " ".join(map(str, dilated.buffer(0.8).bounds))
return dilated
def erosion(mapfile, dilated):
"""
We will continue to work with the modified Mapfile
If we wanted to start from scratch we could simply reread it
"""
ll = mappyfile.find(mapfile["layers"], "name", "line")
ll["status"] = "OFF"
pl = mappyfile.find(mapfile["layers"], "name", "polygon")
# make a deep copy of the polygon layer in the Map
# so any modification are made to this layer only
pl2 = deepcopy(pl)
pl2["name"] = "newpolygon"
mapfile["layers"].append(pl2)
dilated = dilated.buffer(-0.3)
pl2["features"][0]["wkt"] = "'%s'" % dilated.wkt
style = pl["classes"][0]["styles"][0]
style["color"] = "'#999999'"
STYLE
COLOR 107 208 107
OUTLINECOLOR 2 2 2
WIDTH 1
END
END
END
"""
new_layer = mappyfile.loads(new_layer_string)
layers.insert(0, new_layer) # can insert the new layer at any index
assert(layers[0]['name'] == 'land')
# END OF ADD LAYER EXAMPLE
# START OF ADD CLASS EXAMPLE
# find a layer using its name
layer = mappyfile.find(mapfile["layers"], "name", "highlighted")
new_class_string = """
CLASS
NAME "highlights"
STYLE
COLOR 107 208 107
OUTLINECOLOR 2 2 2
WIDTH 1
END
END
"""
new_class = mappyfile.loads(new_class_string)
layer["classes"].insert(1, new_class) # can insert the new class at any index
assert(layer['classes'][1]['name'] == 'land')
def create_frame(mapfile, line, dist):
# get the polygon layer
pl = mappyfile.find(mapfile["layers"], "name", "polygon")
# buffer the line
dilated = line.buffer(dist, cap_style=3)
# now set the FEATURES in the Mapfile to be the WKT from Shapely
pl["features"][0]["wkt"] = "'%s'" % dilated.wkt
# create an image from this Mapfile
return create_image("animation_%s" % str(dist), mapfile, format="gif")
def erosion(mapfile, dilated):
"""
We will continue to work with the modified Mapfile
If we wanted to start from scratch we could simply reread it
"""
ll = mappyfile.find(mapfile["layers"], "name", "line")
ll["status"] = "OFF"
pl = mappyfile.find(mapfile["layers"], "name", "polygon")
# make a deep copy of the polygon layer in the Map
# so any modification are made to this layer only
pl2 = deepcopy(pl)
pl2["name"] = "newpolygon"
mapfile["layers"].append(pl2)
dilated = dilated.buffer(-0.3)
pl2["features"][0]["wkt"] = "'%s'" % dilated.wkt
style = pl["classes"][0]["styles"][0]
style["color"] = "'#999999'"
style["outlinecolor"] = "'#b2b2b2'"
def dilation(mapfile):
line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])
ll = mappyfile.find(mapfile["layers"], "name", "line")
ll["features"][0]["wkt"] = "'%s'" % line.wkt
dilated = line.buffer(0.5, cap_style=3)
pl = mappyfile.find(mapfile["layers"], "name", "polygon")
pl["features"][0]["wkt"] = "'%s'" % dilated.wkt
mapfile["extent"] = " ".join(map(str, dilated.buffer(0.8).bounds))
return dilated