コード例 #1
0
import mapnik

m = mapnik.Map(1000, 700)
m.background = mapnik.Color('blue')
s = mapnik.Style()
r = mapnik.Rule()
polygon_symbolizer = mapnik.PolygonSymbolizer()
polygon_symbolizer.fill = mapnik.Color('#ff0000')
r.symbols.append(polygon_symbolizer)

line_symbolizer = mapnik.LineSymbolizer()
line_symbolizer = mapnik.LineSymbolizer(mapnik.Color('green'), 1)
line_symbolizer.stroke_width = 10.0

r.symbols.append(line_symbolizer)
s.rules.append(r)
m.append_style('Ari', s)
ds = mapnik.Shapefile(file="kabupaten/INDONESIA_KAB.shp")
layer = mapnik.Layer('world')
layer.datasource = ds
layer.styles.append('Ari')
m.layers.append(layer)
m.zoom_all()
mapnik.render_to_file(m, 'kabupaten.png', 'png')
print "rendered image to 'world.png'"
コード例 #2
0
ondrain_lyr.styles.append('drainage')
m.layers.append(ondrain_lyr)

# Provincial boundaries

provlines_lyr = mapnik.Layer('Provincial borders')
provlines_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
provlines_lyr.datasource = mapnik.Shapefile(
    file=path.join(root, '../data/boundaries_l'))

# Here we define a "dash dot dot dash" pattern for the provincial boundaries.

provlines_style = mapnik.Style()
provlines_rule = mapnik.Rule()
sym = mapnik.LineSymbolizer()
# FIXME - currently adding dash arrays is broken
# https://github.com/mapnik/mapnik/issues/2324
sym.stroke = mapnik.Color('black')
sym.stroke_width = 1.0
provlines_rule.symbols.append(sym)
provlines_style.rules.append(provlines_rule)

m.append_style('provlines', provlines_style)
provlines_lyr.styles.append('provlines')
m.layers.append(provlines_lyr)

# Roads 3 and 4 (The "grey" roads)

roads34_lyr = mapnik.Layer('Roads')
roads34_lyr.srs = "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"
コード例 #3
0
import mapnik

m = mapnik.Map(900, 400)
m.background = mapnik.Color('white')
s = mapnik.Style()
r = mapnik.Rule()
polygon_symbolizer = mapnik.PolygonSymbolizer()
polygon_symbolizer.fill = mapnik.Color('#FFD700')
r.symbols.append(polygon_symbolizer)

line_symbolizer = mapnik.LineSymbolizer()
line_symbolizer = mapnik.LineSymbolizer(mapnik.Color('blue'), 1)
line_symbolizer.stroke_width = 10.0

r.symbols.append(line_symbolizer)
s.rules.append(r)
m.append_style('Heri', s)
ds = mapnik.Shapefile(file="shp sawah/lu_sawah.shp")
layer = mapnik.Layer('sawah')
layer.datasource = ds
layer.styles.append('Heri')
m.layers.append(layer)
m.zoom_all()
mapnik.render_to_file(m, 'sawah.png', 'png')
print "rendered image to 'sawah.png'"
コード例 #4
0
ファイル: tugasgis2.py プロジェクト: Firdaus2402/Tugas-GIS
import mapnik
m = mapnik.Map(3840,2160)
m.background = mapnik.Color('steelblue')
s = mapnik.Style()
r = mapnik.Rule()
polygon_symbolizer = mapnik.PolygonSymbolizer()
polygon_symbolizer.fill = mapnik.Color('#C5E384')
r.symbols.append(polygon_symbolizer)

line_symbolizer = mapnik.LineSymbolizer()
line_symbolizer = mapnik.LineSymbolizer(mapnik.Color('white'),1)
line_symbolizer.stroke_width = 10.0

r.symbols.append(line_symbolizer)
s.rules.append(r)
m.append_style('Firdaus2',s)
ds = mapnik.Shapefile(file="countries/ne_110m_admin_0_countries.shp")
layer = mapnik.Layer('world')
layer.datasource = ds
layer.styles.append('Firdaus2')
m.layers.append(layer)


