• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mapnik.has_cairo函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mapnik.has_cairo函数的典型用法代码示例。如果您正苦于以下问题:Python has_cairo函数的具体用法?Python has_cairo怎么用?Python has_cairo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了has_cairo函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_render_points

def test_render_points():

    if not mapnik.has_cairo(): return

    # create and populate point datasource (WGS84 lat-lon coordinates)
    ds = mapnik.MemoryDatasource()
    context = mapnik.Context()
    context.push('Name')
    f = mapnik.Feature(context,1)
    f['Name'] = 'Westernmost Point'
    f.add_geometries_from_wkt('POINT (142.48 -38.38)')
    ds.add_feature(f)

    f = mapnik.Feature(context,2)
    f['Name'] = 'Southernmost Point'
    f.add_geometries_from_wkt('POINT (143.10 -38.60)')
    ds.add_feature(f)

    # create layer/rule/style
    s = mapnik.Style()
    r = mapnik.Rule()
    symb = mapnik.PointSymbolizer()
    symb.allow_overlap = True
    r.symbols.append(symb)
    s.rules.append(r)
    lyr = mapnik.Layer('Places','+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
    lyr.datasource = ds
    lyr.styles.append('places_labels')
    # latlon bounding box corners
    ul_lonlat = mapnik.Coord(142.30,-38.20)
    lr_lonlat = mapnik.Coord(143.40,-38.80)
    # render for different projections 
    projs = { 
        'google': '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m [email protected] +wktext +no_defs +over',
        'latlon': '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
        'merc': '+proj=merc +datum=WGS84 +k=1.0 +units=m +over +no_defs',
        'utm': '+proj=utm +zone=54 +datum=WGS84'
        }
    for projdescr in projs.iterkeys():
        m = mapnik.Map(1000, 500, projs[projdescr])
        m.append_style('places_labels',s)
        m.layers.append(lyr)
        dest_proj = mapnik.Projection(projs[projdescr])
        src_proj = mapnik.Projection('+init=epsg:4326')
        tr = mapnik.ProjTransform(src_proj,dest_proj)
        m.zoom_to_box(tr.forward(mapnik.Box2d(ul_lonlat,lr_lonlat)))
        # Render to SVG so that it can be checked how many points are there with string comparison
        svg_file = os.path.join(tempfile.gettempdir(), 'mapnik-render-points-%s.svg' % projdescr)
        mapnik.render_to_file(m, svg_file)
        num_points_present = len(ds.all_features())
        svg = open(svg_file,'r').read()
        num_points_rendered = svg.count('<image ')
        eq_(num_points_present, num_points_rendered, "Not all points were rendered (%d instead of %d) at projection %s" % (num_points_rendered, num_points_present, projdescr)) 
开发者ID:avlee,项目名称:mapnik,代码行数:53,代码来源:render_test.py


示例2: test_render_points

def test_render_points():

    if not mapnik.has_cairo(): return

    # create and populate point datasource (WGS84 lat-lon coordinates)
    places_ds = mapnik.PointDatasource()
    places_ds.add_point(142.48,-38.38,'Name','Westernmost Point') # westernmost
    places_ds.add_point(143.10,-38.60,'Name','Southernmost Point') # southernmost
    # create layer/rule/style
    s = mapnik.Style()
    r = mapnik.Rule()
    symb = mapnik.PointSymbolizer()
    symb.allow_overlap = True
    r.symbols.append(symb)
    s.rules.append(r)
    lyr = mapnik.Layer('Places','+proj=latlon +datum=WGS84')
    lyr.datasource = places_ds
    lyr.styles.append('places_labels')
    # latlon bounding box corners
    ul_lonlat = mapnik.Coord(142.30,-38.20)
    lr_lonlat = mapnik.Coord(143.40,-38.80)
    # render for different projections 
    projs = { 
        'latlon': '+proj=latlon +datum=WGS84',
        'merc': '+proj=merc +datum=WGS84 +k=1.0 +units=m +over +no_defs',
        'google': '+proj=merc +ellps=sphere +R=6378137 +a=6378137 +units=m',
        'utm': '+proj=utm +zone=54 +datum=WGS84'
        }
    for projdescr in projs.iterkeys():
        m = mapnik.Map(1000, 500, projs[projdescr])
        m.append_style('places_labels',s)
        m.layers.append(lyr)
        p = mapnik.Projection(projs[projdescr])
        m.zoom_to_box(p.forward(mapnik.Box2d(ul_lonlat,lr_lonlat)))
        # Render to SVG so that it can be checked how many points are there with string comparison
        svg_file = '/tmp/%s.svg'
        mapnik.render_to_file(m, svg_file)
        num_points_present = len(places_ds.all_features())
        svg = open(svg_file,'r').read()
        num_points_rendered = svg.count('<image ')
        eq_(num_points_present, num_points_rendered, "Not all points were rendered (%d instead of %d) at projection %s" % (num_points_rendered, num_points_present, projdescr)) 
开发者ID:mojodna,项目名称:debian-mapnik,代码行数:41,代码来源:render_test.py


示例3: _render_surface

 def _render_surface(self, map, map_size):
     if self.format.startswith('image/'):
         # AGG
         f = str(self.format.split('/')[1].lower())
         im = mapnik.Image(*map_size)
         mapnik.render(map, im)
         return im.tostring(f)
     
     elif self.format in ('application/pdf', 'application/postscript', 'text/svg+xml'):
         # CAIRO
         try:
             # first, check if Cairo is available
             import cairo
             # newer Mapniks have better ways of checking whether they were actually
             # compiled with Cairo support
             if hasattr(mapnik, 'has_cairo') and (not mapnik.has_cairo()):
                 raise ImportError
             if hasattr(mapnik, 'has_pycairo') and (not mapnik.has_pycairo()):
                 raise ImportError
         except ImportError:
             raise ImportError("Mapnik wasn't compiled with Cairo support, or Cairo isn't installed.")
         
         surface_file = StringIO()
         if (self.format == 'application/pdf'):
             surface = cairo.PDFSurface(surface_file, *map_size)
         elif (self.format == 'application/postscript'):
             surface = cairo.PSSurface(surface_file, *map_size)
         elif (self.format == 'text/svg+xml'):
             surface = cairo.SVGSurface(surface_file, *map_size)
         
         mapnik.render(map, surface)
         surface.finish()
         return surface_file.getvalue()
     
     else:
         raise ValueError("Unknown format: %s" % self.format)
开发者ID:AppleHolic,项目名称:mapnik-utils,代码行数:36,代码来源:render.py


示例4: len

    im.save('demo.tif', 'tiff')
    images_.append('demo.tif')

if mapnik.has_webp():
    im.save('demo.webp', 'webp') # default quality is 90
    images_.append('demo.webp')

    im.save('demo_highest.webp', 'webp:quality=100')
    images_.append('demo_med.webp')

    im.save('demo_low.webp', 'webp:quality=50')
    images_.append('demo_low.webp')


# Render cairo examples
if  mapnik.has_cairo():
    mapnik.render_to_file(m,'demo.pdf')
    images_.append('demo.pdf')
    mapnik.render_to_file(m,'demo.ps')
    images_.append('demo.ps')
    mapnik.render_to_file(m,'demo.svg')
    images_.append('demo.svg')
    mapnik.render_to_file(m,'demo_cairo_rgb24.png','RGB24')
    images_.append('demo_cairo_rgb.png')
    mapnik.render_to_file(m,'demo_cairo_argb32.png','ARGB32')
    images_.append('demo_cairo_argb.png')

print ("\n\n", len(images_), "maps have been rendered in the current directory:")

for im_ in images_:
    print ("-", im_)
开发者ID:DavidLiuGitHub,项目名称:mapnik,代码行数:31,代码来源:rundemo.py


示例5: render_cairo

import sys
import os.path
from compare import compare, compare_grids

try:
    import json
except ImportError:
    import simplejson as json

visual_output_dir = "/tmp/mapnik-visual-images"

defaults = {
    'sizes': [(500, 100)],
    'scales':[1.0,2.0],
    'agg': True,
    'cairo': mapnik.has_cairo(),
    'grid': mapnik.has_grid_renderer()
}

cairo_threshold = 10
if 'Linux' == os.uname()[0]:
    # we assume if linux then you are running packaged cairo
    # which is older than the 1.12.14 version we used on OS X
    # to generate the expected images, so we'll rachet back the threshold
    # https://github.com/mapnik/mapnik/issues/1868
    cairo_threshold = 181

def render_cairo(m, output, scale_factor):
    mapnik.render_to_file(m, output, 'ARGB32', scale_factor)
    # open and re-save as png8 to save space
    new_im = mapnik.Image.open(output)
开发者ID:GISpecialist,项目名称:mapnik,代码行数:31,代码来源:test.py


示例6:

import mapnik

mapnik.logger.set_severity(mapnik.severity_type.None)

import sys
import os.path
from compare import compare, compare_grids

try:
    import json
except ImportError:
    import simplejson as json

visual_output_dir = "/tmp/mapnik-visual-images"

defaults = {"sizes": [(500, 100)], "scales": [1.0, 2.0], "agg": False, "cairo": mapnik.has_cairo(), "grid": True}

sizes_many_in_big_range = [(800, 100), (600, 100), (400, 100), (300, 100), (250, 100), (150, 100), (100, 100)]

sizes_few_square = [(800, 800), (600, 600), (400, 400), (200, 200)]
sizes_many_in_small_range = [
    (490, 100),
    (495, 100),
    (497, 100),
    (498, 100),
    (499, 100),
    (500, 100),
    (501, 100),
    (502, 100),
    (505, 100),
    (510, 100),
开发者ID:sunshineSun,项目名称:mapnik,代码行数:31,代码来源:test.py


示例7: render_cairo

import sys
import os.path
from compare import compare, compare_grids

try:
    import json
except ImportError:
    import simplejson as json

visual_output_dir = "/tmp/mapnik-visual-images"

defaults = {
    "sizes": [(500, 100)],
    "scales": [1.0, 2.0],
    "agg": True,
    "cairo": mapnik.has_cairo(),
    "grid": mapnik.has_grid_renderer(),
}

cairo_threshold = 10
agg_threshold = 0
if "Linux" == os.uname()[0]:
    # we assume if linux then you are running packaged cairo
    # which is older than the 1.12.14 version we used on OS X
    # to generate the expected images, so we'll rachet back the threshold
    # https://github.com/mapnik/mapnik/issues/1868
    cairo_threshold = 230
    agg_threshold = 12


def render_cairo(m, output, scale_factor):
开发者ID:plepe,项目名称:mapnik,代码行数:31,代码来源:test.py



注:本文中的mapnik.has_cairo函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mapnik.load_map函数代码示例发布时间:2022-05-27
下一篇:
Python logging.msg函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap