Ejemplo n.º 1
0
r = mapnik.Rule()

point_sym = mapnik.MarkersSymbolizer()
point_sym.filename = 'tugu.jpeg'
point_sym.widht = mapnik.Expression("20")
point_sym.height = mapnik.Expression("20")
point_sym.allow_overlap = True
r.symbols.append(point_sym)

text_sym = mapnik.TextSymbolizer(mapnik.Expression('[NAME]'),
                                 'DejaVu Sans Bold', 5, mapnik.Color('black'))
text_sym.hallo_radius = 1
text_sym.allow_overlap = True
text_sym.avoid_edges = False
r.symbols.append(text_sym)

s.rules.append(r)
m.append_style('airport point', s)

ds = mapnik.MemoryDatasource()
f = mapnik.Feature(mapnik.Context(), 1)
f['NAME'] = 'asd asbdashbd ahsbdasbd'
f.add_geometries_from_wkt("POINT(-7.245808 112.737785)")
ds.add_feature(f)

player = mapnik.Layer('airport_layer')
player.datasource = ds

m.zoom_all()
mapnik.render_to_file(m, 'indonesia.pdf', 'pdf')
print "rendered image to 'indonesia.pdf"
   "json":'{"type":"Feature","id":1,"geometry":null,"properties":{"name":"string with \\t quote"}}'
 },
 # remainder are c++ reserved, but not json
 {
   "name":"vert_tab",
   "test":"string with \v quote",
   "json":'{"type":"Feature","id":1,"geometry":null,"properties":{"name":"string with \\u000b quote"}}'
 },
 {
   "name":"alert",
   "test":"string with \a quote",
   "json":'{"type":"Feature","id":1,"geometry":null,"properties":{"name":"string with \u0007 quote"}}'
 }
]

ctx = mapnik.Context()
ctx.push('name')

def test_char_escaping():
    for char in chars:
        feat = mapnik.Feature(ctx,1)
        expected = char['test']
        feat["name"] = expected
        eq_(feat["name"],expected)
        # confirm the python json module
        # is working as we would expect
        pyjson2 = json.loads(char['json'])
        eq_(pyjson2['properties']['name'],expected)
        # confirm our behavior is the same as python json module
        # for the original string
        geojson_feat_string = feat.to_geojson()
Ejemplo n.º 3
0
def test_feature_geo_interface():
    ctx = mapnik.Context()
    feat = mapnik.Feature(ctx, 1)
    feat.geometry = mapnik.Geometry.from_wkt('Point (0 0)')
    eq_(feat.__geo_interface__['geometry'], {
        u'type': u'Point', u'coordinates': [0, 0]})
Ejemplo n.º 4
0
def test_default_constructor():
    f = mapnik.Feature(mapnik.Context(), 1)
    eq_(f is not None, True)