# MAP 1 CHINA
s = mapnik.Style()
r = mapnik.Rule()
polygon_symbolizer = mapnik.PolygonSymbolizer()
polygon_symbolizer.fill = mapnik.Color('#7FFF00')
r.symbols.append(polygon_symbolizer)

line_symbolizer = mapnik.LineSymbolizer()
コード例 #5
0
import tempfile

# Set up logging
logging.basicConfig(format="%(asctime)s|%(levelname)s|%(message)s",
                    level=logging.INFO)

# Parameters
shpPath = "C:/Projects/BirthsAndPregnanciesMapping/data/2014-04-24/Zanzibar/Zanzibar.shp"
epsDir = "C:/Projects/BirthsAndPregnanciesMapping/results/eps"
max_img_size = 1000  # Max width or height of output image

# Create style
stroke = mapnik.Stroke()
stroke.color = mapnik.Color(0, 0, 0)
stroke.width = 1.0
symbolizer = mapnik.LineSymbolizer(stroke)
rule = mapnik.Rule()
rule.symbols.append(symbolizer)
style = mapnik.Style()
style.rules.append(rule)

# Create Datasource
datasource = mapnik.Shapefile(file=shpPath)

# Create layer
layer = mapnik.Layer("boundaries")
layer.datasource = datasource
layer.styles.append("boundariesStyle")

# Calculate image output size
envelope = datasource.envelope()
コード例 #6
0
def createisomap(iso, mapscale, name, name_en):

    map_width = int(mapscale[0])
    map_height = int(mapscale[1])

    map_minx = float(mapscale[2])
    map_maxx = float(mapscale[3])
    map_miny = float(mapscale[4])
    map_maxy = float(mapscale[5])

    print "mapdata:", map_width, map_height, map_maxx, map_maxy, map_minx, map_miny

    m = mapnik.Map(
        map_width,
        map_height)  # create a map with a given width and height in pixels
    # note: m.srs will default to '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
    # the 'map.srs' is the target projection of the map and can be whatever you wish
    m.background = mapnik.Color(
        'steelblue')  # set background colour to 'steelblue'.

    s = mapnik.Style()  # style object to hold rules
    r = mapnik.Rule()  # rule object to hold symbolizers
    # to fill a polygon we create a PolygonSymbolizer

    psymbolizer = mapnik.PolygonSymbolizer()
    psymbolizer.fill = mapnik.Color('#f2eff9')
    r.symbols.append(psymbolizer)

    lsymbolizer = mapnik.LineSymbolizer()
    lsymbolizer.stroke = mapnik.Color('rgb(50%,50%,50%)')
    lsymbolizer.stroke_width = 0.1
    r.symbols.append(lsymbolizer)

    s.rules.append(r)  # now add the rule to the style and we're done

    m.append_style(
        'My Style',
        s)  # Styles are given names only as they are applied to the map

    ds = mapnik.Shapefile(file='/osm/setup/ne_10m_admin_0_countries.shp')

    ds.envelope()

    layer = mapnik.Layer(
        'world')  # new layer called 'world' (we could name it anything)
    # note: layer.srs will default to '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'

    layer.datasource = ds
    layer.styles.append('My Style')

    m.layers.append(layer)

    bbox = mapnik.Box2d(map_maxx, map_maxy, map_minx, map_miny)
    m.zoom_to_box(bbox)

    # .zoom_to_box(mapnik.Box2d(   ))
    # m.zoom_all()

    # Write the data to a png image called world.png the current directory

    img_directory = '/osm/service/' + CONTINENT + '/' + iso + '/img/'
    if not os.path.exists(img_directory):
        os.makedirs(img_directory)

    mapnik.render_to_file(m, img_directory + 'dbackground.png', 'png')

    ######################  flag ##################################

    copyfile('/osm/setup/dflag.png', img_directory + 'dflag.png')

    ####################  Logo #####################################

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 348, 98)
    ctx = cairo.Context(surface)
    ctx.select_font_face("Courier", cairo.FONT_SLANT_NORMAL,
                         cairo.FONT_WEIGHT_BOLD)

    ctx.set_font_size(42)
    ctx.move_to(2, 50)
    ctx.set_source_rgb(0.0, 0.0, 0.15)
    ctx.show_text('Taginfo-' + CONTINENT + '-' + iso)

    ctx.select_font_face('Sans')
    if len(name_en) > 26:
        ctx.set_font_size(20)
    elif len(name_en) > 18:
        ctx.set_font_size(26)
    else:
        ctx.set_font_size(30)

    ctx.move_to(1, 90)
    ctx.set_source_rgb(0.0, 0.0, 0.35)
    ctx.show_text(name_en)

    # finish up
    ctx.stroke()
    surface.write_to_png(img_directory + 'dlogo.png')
