Exemple #1
0
    eq_(e.miny, 50)

    eq_(e.maxx, 250)
    eq_(e.maxy, 250)

    c = e.center()

    eq_(c.x, 150)
    eq_(c.y, 150)

def test_envelope_clipping():
    e1 = mapnik.Box2d(-180,-90,180,90)
    e2 = mapnik.Box2d(-120,40,-110,48)
    e1.clip(e2)
    eq_(e1,e2)

    # madagascar in merc
    e1 = mapnik.Box2d(4772116.5490, -2744395.0631, 5765186.4203, -1609458.0673)
    e2 = mapnik.Box2d(5124338.3753, -2240522.1727, 5207501.8621, -2130452.8520)
    e1.clip(e2)
    eq_(e1,e2)

    # nz in lon/lat
    e1 = mapnik.Box2d(163.8062, -47.1897, 179.3628, -33.9069)
    e2 = mapnik.Box2d(173.7378, -39.6395, 174.4849, -38.9252)
    e1.clip(e2)
    eq_(e1,e2)

if __name__ == "__main__":
    exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
Exemple #2
0
      eq_(hexlify(im.view( 8, 3,1,1).tostring()), hex_v);
      eq_(hexlify(im.view(13, 3,1,1).tostring()), hex_v);
      eq_(hexlify(im.view( 3, 8,1,1).tostring()), hex_v);
      eq_(hexlify(im.view( 8, 8,1,1).tostring()), hex_v);
      eq_(hexlify(im.view(13, 8,1,1).tostring()), hex_a);
      eq_(hexlify(im.view( 3,13,1,1).tostring()), hex_v);
      eq_(hexlify(im.view( 8,13,1,1).tostring()), hex_b);
      eq_(hexlify(im.view(13,13,1,1).tostring()), hex_v);

    def test_rgba_8bui_subquery():
      _test_rgba_subquery('rgba_8bui_subquery', '8BUI', 255, 0, 0, 255, 255, 255)

    #def test_rgba_16bui_subquery():
    #  _test_rgba_subquery('rgba_16bui_subquery', '16BUI', 65535, 0, 0, 65535, 65535, 65535)

    #def test_rgba_32bui_subquery():
    #  _test_rgba_subquery('rgba_32bui_subquery', '32BUI')

    atexit.register(postgis_takedown)

def enabled(tname):
  enabled = len(sys.argv) < 2 or tname in sys.argv
  if not enabled:
    print "Skipping " + tname + " as not explicitly enabled"
  return enabled

if __name__ == "__main__":
    setup()
    fail = run_all(eval(x) for x in dir() if x.startswith("test_") and enabled(x))
    exit(fail)
Exemple #3
0
    im = mapnik.Image(m.width, m.height)
    mapnik.render(m, im)
    eq_(get_unique_colors(im), ['rgba(255,255,85,191)'])


def test_background_image_with_alpha_and_background_color_against_composited_control(
):
    m = mapnik.Map(10, 10)
    m.background = mapnik.Color('rgba(255,255,255,.5)')
    m.background_image = '../data/images/yellow_half_trans.png'
    im = mapnik.Image(m.width, m.height)
    mapnik.render(m, im)
    # create and composite the expected result
    im1 = mapnik.Image(10, 10)
    im1.background = mapnik.Color('rgba(255,255,255,.5)')
    im1.premultiply()
    im2 = mapnik.Image(10, 10)
    im2.background = mapnik.Color('rgba(255,255,0,.5)')
    im2.premultiply()
    im1.composite(im2)
    im1.demultiply()
    # compare image rendered (compositing in `agg_renderer<T>::setup`)
    # vs image composited via python bindings
    #raise Todo("looks like we need to investigate PNG color rounding when saving")
    #eq_(get_unique_colors(im),get_unique_colors(im1))


if __name__ == "__main__":
    setup()
    exit(run_all(eval(x) for x in dir() if x.startswith("test_")))
        eq_(hexlify(im.view(13, 8, 1, 1).tostring()), hex_a)
        eq_(hexlify(im.view(3, 13, 1, 1).tostring()), hex_v)
        eq_(hexlify(im.view(8, 13, 1, 1).tostring()), hex_b)
        eq_(hexlify(im.view(13, 13, 1, 1).tostring()), hex_v)

    def test_rgba_8bui_subquery():
        _test_rgba_subquery('rgba_8bui_subquery', '8BUI', 255, 0, 0, 255, 255,
                            255)

    #def test_rgba_16bui_subquery():
    #  _test_rgba_subquery('rgba_16bui_subquery', '16BUI', 65535, 0, 0, 65535, 65535, 65535)

    #def test_rgba_32bui_subquery():
    #  _test_rgba_subquery('rgba_32bui_subquery', '32BUI')

    atexit.register(postgis_takedown)