Ejemplo n.º 5
0
def test_filtering_nulls_and_empty_strings():
    context = mapnik.Context()
    f = mapnik.Feature(context,0)
    f["prop"] = u"hello"
    eq_(f["prop"],u"hello")
    eq_(mapnik.Expression("[prop]").to_bool(f),True)
    eq_(mapnik.Expression("! [prop]").to_bool(f),False)
    eq_(mapnik.Expression("[prop] != null").to_bool(f),True)
    eq_(mapnik.Expression("[prop] != ''").to_bool(f),True)
    eq_(mapnik.Expression("[prop] != null and [prop] != ''").to_bool(f),True)
    eq_(mapnik.Expression("[prop] != null or [prop] != ''").to_bool(f),True)
    f["prop2"] = u""
    eq_(f["prop2"],u"")
    eq_(mapnik.Expression("[prop2]").to_bool(f),False)
    eq_(mapnik.Expression("! [prop2]").to_bool(f),True)
    eq_(mapnik.Expression("[prop2] != null").to_bool(f),True)
    eq_(mapnik.Expression("[prop2] != ''").to_bool(f),False)
    eq_(mapnik.Expression("[prop2] = ''").to_bool(f),True)
    eq_(mapnik.Expression("[prop2] != null or [prop2] != ''").to_bool(f),True)
    eq_(mapnik.Expression("[prop2] != null and [prop2] != ''").to_bool(f),False)
    f["prop3"] = None
    eq_(f["prop3"],None)
    eq_(mapnik.Expression("[prop3]").to_bool(f),False)
    eq_(mapnik.Expression("! [prop3]").to_bool(f),True)
    eq_(mapnik.Expression("[prop3] != null").to_bool(f),False)
    eq_(mapnik.Expression("[prop3] = null").to_bool(f),True)

    # https://github.com/mapnik/mapnik/issues/1859
    #eq_(mapnik.Expression("[prop3] != ''").to_bool(f),True)
    eq_(mapnik.Expression("[prop3] != ''").to_bool(f),False)

    eq_(mapnik.Expression("[prop3] = ''").to_bool(f),False)

    # https://github.com/mapnik/mapnik/issues/1859
    #eq_(mapnik.Expression("[prop3] != null or [prop3] != ''").to_bool(f),True)
    eq_(mapnik.Expression("[prop3] != null or [prop3] != ''").to_bool(f),False)

    eq_(mapnik.Expression("[prop3] != null and [prop3] != ''").to_bool(f),False)
    # attr not existing should behave the same as prop3
    eq_(mapnik.Expression("[prop4]").to_bool(f),False)
    eq_(mapnik.Expression("! [prop4]").to_bool(f),True)
    eq_(mapnik.Expression("[prop4] != null").to_bool(f),False)
    eq_(mapnik.Expression("[prop4] = null").to_bool(f),True)

    # https://github.com/mapnik/mapnik/issues/1859
    ##eq_(mapnik.Expression("[prop4] != ''").to_bool(f),True)
    eq_(mapnik.Expression("[prop4] != ''").to_bool(f),False)

    eq_(mapnik.Expression("[prop4] = ''").to_bool(f),False)

    # https://github.com/mapnik/mapnik/issues/1859
    ##eq_(mapnik.Expression("[prop4] != null or [prop4] != ''").to_bool(f),True)
    eq_(mapnik.Expression("[prop4] != null or [prop4] != ''").to_bool(f),False)

    eq_(mapnik.Expression("[prop4] != null and [prop4] != ''").to_bool(f),False)
    f["prop5"] = False
    eq_(f["prop5"],False)
    eq_(mapnik.Expression("[prop5]").to_bool(f),False)
    eq_(mapnik.Expression("! [prop5]").to_bool(f),True)
    eq_(mapnik.Expression("[prop5] != null").to_bool(f),True)
    eq_(mapnik.Expression("[prop5] = null").to_bool(f),False)
    eq_(mapnik.Expression("[prop5] != ''").to_bool(f),True)
    eq_(mapnik.Expression("[prop5] = ''").to_bool(f),False)
    eq_(mapnik.Expression("[prop5] != null or [prop5] != ''").to_bool(f),True)
    eq_(mapnik.Expression("[prop5] != null and [prop5] != ''").to_bool(f),True)
    # note, we need to do [prop5] != 0 here instead of false due to this bug:
    # https://github.com/mapnik/mapnik/issues/1873
    eq_(mapnik.Expression("[prop5] != null and [prop5] != '' and [prop5] != 0").to_bool(f),False)
Ejemplo n.º 6
0
def test_geometry_index_error2():
    wkt = 'Point (0 0)'
    f = mapnik.Feature(mapnik.Context(), 1)
    f.add_geometries_from_wkt(wkt)
    f.geometries()[3]
Ejemplo n.º 7
0
poin_wisata.width = mapnik.Expression('20')
poin_wisata.height = mapnik.Expression('20')
poin_wisata.allow_overlap = True
rsby_wisata.symbols.append(poin_wisata)  #membuat rule poin_wisata

label = mapnik.TextSymbolizer(mapnik.Expression('[Kecamatan]'),
                              'DejaVu Sans Book', 5, mapnik.Color('Red'))
label.halo_radius = 1
label.avoid_edges = False
rsby_wisata.symbols.append(label)  #membuat rule label

#Membuat Layer Tempat Wisata
layer_wisata = mapnik.Layer('Wisata', '+init=epsg:4326')
ds = mapnik.MemoryDatasource()
layer_wisata.datasource = ds
fitur_wisata = mapnik.Feature(mapnik.Context(), 1)
fitur_wisata['Kecamatan'] = 'Kenjeran'
fitur_wisata.add_geometries_from_wkt("POINT(112.7078354 -7.260369)")
ds.add_feature(fitur_wisata)
#layer_wisata.srs = longlat.params()

#Menerapkan rule-rule yang ada ke style yang telah dibuat
ssby.rules.append(rsby)
ssby_wisata.rules.append(rsby_wisata)

#Menerapkan Style utama ke peta yang telah dibuat
m.append_style('StyleLayerSby', ssby)  #memberi nama Style
m.append_style('PoinWisata', ssby_wisata)  #memberinama style poinwisata
layer_sby.styles.append(
    'StyleLayerSby')  #meletakkan style sby ke dalam layer_sby
layer_wisata.styles.append(