Exemple #1
0
 def test_reading_ways():
     ds = mapnik.Osm(file='../data/osm/ways.osm')
     eq_(len(ds.fields()), 0)
     eq_(ds.fields(), [])
     eq_(ds.field_types(), [])
     feat = ds.all_features()[4]
     eq_(feat.to_geojson(
     ), '{"type":"Feature","id":1,"geometry":{"type":"LineString","coordinates":[[0,2],[0,-2]]},"properties":{}}')
     eq_(feat.id(), 1)
Exemple #2
0
 def test_that_nonexistant_query_field_throws(**kwargs):
     ds = mapnik.Osm(file='../data/osm/nodes.osm')
     eq_(len(ds.fields()), 0)
     query = mapnik.Query(ds.envelope())
     for fld in ds.fields():
         query.add_property_name(fld)
     # also add an invalid one, triggering throw
     query.add_property_name('bogus')
     ds.features(query)
Exemple #3
0
    def test_osm_init():
        ds = mapnik.Osm(file='../data/osm/nodes.osm')

        e = ds.envelope()

        # these are hardcoded in the plugin… ugh
        assert_almost_equal(e.minx, -180.0)
        assert_almost_equal(e.miny, -90.0)
        assert_almost_equal(e.maxx, 180.0)
        assert_almost_equal(e.maxy, 90)
Exemple #4
0
    def test_osm_init():
        ds = mapnik.Osm(file='../data/osm/nodes.osm')

        e = ds.envelope()

        # these are hardcoded in the plugin… ugh
        eq_(e.minx >= -180.0, True)
        eq_(e.miny >= -90.0, True)
        eq_(e.maxx <= 180.0, True)
        eq_(e.maxy <= 90, True)
Exemple #5
0
 def test_that_64bit_int_fields_work():
     ds = mapnik.Osm(file='../data/osm/64bit.osm')
     eq_(len(ds.fields()), 4)
     eq_(ds.fields(), ['bigint', 'highway', 'junction', 'note'])
     eq_(ds.field_types(), ['str', 'str', 'str', 'str'])
     fs = ds.featureset()
     feat = fs.next()
     eq_(feat.id(), 4294968186)
     eq_(feat['bigint'], None)
     feat = fs.next()
     eq_(feat['bigint'], '9223372036854775807')
Exemple #6
0
 def test_that_nonexistant_query_field_throws(**kwargs):
     ds = mapnik.Osm(file='../data/osm/nodes.osm')
     # ugh, more odd stuff hardcoded...
     eq_(len(ds.fields()), 5)
     eq_(ds.fields(), ['bicycle', 'foot', 'horse', 'name', 'width'])
     eq_(ds.field_types(), ['str', 'str', 'str', 'str', 'str'])
     query = mapnik.Query(ds.envelope())
     for fld in ds.fields():
         query.add_property_name(fld)
     # also add an invalid one, triggering throw
     query.add_property_name('bogus')
     fs = ds.features(query)
Exemple #7
0
 def test_that_64bit_int_fields_work():
     ds = mapnik.Osm(file='../data/osm/64bit.osm')
     eq_(len(ds.fields()), 4)
     eq_(ds.fields(), ['bigint', 'highway', 'junction', 'note'])
     eq_(ds.field_types(), ['str', 'str', 'str', 'str'])
     fs = ds.featureset()
     feat = fs.next()
     eq_(feat.to_geojson(
     ), '{"type":"Feature","id":890,"geometry":{"type":"Point","coordinates":[-61.7960248,17.1415874]},"properties":{}}')
     eq_(feat.id(), 4294968186)
     eq_(feat['bigint'], None)
     feat = fs.next()
     eq_(feat['bigint'], '9223372036854775807')
Exemple #8
0
def renderMap():
    m = mapnik.Map(600, 600)
    mapnik.load_map(m, 'mini_osm.xml')
    s_my = makeStyleMyShape()
    m.append_style('mystyle', s_my)

    layer = mapnik.Layer("osm")
    ds = mapnik.Osm(file="/home/charles/data/osm/dcc.osm")
    layer.datasource = ds
    layer.styles.append('cf')
    m.layers.append(layer)

    layer2 = mapnik.Layer("myshape")
    ds = mapnik.Shapefile(file="test.shp")
    layer2.datasource = ds
    layer2.styles.append('mystyle')
    m.layers.append(layer2)

    m.zoom_all()
    mapnik.render_to_file(m, 'dcc.png', 'png')
Exemple #9
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)
Exemple #10
0
text.placements.defaults.displacement = (0, 5)
text.placements.defaults.format.face_name = 'DejaVu Sans Book'

point = mapnik.PointSymbolizer()

rule = mapnik.Rule()
rule.symbols.append(text)
rule.symbols.append(point)

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

m.append_style('Style', style)

layer = mapnik.Layer('Layer')
layer.datasource = mapnik.Osm(file=os.path.join(dirname, "data/points.osm"))
layer.styles.append('Style')
m.layers.append(layer)

bbox = mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)
m.zoom_to_box(bbox)

formatnode = mapnik.FormattingFormat()
formatnode.child = mapnik.FormattingText("[name]")
formatnode.fill = mapnik.Color("green")

format_trees = [
    ('TextNode', mapnik.FormattingText("[name]")), ('MyText', MyText()),
    ('IfElse',
     IfElse("[nr] != '5'", mapnik.FormattingText("[name]"),
            mapnik.FormattingText("'SPECIAL!'"))), ('Format', formatnode),