示例#1
0
def init_map(zoom, seq):
    m = mapnik.Map(256, 256, merc_srs)
    m.background_color = mapnik.Color('white')
    s = mapnik.Style()
    r = mapnik.Rule()
    sym = mapnik.MarkersSymbolizer()
    sym.fill = mapnik.Color('black')
    sym.spacing = 0.0
    sym.opacity = opacity(zoom)
    sym.height = mapnik.Expression(str(pointWeight(zoom) / 2.0))
    sym.width = mapnik.Expression(str(pointWeight(zoom) / 2.0))

    # Ignore placement instructs Mapnik to avoid building the quadtree
    # collision cache and helps performance if you know you want to
    # allow for overlaps between features.
    #        - Dane
    sym.allow_overlap = True
    sym.ignore_placement = True

    r.symbols.append(sym)
    s.rules.append(r)
    m.append_style('point_style', s)
    TuplesDatasource.set_source(seq)
    ds = mapnik.Python(factory='TuplesDatasource')
    layer = mapnik.Layer('file', merc_srs)
    layer.datasource = ds
    layer.styles.append('point_style')
    m.layers.append(layer)
    return m
示例#2
0
    def test_python_circle_init():
        ds = mapnik.Python(factory='python_plugin_test:CirclesDatasource')
        e = ds.envelope()

        assert_almost_equal(e.minx, -180, places=7)
        assert_almost_equal(e.miny, -90, places=7)
        assert_almost_equal(e.maxx, 180, places=7)
        assert_almost_equal(e.maxy, 90, places=7)
示例#3
0
    def test_python_point_init():
        ds = mapnik.Python(factory='python_plugin_test:PointDatasource')
        e = ds.envelope()

        assert_almost_equal(e.minx, 0, places=7)
        assert_almost_equal(e.miny, -10, places=7)
        assert_almost_equal(e.maxx, 100, places=7)
        assert_almost_equal(e.maxy, 110, places=7)
                geometry_type=mapnik.DataGeometryType.Polygon
        )

    def features(self, query):
        # Get the query bounding-box as a shapely bounding box
        bounding_box = box2d_to_shapely(query.bbox)
        centre = Point(-20, 0)

        return mapnik.PythonDatasource.wkb_features(
            keys = (),
            features = ConcentricCircles(centre, bounding_box, 0.5)
        )

if __name__ == '__main__':
    m = mapnik.Map(640, 320)

    m.background = mapnik.Color('white')
    s = mapnik.Style()
    r = mapnik.Rule()
    r.symbols.append(mapnik.LineSymbolizer())
    s.rules.append(r)
    m.append_style('point_style',s)
    ds = mapnik.Python(factory='TestDatasource')
    layer = mapnik.Layer('python')
    layer.datasource = ds
    layer.styles.append('point_style')
    m.layers.append(layer)
    box = mapnik.Box2d(-60, -60, 0, -30)
    m.zoom_to_box(box)
    mapnik.render_to_file(m,'map.png', 'png')