コード例 #7
0
#!/usr/bin/env python2
import mapnik

SHAPE_FILE = 'data/Voter_Precinct.shp'

symbolizer = mapnik.PolygonSymbolizer(mapnik.Color("#FFEEEE"))

rule = mapnik.Rule()
rule.symbols.append(symbolizer)

style = mapnik.Style()
style.rules.append(rule)

symbolizer = mapnik.LineSymbolizer()
symbolizer.stroke = mapnik.Stroke(mapnik.Color("#000000"), 1)
rule.symbols.append(symbolizer)
style.rules.append(rule)

layer = mapnik.Layer("map_layer")
layer.datasource = mapnik.Shapefile(file=SHAPE_FILE)
layer.styles.append("map_style")

map1 = mapnik.Map(1024, 1024)
map1.background = mapnik.Color("#EEFFEE")
map1.append_style("map_style", style)
map1.layers.append(layer)

map1.zoom_all()
mapnik.render_to_file(map1, "arl_voter_precinct_map.png", "png")
コード例 #8
0
def getMapImage(osmFile, map_output):
    '''Uses the data from the osmFile to out a .png image
       of the area depicted by the input file'''

    if not HAS_MAPNIK:
        print('Error: Mapnik module is missing. ' +
              'Please install for getting the image functionality.')
        return -2

    print('Has Mapnik.')

    if osmFile == '':
        print('Error: getMapImage::No File Recieved')
        return -1
    else:
        print('OSM File: ' + osmFile)

    highwayList = dict({
        "motorway": {
            'width': 4,
            'color': 'green',
            'fontSize': 12
        },
        "trunk": {
            'width': 3,
            'color': 'green',
            'fontSize': 11
        },
        "primary": {
            'width': 1.5,
            'color': '#0090ff',
            'fontSize': 10
        },
        "secondary": {
            'width': 0.8,
            'color': '#ff00ff',
            'fontSize': 8
        },
        "tertiary": {
            'width': 0.42,
            'color': '#000000',
            'fontSize': 8
        },
        "residential": {
            'width': 0.21,
            'color': 'black',
            'fontSize': 8
        },
        "living_street": {
            'width': 0.21,
            'color': 'black',
            'fontSize': 8
        },
        "pedestrian": {
            'width': 0.21,
            'color': 'brown',
            'fontSize': 8
        },
        "footway": {
            'width': 0.21,
            'color': 'brown',
            'fontSize': 8
        }
    })

    m = mapnik.Map(1024, 1024)
    m.background = mapnik.Color('white')

    for highwayType in highwayList.keys():
        styleType = mapnik.Style()
        print(styleType)
        rule = mapnik.Rule()

        rule.filter = mapnik.Expression('[highway]=' + "'" + highwayType + "'")

        stk = mapnik.Stroke()
        stk.color = mapnik.Color(highwayList[highwayType]['color'])
        stk.line_cap = mapnik.line_cap.ROUND_CAP
        stk.width = highwayList[highwayType]['width']

        line_symbolizer = mapnik.LineSymbolizer(stk)

        rule.symbols.append(line_symbolizer)

        rule2 = mapnik.Rule()

        rule2.filter = mapnik.Expression('[highway]=' + "'" + highwayType +
                                         "'")

        text_symbolizer = mapnik.TextSymbolizer(
            mapnik.Expression("[name]"), "DejaVu Sans Book",
            highwayList[highwayType]['fontSize'], mapnik.Color('black'))
        text_symbolizer.halo_fill = mapnik.Color('white')

        rule2.symbols.append(text_symbolizer)

        styleType.rules.append(rule)
        styleType.rules.append(rule2)

        m.append_style(highwayType, styleType)

    ds = mapnik.Osm(file=osmFile)

    layer = mapnik.Layer('world')
    layer.datasource = ds
    for highwayType in highwayList.keys():
        layer.styles.append(highwayType)

    m.layers.append(layer)
    m.zoom_all()
    mapnik.render_to_file(m, map_output, 'png')

    return os.system('xdg-open ' + map_output)
