예제 #1
0
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"] = line.wkt

    dilated = line.buffer(0.5, cap_style=3)
    pl = mappyfile.find(mapfile["layers"], "name", "polygon")
    pl["features"][0]["wkt"] = dilated.wkt

    mapfile["extent"] = " ".join(map(str, dilated.buffer(0.8).bounds))
    return dilated
예제 #2
0
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")
예제 #3
0
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")
예제 #4
0
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"] = dilated.wkt

    style = pl["classes"][0]["styles"][0]
    style["color"] = "#999999"
    style["outlinecolor"] = "#b2b2b2"
예제 #5
0
def test():
    # START OF API EXAMPLE
    # load will accept a filename (loads will accept a string)
    mapfile = mappyfile.load("./docs/examples/raster.map")

    # search for a layer by name
    layer = mappyfile.find(mapfile['layers'], 'name', 'sea')
    print(layer['name'])  # "sea"

    # search for all layers in a group
    for layer in mappyfile.findall(mapfile['layers'], 'group', 'my_group'):
        print(layer['name'])

    # END OF API EXAMPLE
    assert (layer['name'] == 'sea')
예제 #6
0
def test():
    # START OF API EXAMPLE
    # load will accept a filename (loads will accept a string)
    mapfile = mappyfile.open("./docs/examples/raster.map")

    # search for a layer by name
    layer = mappyfile.find(mapfile['layers'], 'name', 'sea')
    print(layer['name']) # "sea"
       
    # search for all layers in a group
    for layer in mappyfile.findall(mapfile['layers'], 'group', 'my_group'):
        print(layer['name'])

    # END OF API EXAMPLE
    assert(layer['name'] == 'sea')
def changeLayerRange(layer, layerRange, userFString):

    userInitMap = f'{os.path.join(current_app.config["PERSONAL_FOLDERS_LOCATION"], userFString, "mapFiles/sentinel_index.map")}'
    userModifiedMap = f'{os.path.join(current_app.config["PERSONAL_FOLDERS_LOCATION"], userFString, "mapFiles/mapFilesModified", "sentinel_index_modified.map")}'

    layerRangeJSON = json.loads(layerRange.replace("\'", "\""))
    mapfile = mappyfile.open(userInitMap)

    # update the map name
    mapfile['name'] = 'sentinel_index_modified.map'

    ## Check for existing map file and delete in it exists.
    if os.path.exists(userModifiedMap):
        os.remove(userModifiedMap)

    # find a layer using its name
    layer = mappyfile.find(mapfile["layers"], "name", layer)
    # get class breaks and class colours from layerRange
    classBreaks = layerRangeJSON['classBreaks']
    classColours = layerRangeJSON['classColours']
    # define new mapfile classes empty string
    completeNewClassString = ''
    # iteraterate over class breaks and colours and insert their values to default class string. At the end append current string to string containing all classes
    for breaks,colours in zip(classBreaks,classColours):
        newClassString = f"""
    CLASS
        EXPRESSION ([pixel] >= {breaks[0]} AND [pixel] < {breaks[1]})
        STYLE
            COLORRANGE {colours[0][0]} {colours[0][1]} {colours[0][2]} {colours[1][0]} {colours[1][1]} {colours[1][2]}
            RANGEITEM 'pixel'
        END
    END
"""
        completeNewClassString += newClassString
    # load class string to map object
    newClasses = mappyfile.loads(completeNewClassString)
    layer["classes"] = newClasses
    # save new map file to disk and return path to it
    modifiedMapFile = mappyfile.dumps(mapfile)
    with open(userModifiedMap, "w")as mf:
        for li in modifiedMapFile:
            mf.write(li)
        mf.close 
    return {"modifiedMapFile": userModifiedMap}
예제 #8
0
def test_class():
    # START OF ADD CLASS EXAMPLE
    # find a layer using its name
    layer = mappyfile.find(mapfile["layers"], "name", "sea")

    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
    print(mappyfile.dumps(mapfile))

    # END OF ADD CLASS EXAMPLE
    assert (layer['classes'][1]['name'] == "highlights")

    # multiple classes
    # define all classes in a single string TODO - allow on single line
    classes = """
    CLASS 
	    NAME 'The World' 
	    STYLE 
        OUTLINECOLOR 0 255 0
        END
    END
	CLASS 
	    NAME 'Roads' 
	    STYLE
        OUTLINECOLOR 0 0 0
        END
    END
	"""
    # parse the string and replace the existing classes for the layer
    layer["classes"] = mappyfile.loads(classes)
    print(mappyfile.dumps(mapfile))
예제 #9
0
def test_class():
    # START OF ADD CLASS EXAMPLE
    # find a layer using its name
    layer = mappyfile.find(mapfile["layers"], "name", "sea")

    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
    print(mappyfile.dumps(mapfile))

    # END OF ADD CLASS EXAMPLE
    assert(layer['classes'][1]['name'] == "highlights")

    # multiple classes
	# define all classes in a single string TODO - allow on single line
    classes = """
    CLASS 
	    NAME 'The World' 
	    STYLE 
        OUTLINECOLOR 0 255 0
        END
    END
	CLASS 
	    NAME 'Roads' 
	    STYLE
        OUTLINECOLOR 0 0 0
        END
    END
	"""
    # parse the string and replace the existing classes for the layer
    layer["classes"] = mappyfile.loads(classes)
    print(mappyfile.dumps(mapfile))
