本文整理汇总了Python中mapnik.Map方法的典型用法代码示例。如果您正苦于以下问题:Python mapnik.Map方法的具体用法?Python mapnik.Map怎么用?Python mapnik.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mapnik
的用法示例。
在下文中一共展示了mapnik.Map方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import mapnik [as 别名]
# 或者: from mapnik import Map [as 别名]
def __init__(self, size, stylesheet):
self._map = mapnik.Map(size, size)
mapnik.load_map(self._map, stylesheet)
示例2: generate_image
# 需要导入模块: import mapnik [as 别名]
# 或者: from mapnik import Map [as 别名]
def generate_image(xml, filename, ext, ftype, ll, dx, dy, res, verbose, force):
print "generate_image:", xml, filename
mapfile = xml
merc = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over"
latlon = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
m = mapnik.Map(dx, dy)
mapnik.load_map(m, mapfile)
# Override projection defined in mapfile
m.srs = latlon
#m.srs = merc
# Calculate projected boundaries
prj = mapnik.Projection(m.srs)
c0 = prj.forward(mapnik.Coord(ll[0], ll[1]))
c1 = prj.forward(mapnik.Coord(ll[2], ll[3]))
# Apply bounding box
bbox = mapnik.Envelope(c0.x, c0.y, c1.x, c1.y)
m.zoom_to_box(bbox)
# Render image
im = mapnik.Image(dx, dy)
mapnik.render(m, im)
view = im.view(0, 0, dx, dy)
png_file = filename + ext #".png"
if force or not os.path.isfile(png_file):
if verbose:
print( "saving "+ png_file)
view.save(png_file, ftype)
# Main
# geojson_osm.py --bbox 20.0 -20.0 30.00 -10.00 --img 4551 4551 --res 0.00219726562502 --dir . -v
示例3: generate_image
# 需要导入模块: import mapnik [as 别名]
# 或者: from mapnik import Map [as 别名]
def generate_image(self, xml, filename, ext, ftype, ll, dx, dy, res, verbose, force):
print "generate_image:", xml, filename
mapfile = xml
merc = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over"
latlon = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
m = mapnik.Map(dx, dy)
mapnik.load_map(m, mapfile)
# Override projection defined in mapfile
m.srs = latlon
#m.srs = merc
# Calculate projected boundaries
prj = mapnik.Projection(m.srs)
c0 = prj.forward(mapnik.Coord(ll[0], ll[1]))
c1 = prj.forward(mapnik.Coord(ll[2], ll[3]))
# Apply bounding box
bbox = mapnik.Envelope(c0.x, c0.y, c1.x, c1.y)
m.zoom_to_box(bbox)
# Render image
im = mapnik.Image(dx, dy)
mapnik.render(m, im)
view = im.view(0, 0, dx, dy)
png_file = filename + ext #".png"
if force or not os.path.isfile(png_file):
if verbose:
print( "saving "+ png_file)
view.save(png_file, ftype)
示例4: style_map
# 需要导入模块: import mapnik [as 别名]
# 或者: from mapnik import Map [as 别名]
def style_map(self, Map):
style = mapnik.Style()
rule = mapnik.Rule()
sym = mapnik.RasterSymbolizer()
sym.opacity = self.opacity
colorizer = mapnik.RasterColorizer(
mapnik.COLORIZER_DISCRETE,
mapnik.Color('white')
)
# colorizer.epsilon = 0.001
if self.colormap:
for stop in self.colormap:
colorizer.add_stop(stop['quantity'], mapnik.Color(
stop['color'].encode('ascii')))
sym.colorizer = colorizer
rule.symbols.append(sym)
style.rules.append(rule)
Map.append_style('Raster Style', style)
lyr = mapnik.Layer('GDAL Layer from TIFF', self.layer_srs)
lyr.datasource = mapnik.Gdal(base=os.path.dirname(self.vrt_path),
file=os.path.basename(self.vrt_path),
band=self.mapnik_band)
lyr.styles.append('Raster Style')
Map.layers.append(lyr)
return Map
示例5: renderArea
# 需要导入模块: import mapnik [as 别名]
# 或者: from mapnik import Map [as 别名]
def renderArea(self, width, height, srs, xmin, ymin, xmax, ymax, zoom):
'''
'''
# NB: To be thread-safe Map object cannot be stored in the class state.
# see: https://groups.google.com/forum/#!topic/mapnik/USDlVfSk328
Map = mapnik.Map(width, height, srs)
Map.zoom_to_box(Box2d(xmin, ymin, xmax, ymax))
Map = self.style_map(Map)
img = mapnik.Image(width, height)
# Don't even call render with scale factor if it's not
# defined. Plays safe with older versions.
if self.scale_factor is None:
mapnik.render(Map, img)
else:
mapnik.render(Map, img, self.scale_factor)
def gamma_correct(im):
"""Fast gamma correction with PIL's image.point() method."""
if self.gamma != 1.0:
table = [pow(x / 255., 1.0 / self.gamma) * 255
for x in range(256)]
# Expand table to number of bands
table = table * len(im.mode)
return im.point(table)
else:
return im
# b = BytesIO(img.tostring())
img = Image.frombytes('RGBA', (width, height), img.tostring())
img = gamma_correct(img)
return img
示例6: prepare_ozi
# 需要导入模块: import mapnik [as 别名]
# 或者: from mapnik import Map [as 别名]
def prepare_ozi(mbbox, mwidth, mheight, name, transform):
"""Create georeferencing file for OziExplorer"""
def deg(value, is_lon):
degrees = math.floor(abs(value))
minutes = (abs(value) - degrees) * 60
return '{:4d},{:3.5F},{}'.format(
int(round(degrees)), minutes,
('W' if is_lon else 'S') if value < 0 else ('E' if is_lon else 'N'))
ozipoint = ('Point{:02d},xy, , ,in, deg, , ,N, , ,E' +
', grid, , , ,N')
bbox = transform.backward(mbbox)
points = "\n".join([ozipoint.format(n) for n in range(3, 31)])
header = '''OziExplorer Map Data File Version 2.2
Nik4
{name}
1 ,Map Code,
WGS 84,WGS 84, 0.0000, 0.0000,WGS 84
Reserved 1
Reserved 2
Magnetic Variation,,,E
Map Projection,Mercator,PolyCal,No,AutoCalOnly,No,BSBUseWPX,No
Point01,xy, 0, 0,in, deg,{top},{left}, grid, , , ,N
Point02,xy, {width:4d}, {height:4d},in, deg,{bottom},{right}, grid, , , ,N
{points}
Projection Setup,,,,,,,,,,
Map Feature = MF ; Map Comment = MC These follow if they exist
Track File = TF These follow if they exist
Moving Map Parameters = MM? These follow if they exist
MM0,Yes
MMPNUM,4
MMPXY,1,0,0
'''.format(name=name,
top=deg(bbox.maxy, False),
left=deg(bbox.minx, True),
width=mwidth - 1,
height=mheight - 1,
bottom=deg(bbox.miny, False),
right=deg(bbox.maxx, True),
points=points)
return ''.join([
header,
"MMPXY,2,{},0\n".format(mwidth),
"MMPXY,3,{},{}\n".format(mwidth, mheight),
"MMPXY,4,0,{}\n".format(mheight),
'MMPLL,1,{:4.6f},{:4.6f}\n'.format(bbox.minx, bbox.maxy),
'MMPLL,2,{:4.6f},{:4.6f}\n'.format(bbox.maxx, bbox.maxy),
'MMPLL,3,{:4.6f},{:4.6f}\n'.format(bbox.maxx, bbox.miny),
'MMPLL,4,{:4.6f},{:4.6f}\n'.format(bbox.minx, bbox.miny),
"MM1B,{}\n".format((mbbox.maxx - mbbox.minx) / mwidth * math.cos(
math.radians(bbox.center().y))),
"MOP,Map Open Position,0,0\n",
"IWH,Map Image Width/Height,{},{}\n".format(mwidth, mheight),
])