コード例 #9
0
ファイル: Mapnik3.py プロジェクト: Yoesrilim/GIS_04316032
import mapnik
m = mapnik.Map(700,400)
m.background = mapnik.Color('steelblue')
s = mapnik.Style()
r = mapnik.Rule()
polygon_symbolizer = mapnik.PolygonSymbolizer()
polygon_symbolizer.fill = mapnik.Color('#000000')
r.symbols.append(polygon_symbolizer)

line_symbolizer = mapnik.LineSymbolizer()
line_symbolizer = mapnik.LineSymbolizer(mapnik.Color('Yello'),1)
line_symbolizer.stroke_width = 10.0

r.symbols.append(line_symbolizer)
s.rules.append(r)
m.append_style('Yoesril',s)
ds = mapnik.Shapefile(file="ne_110m_admin_0_countries.shp")
layer = mapnik.Layer('world')
layer.datasource = ds
layer.styles.append('Yoesril')
m.layers.append(layer)
m.zoom_all()
mapnik.render_to_file(m,'world3.JPEG', 'JPEG')
print "rendered image to 'world3.JEPG' "
コード例 #10
0
import mapnik
m = mapnik.Map(1920,1080)
m.background = mapnik.Color('steelblue')
s = mapnik.Style()
r = mapnik.Rule()
polygon_symbolizer = mapnik.PolygonSymbolizer()
polygon_symbolizer.fill = mapnik.Color('#f2eff9')

r.symbols.append(polygon_symbolizer)

line_symbolizer = mapnik.LineSymbolizer()
line_symbolizer = mapnik.LineSymbolizer(mapnik.Color('green'),1)
line_symbolizer.stroke_width = 10.0

r.symbols.append(line_symbolizer)

point_sym = mapnik.MarkersSymbolizer()
point_sym.filename

basinsLabels = mapnik.TextSymbolizer(mapnik.Expression('[NAME]'), 'DejaVu Sans Bold',5,mapnik.Color('red'))
basinsLabels.halo_fill = mapnik.Color('yellow')
basinsLabels.halo_radius = 2
r.symbols.append(basinsLabels)

point_sym = mapnik.PointSymbolizer()
point_sym.allow_overlap = True
r.symbols.append(point_sym)

s.rules.append(r)

