def get_band_layer(self, band_num): lyr = Layer('Tiff Layer') lyr.datasource = Gdal(file=self.raster.name, band=band_num, nodata=0, shared=True) lyr.srs = self.srs lyr.styles.append(self.get_band_style_name(band_num)) return lyr
def copy_layer(obj): lyr = Layer(obj.name) lyr.abstract = obj.abstract lyr.active = obj.active lyr.clear_label_cache = obj.clear_label_cache lyr.datasource = obj.datasource #lyr.maxzoom = obj.maxzoom #lyr.minzoom = obj.minzoom lyr.queryable = obj.queryable lyr.srs = obj.srs lyr.title = obj.title if hasattr(obj,'wmsdefaultstyle'): lyr.wmsdefaultstyle = obj.wmsdefaultstyle if hasattr(obj,'wmsextrastyles'): lyr.wmsextrastyles = obj.wmsextrastyles return lyr
# conn.close() # # print records # xys = map(lambda vals:map(encodeAttr,vals),records) # MultiPoint = { "type": "MultiPoint", # "coordinates": xys # } # f = file(r"G:\mapnik\geojson\data.geojson",'w+') # f.write(str(MultiPoint)) # f.close() from mapnik import Ogr,Layer import mapnik datasource = Ogr(base='G:/mapnik/geojson',file='data.geojson',layer='OGRGeoJSON') lyr = Layer('OGR Layer from GeoJSON file') lyr.datasource = datasource m = mapnik.Map(800, 800) m.background = mapnik.Color('steelblue') s = mapnik.Style() r = mapnik.Rule() point_symbolizer = mapnik.PointSymbolizer(mapnik.PathExpression("../point.png")) # point_symbolizer = mapnik.PointSymbolizer("../point.png", "png", 16, 16) #为何这样用会报错? point_symbolizer.allow_overlap = True point_symbolizer.opacity = 0.8
t.label_placement = label_placement.POINT_PLACEMENT s1 = Style() r1 = Rule() r1.symbols.append(t) r1.filter = f s1.rules.append(r1) m.append_style('Text', s1) s = Style() r = Rule() r.symbols.append(PolygonSymbolizer(Color('#f2eff9'))) r.symbols.append(LineSymbolizer(Color('rgb(50%,50%,50%)'), 0.1)) s.rules.append(r) m.append_style('My Style', s) lyr = Layer('france', proj4) import os shp = Shapefile(base='.',file='departement') lyr.datasource = shp #lyr.datasource = SQLite(base=os.getcwd(), file = sqlitedatabase, table = tablename, geometry_field = 'Geometry', key_field = 'ID_GEOFLA', extent = shp_extent, wkb_format = 'spatialite') lyr.styles.append('My Style') lyr.styles.append('Text') m.layers.append(lyr) m.zoom_to_box(lyr.envelope()) file_formats = {'svg': cairo.SVGSurface, }
t.label_placement = label_placement.POINT_PLACEMENT s1 = Style() r1 = Rule() r1.symbols.append(t) r1.filter = f s1.rules.append(r1) m.append_style('Text', s1) s = Style() r = Rule() r.symbols.append(PolygonSymbolizer(Color('#f2eff9'))) r.symbols.append(LineSymbolizer(Color('rgb(50%,50%,50%)'), 0.1)) s.rules.append(r) m.append_style('My Style', s) lyr = Layer('france', proj4) import os shp = Shapefile(base='.', file='departement') lyr.datasource = shp #lyr.datasource = SQLite(base=os.getcwd(), file = sqlitedatabase, table = tablename, geometry_field = 'Geometry', key_field = 'ID_GEOFLA', extent = shp_extent, wkb_format = 'spatialite') lyr.styles.append('My Style') lyr.styles.append('Text') m.layers.append(lyr) m.zoom_to_box(lyr.envelope()) file_formats = { 'svg': cairo.SVGSurface,
def copy_layer(obj): lyr = Layer(obj.name) if hasattr(obj, 'title'): lyr.title = obj.title else: lyr.title = '' if hasattr(obj, 'abstract'): lyr.abstract = obj.abstract else: lyr.abstract = '' # only if mapnik version supports it # http://trac.mapnik.org/ticket/503 if hasattr(obj, 'tolerance'): lyr.tolerance = obj.tolerance if hasattr(obj, 'toleranceunits'): lyr.toleranceunits = obj.toleranceunits lyr.srs = obj.srs if hasattr(obj, 'minzoom'): lyr.minzoom = obj.minzoom if hasattr(obj, 'maxzoom'): lyr.maxzoom = obj.maxzoom lyr.active = obj.active lyr.queryable = obj.queryable lyr.clear_label_cache = obj.clear_label_cache lyr.datasource = obj.datasource if hasattr(obj, 'wmsdefaultstyle'): lyr.wmsdefaultstyle = obj.wmsdefaultstyle if hasattr(obj, 'wmsextrastyles'): lyr.wmsextrastyles = obj.wmsextrastyles if hasattr(obj, 'meta_style'): lyr.meta_style = obj.meta_style if hasattr(lyr, 'wms_srs'): lyr.wms_srs = obj.wms_srs return lyr
def copy_layer(obj): lyr = Layer(obj.name) if hasattr(obj, 'title'): lyr.title = obj.title else: lyr.title = '' if hasattr(obj, 'abstract'): lyr.abstract = obj.abstract else: lyr.abstract = '' # only if mapnik version supports it # http://trac.mapnik.org/ticket/503 if hasattr(obj, 'tolerance'): lyr.tolerance = obj.tolerance if hasattr(obj, 'toleranceunits'): lyr.toleranceunits = obj.toleranceunits lyr.srs = obj.srs lyr.minzoom = obj.minzoom lyr.maxzoom = obj.maxzoom lyr.active = obj.active lyr.queryable = obj.queryable lyr.clear_label_cache = obj.clear_label_cache lyr.datasource = obj.datasource if hasattr(obj,'wmsdefaultstyle'): lyr.wmsdefaultstyle = obj.wmsdefaultstyle if hasattr(obj,'wmsextrastyles'): lyr.wmsextrastyles = obj.wmsextrastyles if hasattr(obj,'meta_style'): lyr.meta_style = obj.meta_style if hasattr(lyr, 'wms_srs'): lyr.wms_srs = obj.wms_srs return lyr
def get_layers(self): lyr = Layer('Tiff Layer') lyr.datasource = Gdal(file=self.raster.name, nodata=0, shared=True) lyr.srs = self.srs lyr.styles.append(self.style_name) return [lyr]
from mapnik import PolygonSymbolizer, LineSymbolizer, Rule, Style, Color, Layer, Shapefile, Map, Image, render rule = Rule() rule.symbols.append(PolygonSymbolizer(Color("grey"))) rule.symbols.append(LineSymbolizer(Color("black"), 0.1)) style = Style() style.rules.append(rule) layer = Layer("world") layer.datasource = Shapefile(file="coastlines/land") layer.styles.append("world") m = Map(800, 400) m.background = Color("white") m.append_style("world", style) m.layers.append(layer) m.zoom_to_box(layer.envelope()) image = Image(800, 400) render(m, image) with open("test.png", "w") as image_file: image_file.write(image.tostring("png"))
t.label_placement = label_placement.POINT_PLACEMENT s1 = Style() r1 = Rule() r1.symbols.append(t) r1.filter = f s1.rules.append(r1) m.append_style('Text', s1) s = Style() r = Rule() r.symbols.append(PolygonSymbolizer(Color('#f2eff9'))) r.symbols.append(LineSymbolizer(Color('rgb(50%,50%,50%)'), 0.1)) s.rules.append(r) m.append_style('My Style', s) lyr = Layer('france', proj4) import os lyr.datasource = SQLite(base=os.getcwd(), file = sqlitedatabase, table = tablename, geometry_field = 'Geometry', key_field = 'pkuid', extent = shp_extent, wkb_format = 'spatialite') lyr.styles.append('My Style') lyr.styles.append('Text') m.layers.append(lyr) m.zoom_to_box(lyr.envelope()) file_formats = {'svg': cairo.SVGSurface, } for type_format in file_formats: print '// -- Rendering %s -----------------------------' % type_format file_open = open('%s.%s' % (map_output, type_format), 'w')
t = TextSymbolizer('code_dept', 'DejaVu Sans Book', 8, Color('black')) f = Filter("[code_dept]<>'75' and [code_dept]<>'92' and [code_dept]<>'93' and [code_dept]<>'94'") t.allow_overlap = 1 t.label_placement = label_placement.POINT_PLACEMENT s1 = Style() r1 = Rule() r1.symbols.append(t) r1.filter = f s1.rules.append(r1) m.append_style('Text', s1) s.rules.append(r) m.append_style('My Style', s) lyr = Layer('france', proj4) import os lyr.datasource = SQLite(base=os.getcwd(), file = sqlitedatabase, table = tablename, geometry_field = 'Geometry', key_field = 'pkuid', extent = '99226.000000,6049647.000000,1242375.000000,7110524.000000', wkb_format = 'spatialite') lyr.styles.append('My Style') lyr.styles.append('Text') m.layers.append(lyr) m.zoom_to_box(lyr.envelope()) file_formats = {'svg': cairo.SVGSurface, } for type_format in file_formats: print '// -- Rendering %s -----------------------------' % type_format file_open = open('%s.%s' % (map_output, type_format), 'w')
import mapnik from mapnik import PostGIS, Layer m = mapnik.Map(256, 256) s = mapnik.Style() r = mapnik.Rule() ptsym = mapnik.PointSymbolizer() r.symbols.append(ptsym) s.rules.append(r) m.append_style('My Style', s) lyr = Layer('PostGIS') ds = PostGIS(host='database.lambnik.azavea.com', user='******', password='******', dbname='lambnik-test', table='pwd_inlets') lyr.datasource = ds lyr.styles.append('My Style') m.layers.append(lyr) m.zoom_all() mapnik.render_to_file(m, 'test.png', 'png')