예제 #10
0
def test_find():

    s = """
    MAP
        LAYER
            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"
예제 #11
0
import mappyfile_geojson
import geojson

gj = '''{
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [30, 10], [40, 40], [20, 40], [10, 20], [30, 10]
    ]
  }
}'''

# load a string into a GeoJSON object
gj = geojson.loads(gj)

# convert it to a mappyfile layer dict
layer = mappyfile_geojson.convert(gj, extent_buffer=10)

# now load a Mapfile
mf = mappyfile.load("example.map")
# find an existing layer by name
map_layer = mappyfile.find(mf["layers"], "name", "Polygon")
# apply the FEATURES from GeoJSON to the layer
map_layer.update(layer)
# update the map extent to the extent of the features
mf["extent"] = layer["extent"]
# we now have a layer populated from the GeoJSON
s = mappyfile.dumps(mf)
print(s)
예제 #12
0
    def __getMsSymbol(self, symbolname, props, ispolygon=False):
        """docstring for __getMsSymbol"""
        #SYMBOL [integer|string|filename|url|attribute]
        type_marker = _ms.MS_SYMBOL_SIMPLE
        props['name'] = u'circle'
        msSymbol = None
        #buscar si es un marcador conocido
        if symbolname in _qgis.MARKERS_WELL_KNOWN:
            props['name'] = symbolname
        elif symbolname in _qgis.MARKERS_ARROW:
            type_marker = _ms.MS_SYMBOL_ARROW
            props['name'] = symbolname
        else:
            match_url = _qgis.REGEX_URL.search(symbolname)
            match_file = _qgis.REGEX_FILE.search(symbolname)
            match_attr = _qgis.REGEX_ATTR.search(symbolname)

            if match_url:
                #url
                svgpath = FileManagement.url2svg(symbolname,
                                                 self.symbolsetpath)
                if svgpath:
                    props['name'] = svgpath
                    type_marker = _ms.MS_SYMBOL_SVG
            elif match_file:
                svgpath = FileManagement.file2svg(symbolname,
                                                  self.symbolsetpath)
                if svgpath:
                    props['name'] = svgpath
                    type_marker = _ms.MS_SYMBOL_SVG
            elif match_attr:
                #atributo
                props['name_dd_active'] = u'1'
                props['name_dd_field'] = match_attr.group(1)
            else:
                #QgsMarkerLineSymbolLayerV2 o QgsArrowSymbolLayer
                if self.mssymbols:
                    if isinstance(symbolname, (int, long)):
                        #indice en el symbolset, empieza por 1:
                        msSymbol = self.mssymbols[symbolname - 1]
                        symbolname = msSymbol.get('name')
                    else:
                        #buscar en el symbolset el simbolo por nombre
                        msSymbol = mappyfile.find(self.mssymbols, 'name',
                                                  symbolname)

                if msSymbol:
                    #print("Tiene simbolo")
                    if symbolname in _qgis.MARKERS_WELL_KNOWN:
                        #print("Tiene simbolo conocido")
                        props['name'] = symbolname
                    elif symbolname in _qgis.MARKERS_ARROW:
                        #print("Tiene simbolo de flecha")
                        type_marker = _ms.MS_SYMBOL_ARROW
                        props['name'] = symbolname
                    else:
                        #print("Busquemos otro tipo de simbolo")
                        symbol_type = msSymbol.get('type').lower()
                        if symbol_type == _ms.MS_SYMBOL_SIMPLE:
                            #type_marker = _ms.MS_SYMBOL_SIMPLE
                            type_marker = ''
                        elif symbol_type == _ms.MS_SYMBOL_VECTOR:
                            #print("Tiene simbolo de tipo vector")
                            #print(self.symbolsetpath)
                            svgpath = FileManagement.vector2svg(
                                msSymbol, self.symbolsetpath)
                            #print(svgpath)
                            if svgpath:
                                props['name'] = svgpath
                                type_marker = _ms.MS_SYMBOL_SVG
                        elif symbol_type == _ms.MS_SYMBOL_ELLIPSE:
                            #print("Tiene simbolo de tipo ellipse")
                            svgpath = FileManagement.ellipse2svg(
                                msSymbol, self.symbolsetpath)
                            if svgpath:
                                props['name'] = svgpath
                                type_marker = _ms.MS_SYMBOL_SVG
                            else:
                                #en este momento no es conocido,
                                #pero aplicar symbol layer de tipo elipse
                                #o usar circulo por defecto?
                                type_marker = _ms.MS_SYMBOL_ELLIPSE
                        elif symbol_type == _ms.MS_SYMBOL_SVG:
                            #print("Tiene simbolo de tipo svg")
                            props['name'] = Util.abspath(
                                self.symbolsetpath, '', msSymbol.get('image'))
                            type_marker = _ms.MS_SYMBOL_SVG
                        elif symbol_type == _ms.MS_SYMBOL_PIXMAP:
                            #print("Tiene simbolo de tipo pixmap")
                            if ispolygon:
                                type_marker = _ms.MS_SYMBOL_PIXMAP
                            else:
                                svgpath = FileManagement.pixmap2svg(
                                    msSymbol.get('image'), self.symbolsetpath)
                                if svgpath:
                                    props['name'] = svgpath
                                    type_marker = _ms.MS_SYMBOL_SVG
                        elif symbol_type == _ms.MS_SYMBOL_HATCH:
                            #para poligonos
                            type_marker = _ms.MS_SYMBOL_HATCH if ispolygon else _ms.MS_SYMBOL_SIMPLE
                        elif symbol_type == _ms.MS_SYMBOL_TRUETYPE:
                            #print("Tiene simbolo de tipo truetype")
                            font = msSymbol.get('font', '')
                            if self.fontset and font:
                                props['font'] = Util.getFont(
                                    self.fontset.get(font))
                            else:
                                props['font'] = Util.getFont(font)
                            props['chr'] = self.__getChr(
                                msSymbol.get('character', ''))
                            type_marker = _ms.MS_SYMBOL_TRUETYPE
        #print((type_marker, symbolname, msSymbol, props))
        return (type_marker, symbolname, msSymbol, props)