def enabled(tname):
    enabled = len(sys.argv) < 2 or tname in sys.argv
    if not enabled:
        print "Skipping " + tname + " as not explicitly enabled"
    return enabled


if __name__ == "__main__":
    setup()
    fail = run_all(
        eval(x) for x in dir() if x.startswith("test_") and enabled(x))
    exit(fail)
        mapnik.logger.set_severity(mapnik.severity_type.None)
        # form up an in-memory test db
        wkb = '010100000000000000000000000000000000000000'
        # note: the osm_id should be declared INTEGER PRIMARY KEY
        # but in this case we intentionally do not make this a valid pkey
        # otherwise sqlite would turn the null into a valid, serial id
        ds = mapnik.SQLite(file=':memory:',
                           table='test1',
                           initdb='''
                create table test1 (osm_id INTEGER,geometry BLOB);
                insert into test1 values (null,x'%s');
                ''' % wkb,
                           extent='-180,-60,180,60',
                           use_spatial_index=False,
                           key_field='osm_id')
        fs = ds.featureset()
        feature = None
        try:
            feature = fs.next()
        except StopIteration:
            pass
        eq_(feature, None)
        mapnik.logger.set_severity(default_logging_severity)


if __name__ == "__main__":
    setup()
    result = run_all(eval(x) for x in dir() if x.startswith("test_"))
    teardown()
    exit(result)
Exemple #6
0
        feat = fs.next()
        eq_(feat.id(),1)
        eq_(feat['name'],'test point')
        geoms = feat.geometries()
        eq_(len(geoms),1)
        eq_(geoms.to_wkt(),'Point(-122 48)')
        del ds

        # ensure it matches data read with just sqlite
        conn = sqlite3.connect(test_db)
        cur = conn.cursor()
        cur.execute('''SELECT * from point_table''')
        conn.commit()
        result = cur.fetchone()
        cur.close()
        feat_id = result[0]
        eq_(feat_id,1)
        name = result[2]
        eq_(name,'test point')
        geom_wkb_blob = result[1]
        eq_(str(geom_wkb_blob),geoms.to_wkb(mapnik.wkbByteOrder.NDR))
        new_geom = mapnik.Path.from_wkb(str(geom_wkb_blob))
        eq_(new_geom.to_wkt(),geoms.to_wkt())
        conn.close()
        os.unlink(test_db)

if __name__ == "__main__":
    setup()
    returncode = run_all(eval(x) for x in dir() if x.startswith("test_"))
    exit(returncode)
        feat = fs.next()
        eq_(feat.id(),1)
        eq_(feat['name'],'test point')
        geoms = feat.geometries()
        eq_(len(geoms),1)
        eq_(geoms.to_wkt(),'Point(-122 48)')
        del ds

        # ensure it matches data read with just sqlite
        conn = sqlite3.connect(test_db)
        cur = conn.cursor()
        cur.execute('''SELECT * from point_table''')
        conn.commit()
        result = cur.fetchone()
        cur.close()
        feat_id = result[0]
        eq_(feat_id,1)
        name = result[2]
        eq_(name,'test point')
        geom_wkb_blob = result[1]
        eq_(str(geom_wkb_blob),geoms.to_wkb(mapnik.wkbByteOrder.NDR))
        new_geom = mapnik.Path.from_wkb(str(geom_wkb_blob))
        eq_(new_geom.to_wkt(),geoms.to_wkt())
        conn.close()
        os.unlink(test_db)

if __name__ == "__main__":
    setup()
    returncode = run_all(eval(x) for x in dir() if x.startswith("test_"))
    exit(returncode)
        # note: the osm_id should be declared INTEGER PRIMARY KEY
        # but in this case we intentionally do not make this a valid pkey
        # otherwise sqlite would turn the null into a valid, serial id
        ds = mapnik.SQLite(
            file=":memory:",
            table="test1",
            initdb="""
                create table test1 (osm_id INTEGER,geometry BLOB);
                insert into test1 values (null,x'%s');
                """
            % wkb,
            extent="-180,-60,180,60",
            use_spatial_index=False,
            key_field="osm_id",
        )
        fs = ds.featureset()
        feature = None
        try:
            feature = fs.next()
        except StopIteration:
            pass
        eq_(feature, None)
        mapnik.logger.set_severity(default_logging_severity)


if __name__ == "__main__":
    setup()
    result = run_all(eval(x) for x in dir() if x.startswith("test_"))
    teardown()
    exit(result)