m.append_style('Surya',s)
コード例 #11
0
def createisomap(iso, mapscale, name, name_en):

    map_width = int(mapscale[0])
    map_height = int(mapscale[1])

    map_minx = float(mapscale[2])
    map_maxx = float(mapscale[3])
    map_miny = float(mapscale[4])
    map_maxy = float(mapscale[5])

    print("mapdata:", map_width, map_height, map_maxx, map_maxy, map_minx,
          map_miny)

    geojsonfile = '/osm/service/' + CONTINENT + '/' + iso + '/poly/osm.geojson'

    m = mapnik.Map(
        map_width,
        map_height)  # create a map with a given width and height in pixels
    # note: m.srs will default to '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
    # the 'map.srs' is the target projection of the map and can be whatever you wish
    m.background = mapnik.Color(
        '#000000')  # set background colour to 'steelblue'.

    s = mapnik.Style()  # style object to hold rules
    r = mapnik.Rule()  # rule object to hold symbolizers
    # to fill a polygon we create a PolygonSymbolizer

    psymbolizer = mapnik.PolygonSymbolizer()
    #psymbolizer.fill = mapnik.Color('#f2eff9')
    psymbolizer.fill = mapnik.Color('#000000')
    r.symbols.append(psymbolizer)

    lsymbolizer = mapnik.LineSymbolizer()
    #lsymbolizer.stroke = mapnik.Color('rgb(50%,50%,50%)')
    lsymbolizer.stroke = mapnik.Color('#FFA500')
    lsymbolizer.stroke_width = 0.8
    r.symbols.append(lsymbolizer)

    s.rules.append(r)  # now add the rule to the style and we're done

    m.append_style(
        'My Style',
        s)  # Styles are given names only as they are applied to the map

    ds = mapnik.Ogr(file=geojsonfile, layer_by_index=0)
    print(ds)

    ds.envelope()

    layer = mapnik.Layer(
        'world')  # new layer called 'world' (we could name it anything)
    # note: layer.srs will default to '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'

    layer.datasource = ds
    layer.styles.append('My Style')

    m.layers.append(layer)

    bbox = mapnik.Box2d(map_maxx, map_maxy, map_minx, map_miny)
    m.zoom_to_box(bbox)

    # Write the data to a png image called world.png the current directory

    img_directory = '/osm/service/' + CONTINENT + '/' + iso + '/img/'
    if not os.path.exists(img_directory):
        os.makedirs(img_directory)

    os.system("rm -f " + img_directory + "*")

    mapnik.render_to_file(m, img_directory + 'dbackground0.png', 'png')

    gdalw1 = 'gdalwarp    -te {} {} {} {}  -ts {} {} '.format(
        map_minx, map_miny, map_maxx, map_maxy, map_width, map_height)
    # NE1_HR_LC_SR_W_DR.tif
    gdalw2 = ' -of GTiff   /osm/ne/ne.tif {}  '.format(img_directory +
                                                       'nebackground.geotif')

    print("gdalw:", gdalw1, gdalw2)

    os.system(gdalw1 + gdalw2)

    os.system('gdal_translate -of PNG  {} {} '.format(
        img_directory + 'nebackground.geotif',
        img_directory + 'nebackground.png'))

    os.system('convert   {} -transparent Black {} '.format(
        img_directory + 'dbackground0.png',
        img_directory + 'tdbackground.png'))
    os.system('composite {} -compose over   {} {} '.format(
        img_directory + 'tdbackground.png', img_directory + 'nebackground.png',
        img_directory + 'dbackground.png'))

    ######################  flag ##################################

    im_cmd1 = r'convert /osm/setup/osmlogo.png -font DejaVu-Serif -fill darkblue  -pointsize 34 -gravity center -draw "text 16,-18'
    im_cmd2 = r" '." + iso[:2] + "' "
    im_cmd3 = r'"  ' + img_directory + 'dflag.png'

    os.system(im_cmd1 + im_cmd2 + im_cmd3)

    ####################  Logo #####################################

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 448, 98)
    ctx = cairo.Context(surface)
    ctx.select_font_face("Courier", cairo.FONT_SLANT_NORMAL,
                         cairo.FONT_WEIGHT_BOLD)

    ctx.set_font_size(42)
    ctx.move_to(2, 50)
    ctx.set_source_rgb(0.0, 0.0, 0.15)
    ctx.show_text('Taginfo-' + CONTINENT + '-' + iso)

    ctx.select_font_face('Sans')
    if len(name_en) > 26:
        ctx.set_font_size(20)
    elif len(name_en) > 18:
        ctx.set_font_size(26)
    else:
        ctx.set_font_size(30)

    ctx.move_to(1, 90)
    ctx.set_source_rgb(0.0, 0.0, 0.35)
    ctx.show_text(name_en)

    # finish up
    ctx.stroke()
    surface.write_to_png(img_directory + 'dlogo.png')
rule = mapnik.Rule()
rule.filter = mapnik.Filter("[NAME] = 'Angola'")
symbol = mapnik.PolygonSymbolizer(mapnik.Color("#604040"))
rule.symbols.append(symbol)

polygonStyle.rules.append(rule)

rule = mapnik.Rule()
rule.filter = mapnik.Filter("[NAME] != 'Angola'")
symbol = mapnik.PolygonSymbolizer(mapnik.Color("#406040"))
rule.symbols.append(symbol)

polygonStyle.rules.append(rule)

rule = mapnik.Rule()
symbol = mapnik.LineSymbolizer(mapnik.Color("#000000"), 0.1)
rule.symbols.append(symbol)

polygonStyle.rules.append(rule)

# Define our label style:

labelStyle = mapnik.Style()

rule = mapnik.Rule()
symbol = mapnik.TextSymbolizer(mapnik.Expression("[NAME]"), "DejaVu Sans Book",
                               12, mapnik.Color("#000000"))
rule.symbols.append(symbol)

labelStyle.rules.append(rule)