def simple_points_and_lines(self): self.set_step_name('Simple Points and Lines') self.set_text('You should see a four segment red line, and\n' + 'a blue cross hair 12 pixels tall.\n\n' + 'Try zooming in, the crosshair should *not* get bigger.') shapes = gview.GvShapes() gview.undo_register(shapes) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(20, 50, node=0) shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_LINE) shape.set_node(10, 10, node=0) shape.set_node(80, 10, node=1) shape.set_node(80, 90, node=2) shape.set_node(50, 80, node=3) shape.set_node(10, 90, node=4) shapes.append(shape) layer = gview.GvShapesLayer(shapes) layer.set_name('test_poly') layer.set_property('_line_color', '255 0 0 255') layer.set_property('_line_width', '3') layer.set_property('_point_color', '0 0 255 255') layer.set_property('_point_size', '12') self.view.add_layer(layer) self.view.set_active_layer(layer) self.view.fit_extents(0, 0, 100, 100)
def transparent_poly(self): self.set_step_name('Polygon Transparency') self.set_text('You should see two overlaping polygons, with the\n' + 'rear one showing through the top one a little.') shapes = gview.GvShapes() gview.undo_register(shapes) poly = gview.GvShape(type=gview.GVSHAPE_AREA) poly.set_node(20, 5, node=0) poly.set_node(40, 5, node=1) poly.set_node(30, 50, node=2) shapes.append(poly) poly = gview.GvShape(type=gview.GVSHAPE_AREA) poly.set_node(10, 10, node=0) poly.set_node(80, 10, node=1) poly.set_node(80, 90, node=2) poly.set_node(50, 80, node=3) poly.set_node(10, 90, node=4) poly.set_node(10, 10, node=5) shapes.append(poly) layer = gview.GvShapesLayer(shapes) layer.set_name('test_poly') layer.set_property('_area_edge_color', '255 0 0 255') layer.set_property('_area_fill_color', '0 0 255 150') layer.set_property('_area_edge_width', '3') self.view.add_layer(layer) self.view.set_active_layer(layer) self.view.fit_extents(0, 0, 100, 100)
def ogrfs_points2(self): self.set_step_name('OGRFS Point Symbols') self.set_text( \ 'In the bottom right corner should be a yellow triangle\n' + 'pointing "north west".\n' + '\n' + 'In the middle should be a white cross hair.\n' + 'To the top/right is a red X.\n' + 'To the lower/left is a green X.\n' + '\n' + 'As you zoom in the red X should remain a constant distance\n' + 'in screen pixels from the white cross. It is "offset" from\n' + 'the white cross a distance in screen pixels.\n' + '\n' + 'The green X is offset by a "georeferenced" distance, and\n' + 'should move closer as you zoom out, and further as you zoom\n' + 'in.\n' + '\n' + '\n' + '\n' ) shapes = gview.GvShapes() gview.undo_register(shapes) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(15, 15, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFF00,a:45,s:3,id:ogr-sym-7)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 50, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFFFF,s:2,id:ogr-sym-0)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 50, node=0) shape.set_property( '_gv_ogrfs', 'SYMBOL(c:#FF0000,dx:20px,dy:10px,s:1,id:ogr-sym-1)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 50, node=0) shape.set_property( '_gv_ogrfs', 'SYMBOL(c:#00FF00,dx:-10g,dy:-5g,s:1,id:ogr-sym-1)') shapes.append(shape) layer = gview.GvShapesLayer(shapes) layer.set_name('test') self.view.add_layer(layer) self.view.set_active_layer(layer) self.view.fit_extents(0, 0, 100, 100)
def simple_poly(self): self.set_step_name('Simple Polygon Display') self.set_text('You should see a five sided polygon with a red edge\n' + 'and blue fill. The edge should be 3 pixels wide.\n' + 'The polygon should have a triangular hole.') shapes = gview.GvShapes() gview.undo_register(shapes) poly = gview.GvShape(type=gview.GVSHAPE_AREA) poly.set_node(10, 10, node=0) poly.set_node(80, 10, node=1) poly.set_node(80, 90, node=2) poly.set_node(50, 80, node=3) poly.set_node(10, 90, node=4) poly.set_node(10, 10, node=5) poly.set_node(20, 20, node=0, ring=1) poly.set_node(40, 20, node=1, ring=1) poly.set_node(30, 50, node=2, ring=1) shapes.append(poly) layer = gview.GvShapesLayer(shapes) layer.set_name('test_poly') layer.set_property('_area_edge_color', '255 0 0 255') layer.set_property('_area_fill_color', '0 0 255 255') layer.set_property('_area_edge_width', '3') self.view.add_layer(layer) self.view.set_active_layer(layer) self.view.fit_extents(0, 0, 100, 100)
def SimpleNorthLayer(xoffset, yoffset, ntype=GVNORTHSYM1, color1=(0.0, 0.0, 0.0, 1.0), color2=(1.0, 1.0, 1.0, 1.0), scale=1.0, shapes_name="North Arrow"): """ Create a layer with a North arrow symbol, with the North arrow located at (xoffset,yoffset). The 'ntype' parameter will eventually be used for different types of north arrows. The layer will contain two shapes: an area or line, and label. Input: xoffset,yoffset- where to center North Arrow (in display coordinates). ntype- index of north arrow type (currently only one type). color1- First color and outline color for north arrow. A tuple of 4 values between 0 and 1. color2- Second color (not used yet). scale- amount to scale size of symbol by. shapes_name- name to give the shapes that form the north arrow. """ shps = gview.GvShapes(name=shapes_name) gview.undo_register(shps) nshp = gview.GvShape(type=gview.GVSHAPE_POINT) nshp.set_node(xoffset, yoffset) cstr1 = gvogrfs.gv_to_ogr_color(color1) if len(cstr1) < 9: cstr1 = cstr1 + "FF" refname, sm = CreateNorthSymbol(ntype, color1, color2, scale) dxstr = str(-1.5 * scale) dystr = str(-15.0 * scale) nshp.set_property('_gv_ogrfs', 'SYMBOL(c:'+cstr1+',s:4,id:"'+refname+'");'+\ 'LABEL(c:'+cstr1+',t:"N",dx:'+dxstr+\ ',dy:'+dystr+')' ) shps.append(nshp) layer = gview.GvShapesLayer(shps) # Set antialias property so that lines look nice # when rotated. layer.set_property('_gl_antialias', '1') return layer
def ogrfs_lines(self): self.set_step_name('OGRFS Lines') self.set_text( 'You should see a thick (8 pixels wide) green line\n' + 'with a thin (2 pixel wide) red line down the center.\n' + '\n' + 'You should also see a second line in blue rendered \n' + 'in a dash-dot pattern\n' + '') shapes = gview.GvShapes() gview.undo_register(shapes) shape = gview.GvShape(type=gview.GVSHAPE_LINE) shape.set_node(10, 10, node=0) shape.set_node(80, 10, node=1) shape.set_node(80, 90, node=2) shape.set_node(50, 80, node=3) shape.set_node(10, 90, node=4) shape.set_property('_gv_ogrfs', 'PEN(c:#00FF00,w:8);PEN(c:#FF0000,w:2)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_LINE) shape.set_node(20, 20, node=0) shape.set_node(40, 20, node=1) shape.set_node(40, 40, node=2) shape.set_node(60, 60, node=3) shape.set_node(40, 80, node=4) shape.set_property('_gv_ogrfs', 'PEN(c:#0000FF,w:2,p:ogr-pen-6)') shapes.append(shape) layer = gview.GvShapesLayer(shapes) layer.set_name('test') self.view.add_layer(layer) self.view.set_active_layer(layer) self.view.fit_extents(0, 0, 100, 100)
def CreateNorthSymbol(ntype=GVNORTHSYM1, color1=(0.0, 0.0, 0.0, 1.0), color2=(1.0, 1.0, 1.0, 1.0), scale=1.0, symbol_manager=None): """ Create the North Symbol and put it in a symbol manager. Input: ntype- type of north arrow to create color1- first color color2- second color (if needed) scale- amount to scale size by. symbol_manager- symbol manager to inject symbol into (a new one will be created if this is set to None). """ if symbol_manager is None: sm = gview.GvSymbolManager() else: sm = symbol_manager cstr1 = gvogrfs.gv_to_ogr_color(color1) if len(cstr1) < 9: cstr1 = cstr1 + "FF" cstr2 = gvogrfs.gv_to_ogr_color(color2) if len(cstr2) < 9: cstr2 = cstr2 + "FF" sstr = string.replace(str(scale), '.', '_') refname = ntype + cstr1[1:] + cstr2[1:] + sstr if ntype == GVNORTHSYM1: shape = gview.GvShape(type=gview.GVSHAPE_AREA) shape.set_node(1.0 * scale, -2.6 * scale, node=0) shape.set_node(0.0, -0.8 * scale, node=1) shape.set_node(-1.0 * scale, -2.6 * scale, node=2) shape.set_node(0.0, 2.6 * scale, node=3) shape.set_node(1.0 * scale, -2.6 * scale, node=4) shape.set_property('_gv_ogrfs','PEN(c:'+cstr1+');BRUSH(c:'+\ cstr2+')') sm.inject_vector_symbol(refname, shape) return (refname, sm)
def create_taskforce_indicator( self, repeat, size, offset ): """ create a taskforce indicator which is a rectangle with no bottom that fits over a size indicator. Repeat is the number of size indicator symbols to cover. Offset is the number of pixels apart that they are. Size is the vertical size of the symbol. """ dx = ((offset/2.0) * (repeat)) + 2 dy = size + 2 shape = gview.GvShape( type = gview.GVSHAPE_LINE ) shape.add_node( -dx, -dy ) shape.add_node( -dx, dy ) shape.add_node( dx, dy ) shape.add_node( dx, -dy ) return shape
def new_label(self): ####################################################################### # Create a new point shape at the current pointer location. pointer_loc = self.view.get_pointer() new_label = gview.GvShape(type=gview.GVSHAPE_POINT) new_label.set_node(pointer_loc[0], pointer_loc[1]) new_label._gv_ogrfs = self.default_ogrfs ####################################################################### # Attach it to the current layer, and make it selected. shapes = self.layer.get_parent() id = shapes.append(new_label) self.layer.clear_selection() self.layer.select_shape(id) self.edit_mode = 1 self.get_window()._raise() self.label_style.text_entry.grab_focus()
def create_size_indicator( self, sym_name, repeat, size, offset ): """ compose a size indicator based on some number (repeat) of symbols (sym_name) drawn at scale (size). The symbols are drawn horizontally spaced at (offset) pixels apart, centered at 0. """ shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 0.0, 0.0, node=0 ) ogrfs = "" dx_val = -1 * (offset / 2) * (repeat - 1) for i in range( repeat ): dx = "" if abs(dx_val) > 0.001: dx = ",dx:%spx" % dx_val sym = "SYMBOL(id:%s%s%s,s:%s)" % (os.sep, sym_name, dx, size) if ogrfs != "": ogrfs = ogrfs + ";" ogrfs = ogrfs + sym dx_val = dx_val + offset shape.set_property( "_gv_ogrfs", ogrfs ) return shape
def prepare_legend(self): if self.resizing: return if self.layer.get_property('Class_sn') is not None: self.Class_sn = int(self.layer.get_property('Class_sn')) #remove any existing shapes self.shapes.delete_shapes(range(len(self.shapes))) samp_x_size = gview.get_preference('legend-sample-x-size') if samp_x_size is None: samp_x_size = 20 else: samp_x_size = int(samp_x_size) samp_y_size = gview.get_preference('legend-sample-y-size') if samp_y_size is None: samp_y_size = 20 else: samp_y_size = int(samp_y_size) title_font = pgufont.XLFDFontSpec() font_spec = gview.get_preference('legend-title-font') if font_spec is None: title_font.set_font_part('Family', 'times') title_font.set_font_part('Pixel Size', '20') else: title_font.parse_font_spec(font_spec) title_font_color = gview.get_preference('legend-title-font-color') if title_font_color is None: title_font_color = (0.0, 0.0, 0.0, 1.0) else: title_font_color = color_string_to_tuple(title_font_color) title_ogr_color = gv_to_ogr_color(title_font_color) label_font = pgufont.XLFDFontSpec() font_spec = gview.get_preference('legend-label-font') if font_spec is None: label_font.set_font_part('Family', 'times') label_font.set_font_part('Pixel Size', '14') else: label_font.parse_font_spec(font_spec) label_font_color = gview.get_preference('legend-label-font-color') if label_font_color is None: label_font_color = (0.0, 0.0, 0.0, 1.0) else: label_font_color = color_string_to_tuple(label_font_color) label_ogr_color = gv_to_ogr_color(label_font_color) #handle large fonts in the sample text try: gdk_font = load_font(str(label_font)) except: # get a default font if preferred one # can't be loaded. gdk_font = load_font('*') h = gdk_font.height("Wj") samp_offset = max(samp_y_size, h) + 10 #handle multi-line text for the title. try: gdk_title_font = load_font(str(title_font)) except: gdk_title_font = load_font('*') lines = string.split(self.classification.title, '\\n') x_offset = 10 #start title 10 pixels in from left edge col_offset = 30 #space columns apart y_offset = 35 #start title 35 pixels down from top edge title_width = 0 max_height = 0 #resize the window appropriately title_height = y_offset title_width = 0 for idx in range(len(lines)): line = lines[idx] title_height = title_height + gdk_title_font.height(line) title_width = max(title_width, gdk_title_font.width(line)) title_height = title_height + 10 title_width = x_offset + title_width + 10 cols = int(self.classification.count / 8) samps = min(8, self.classification.count) samp_height = samps * (samp_offset) + 10 samp_width = x_offset for i in range(cols + 1): idx = 8 * i col_width = 0 while idx < self.classification.count and idx < 8 * (i + 1): name = self.classification.name[idx] width = samp_x_size + 20 + gdk_font.width(name) col_width = max(col_width, width) idx = idx + 1 samp_width = samp_width + col_width + col_offset samp_width = samp_width + 10 total_width = max(title_width, samp_width) total_height = title_height + samp_height self.resizing = TRUE if (self.get_window().width < total_width) or \ (self.get_window().height < total_height): self.resize_count = self.resize_count + 1 if self.resize_count < 2: self.set_usize(total_width, total_height) self.resizing = FALSE for idx in range(len(lines)): line = lines[idx] w = gdk_title_font.width(line) h = gdk_title_font.height(line) title_width = max(title_width, w) samp_text = gview.GvShape() samp_text.add_node(x_offset, y_offset) samp_text.set_property( '_gv_ogrfs', 'LABEL(c:' + title_ogr_color + \ ',f:"' + str(title_font) + '",' \ + 't:"' + line + '")' ) self.shapes.append(samp_text) y_offset = y_offset + h if ((len(lines[0]) > 6) and (lines[0][:6] != 'Legend') and (lines[0][:6] != 'legend')): self.set_title('Legend: ' + lines[0] + '...') else: self.set_title(lines[0] + '...') y_offset = y_offset + 10 title_offset = y_offset max_width = 0 max_height = 0 for class_id in range(self.classification.count): color = self.classification.get_color(class_id) symbol = self.classification.get_symbol(class_id) scale = self.classification.get_scale(class_id) if symbol is not None: samp = gview.GvShape(type=gview.GVSHAPE_POINT) samp.add_node(x_offset + (samp_x_size / 2), y_offset + (samp_y_size / 2)) ogrfs_color = '#%02x%02x%02x%02x' % ( int(color[0] * 255.999), int(color[1] * 255.999), int(color[2] * 255.999), int(color[3] * 255.999)) ogrfs = "SYMBOL(id:%s,c:%s,s:%s)" % (symbol, ogrfs_color, scale) samp.set_property("_gv_ogrfs", ogrfs) else: samp = gview.GvShape(type=gview.GVSHAPE_AREA) samp.add_node(x_offset, y_offset) samp.add_node(x_offset + samp_x_size, y_offset) samp.add_node(x_offset + samp_x_size, y_offset + samp_y_size) samp.add_node(x_offset, y_offset + samp_y_size) samp.add_node(x_offset, y_offset) color = '%f %f %f %f' % color samp.set_property('_gv_color', color) samp.set_property('_gv_fill_color', color) self.shapes.append(samp) name = self.classification.name[class_id] samp_text = gview.GvShape() samp_text.add_node(x_offset + samp_x_size + 10, y_offset + 17) font = str(label_font) samp_text.set_property( '_gv_ogrfs', 'LABEL(c:' + label_ogr_color + \ ',f:"'+font+'",t:"'+name+'")' ) self.shapes.append(samp_text) this_width = samp_x_size + 20 + gdk_font.width(name) if max_width < this_width: max_width = this_width y_offset = y_offset + samp_offset if y_offset + samp_offset > self.viewarea.get_height(): max_height = max(max_height, y_offset + samp_offset) y_offset = title_offset x_offset = x_offset + col_offset + max_width max_width = 0 self.vlayer.changed()
def raster_symbol(self): self.set_step_name('Raster Symbol Test') self.set_text('A red symbol (the busy indicator from thet toolbar)\n' + 'should be shown. When zooming in or out it should\n' + 'remain the same size on screen.\n' + '' + 'NOTE: This symbols should really be green but it\n' + 'seems that currently the color attribute of\n' + 'SYMBOL directives for raster symbols is ignored\n' + '\n' + '\n' + '') shapes = gview.GvShapes() gview.undo_register(shapes) layer = gview.GvShapesLayer(shapes) layer.set_name('test') if os.name == "nt": sym_file = gview.home_dir + '\\pics\\busy.xpm' sym_file2 = gview.home_dir + '\\pics\\idle.xpm' sym_name = '\\three_idle' else: sym_file = gview.home_dir + '/pics/busy.xpm' sym_file2 = gview.home_dir + '/pics/idle.xpm' sym_name = '/three_idle' # Unoffset icon shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(20, 50, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#00FF00,id:"' + sym_file + '")') shapes.append(shape) # Pixel Offset shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(20, 50, node=0) shape.set_property( '_gv_ogrfs', 'SYMBOL(c:#00FF00,dx:30px,dy:-10px,id:"' + sym_file + '")') shapes.append(shape) # Geo Offset shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(20, 50, node=0) shape.set_property( '_gv_ogrfs', 'SYMBOL(c:#00FF00,dx:30g,dy:-30g,id:"' + sym_file + '")') shapes.append(shape) # Inject a vector icon symbol that consists of three raster symbols, # but do it on the vector layer. sm = layer.get_symbol_manager(1) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(0.0, 0, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(dy:-10px,dx:-40px,id:"' + sym_file2 + '");' + \ 'SYMBOL(id:"' + sym_file2 + '");' + \ 'SYMBOL(dy:10px,dx:40px,id:"' + sym_file2 + '")' ) sm.inject_vector_symbol(sym_name, shape) # Place the "3" idle symbol. shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(60, 50, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#00FF00,id:"' + sym_name + '")') shapes.append(shape) # Add line for context. shape = gview.GvShape(type=gview.GVSHAPE_LINE) shape.set_node(10, 10, node=0) shape.set_node(80, 10, node=1) shape.set_node(80, 90, node=2) shape.set_node(50, 80, node=3) shape.set_node(10, 90, node=4) shapes.append(shape) self.view.add_layer(layer) self.view.set_active_layer(layer) self.view.fit_extents(0, 0, 100, 100)
def SimpleReferenceGrid(min_x, min_y, max_x, max_y, x_divisions, y_divisions, color=(0.5, 1.0, 0.5, 1.0), xoff=-0.15, yoff=-0.04, label_type=None, shapes_name="Grid"): """ Create a reference grid for an unprojected raster. min_x, min_y- minimum lat/longs, in decimal degrees max_x, max_y- minimum lat/longs, in decimal degrees x_divisions- number of divisions in horizontal direction y_divisions- number of divisions in vertical direction xoff- horizontal offset of vertical labels, as a fraction of max_x-min_x. Offset is relative to min_x. yoff- vertical offset of horizontal labels, as a fraction of max_y-min_y. Offset is relative to min_y. color- start color for the grid label_type- not used yet; might be later for formatting. """ shps = gview.GvShapes(name=shapes_name) gview.undo_register(shps) shps.add_field('position', 'string', 20) if os.name == 'nt': font = "-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*" else: #font="-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*" #font="-urw-helvetica-medium-r-normal-*-9-*-*-*-p-*-iso8859-2" font = "-adobe-helvetica-medium-r-normal-*-8-*-*-*-p-*-iso10646-1" #font="-misc-fixed-medium-r-*-*-9-*-*-*-*-*-*-*" lxoff = (max_x - min_x) * xoff # horizontal label placement lyoff = (max_y - min_y) * yoff # vertical label placement hspc = (max_x - min_x) / x_divisions vspc = (max_y - min_y) / y_divisions for hval in Numeric.arange(min_x, max_x + hspc / 100.0, hspc): nshp = gview.GvShape(type=gview.GVSHAPE_LINE) nshp.set_node(hval, max_y, 0, 0) nshp.set_node(hval, min_y, 0, 1) shps.append(nshp) pshp = gview.GvShape(type=gview.GVSHAPE_POINT) pshp.set_node(hval, min_y + lyoff) pshp.set_property('position', "%.1f" % hval) shps.append(pshp) for vval in Numeric.arange(min_y, max_y + vspc / 100.0, vspc): nshp = gview.GvShape(type=gview.GVSHAPE_LINE) nshp.set_node(min_x, vval, 0, 0) nshp.set_node(max_x, vval, 0, 1) shps.append(nshp) pshp = gview.GvShape(type=gview.GVSHAPE_POINT) pshp.set_node(min_x + lxoff, vval) pshp.set_property('position', "%.1f" % vval) shps.append(pshp) cstr = gvogrfs.gv_to_ogr_color(color) if len(cstr) < 9: cstr = cstr + "FF" clstr = str(color[0]) + ' ' + str(color[1]) + ' ' + str( color[2]) + ' ' + str(color[3]) layer = gview.GvShapesLayer(shps) layer.set_property('_line_color', clstr) layer.set_property('_point_color', clstr) # Set antialias property so that lines look nice # when rotated. layer.set_property('_gl_antialias', '1') layer.set_property('_gv_ogrfs_point', 'LABEL(t:{position},f:"' + font + '",c:' + cstr + ')') layer.set_read_only(gtk.TRUE) return layer
def size_symbols( self ): self.set_step_name( 'Military Size Symbols' ) self.set_text( \ 'Here you will see each of the size designators for various sizes\n' + 'of military symbols\n' ) shapes = gview.GvShapes() gview.undo_register( shapes) sm = gview.GvSymbolManager() #symbol_size * base_size * 2 define the size of the symbol on screen. base_size = 1.0 symbol_size = 3.0 #the number of pixels wide to make the task force indicator tf_offset = ( symbol_size * base_size * 2 ) + 2 symbol_offset = tf_offset #create the circle symbol as a multiline with n points import math circle = gview.GvShape( type=gview.GVSHAPE_LINE ) filled_circle = gview.GvShape( type=gview.GVSHAPE_AREA ) n = 8 radius = base_size for i in range( n + 1 ): angle = (float(i)*(360.0/float(n))) / (180.0/math.pi) x = math.sin( angle ) * radius y = math.cos( angle ) * radius circle.add_node( x, y, 0.0 ) filled_circle.add_node( x, y, 0.0 ) circle.set_property( "_gv_ogrfs", "PEN(w:1)" ) filled_circle.set_property( "_gv_ogrfs", "PEN(w:1);BRUSH()" ) sm.inject_vector_symbol( "%scircle" % os.sep, circle ) sm.inject_vector_symbol( "%sfilled_circle" % os.sep, filled_circle) #create a vertical bar symbol shape = gview.GvShape(type=gview.GVSHAPE_LINE ) shape.add_node( 0.0, -base_size, 0.0 ) shape.add_node( 0.0, base_size, 0.0 ) shape.set_property( "_gv_ogrfs", "PEN(w:1)" ) sm.inject_vector_symbol( "%svertical_bar" % os.sep, shape ) #now create a cross from rotated vertical bars shape = gview.GvShape(type=gview.GVSHAPE_LINE ) shape.add_node( -base_size, -base_size, 0.0 ) shape.add_node( base_size, base_size, 0.0 ) shape.set_property( "_gv_ogrfs", "PEN(w:1)" ) sm.inject_vector_symbol( "%sline_45" % os.sep, shape ) shape = gview.GvShape(type=gview.GVSHAPE_LINE ) shape.add_node( -base_size, base_size, 0.0 ) shape.add_node( base_size, -base_size, 0.0 ) shape.set_property( "_gv_ogrfs", "PEN(w:1)" ) sm.inject_vector_symbol( "%sline_315" % os.sep, shape ) shape = gview.GvShape(type=gview.GVSHAPE_POINT ) shape.add_node( 0.0, 0.0, 0.0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(id:%sline_45);SYMBOL(id:%sline_315)" % ( os.sep, os.sep ) ) sm.inject_vector_symbol( "%scross" % os.sep, shape ) #taskforce 1 shape = self.create_taskforce_indicator( 1, symbol_size * base_size, tf_offset ) sm.inject_vector_symbol( "%stf_1" % os.sep, shape ) #taskforce 2 shape = self.create_taskforce_indicator( 2, symbol_size * base_size, tf_offset ) sm.inject_vector_symbol( "%stf_2" % os.sep, shape ) #taskforce 3 shape = self.create_taskforce_indicator( 3, symbol_size * base_size, tf_offset ) sm.inject_vector_symbol( "%stf_3" % os.sep, shape ) #taskforce 4 shape = self.create_taskforce_indicator( 4, symbol_size * base_size, tf_offset ) sm.inject_vector_symbol( "%stf_4" % os.sep, shape ) #taskforce 5 shape = self.create_taskforce_indicator( 5, symbol_size * base_size, tf_offset ) sm.inject_vector_symbol( "%stf_5" % os.sep, shape ) #taskforce 6 shape = self.create_taskforce_indicator( 6, symbol_size * base_size, tf_offset ) sm.inject_vector_symbol( "%stf_6" % os.sep, shape ) #team symbol shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 0.0, 0.0, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(id:%scircle,s:%s);SYMBOL(id:%sline_45,s:%s)" % (os.sep, symbol_size, os.sep, symbol_size) ) sm.inject_vector_symbol( "%steam" % os.sep, shape ) #squad symbol shape = self.create_size_indicator( "filled_circle", 1, symbol_size, symbol_offset ) sm.inject_vector_symbol( "%ssquad" % os.sep, shape ) #section symbol shape = self.create_size_indicator( "filled_circle", 2, symbol_size, symbol_offset ) sm.inject_vector_symbol( "%ssection" % os.sep, shape ) #platoon symbol shape = self.create_size_indicator( "filled_circle", 3, symbol_size, symbol_offset ) sm.inject_vector_symbol( "%splatoon" % os.sep, shape ) #company symbol shape = self.create_size_indicator( "vertical_bar", 1, symbol_size, symbol_offset ) sm.inject_vector_symbol( "%scompany" % os.sep, shape ) #battalion symbol shape = self.create_size_indicator( "vertical_bar", 2, symbol_size, symbol_offset ) sm.inject_vector_symbol( "%sbattalion" % os.sep, shape ) #regiment symbol shape = self.create_size_indicator( "vertical_bar", 3, symbol_size, symbol_offset ) sm.inject_vector_symbol( "%sregiment" % os.sep, shape ) #brigade symbol shape = self.create_size_indicator( "cross", 1, symbol_size, symbol_offset ) sm.inject_vector_symbol( "%sbrigade" % os.sep, shape ) #division symbol shape = self.create_size_indicator( "cross", 2, symbol_size, symbol_offset ) sm.inject_vector_symbol( "%sdivision" % os.sep, shape ) print 'Division:' + shape.get_property('_gv_ogrfs') #corps symbol shape = self.create_size_indicator( "cross", 3, symbol_size, symbol_offset ) sm.inject_vector_symbol( "%scorps" % os.sep, shape ) #army symbol shape = self.create_size_indicator( "cross", 4, symbol_size, symbol_offset ) sm.inject_vector_symbol( "%sarmy" % os.sep, shape ) #armygroup symbol shape = self.create_size_indicator( "cross", 5, symbol_size, symbol_offset ) sm.inject_vector_symbol( "%sarmygroup" % os.sep, shape ) #region symbol shape = self.create_size_indicator( "cross", 6, symbol_size, symbol_offset ) sm.inject_vector_symbol( "%sregion" % os.sep, shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 10, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"team\")" ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 10, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%steam)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 10, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%steam);SYMBOL(c:#00FFFF,id:%stf_1" % (os.sep,os.sep) ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 15, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"squad\")" ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 15, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%ssquad)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 15, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%ssquad);SYMBOL(c:#00FFFF,id:%stf_1" % (os.sep,os.sep) ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 20, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"section\")" ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 20, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%ssection)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 20, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%ssection);SYMBOL(c:#00FFFF,id:%stf_2" % (os.sep,os.sep) ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 25, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"platoon\")" ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 25, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%splatoon)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 25, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%splatoon);SYMBOL(c:#00FFFF,id:%stf_3" % (os.sep,os.sep) ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 30, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"company\")" ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 30, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%scompany)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 30, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%scompany);SYMBOL(c:#00FFFF,id:%stf_1" % (os.sep,os.sep) ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 35, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"battalion\")" ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 35, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sbattalion)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 35, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sbattalion);SYMBOL(c:#00FFFF,id:%stf_2" % (os.sep,os.sep) ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 40, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"regiment\")" ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 40, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sregiment)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 40, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sregiment);SYMBOL(c:#00FFFF,id:%stf_3" % (os.sep,os.sep) ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 45, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"brigade\")" ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 45, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sbrigade)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 45, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sbrigade);SYMBOL(c:#00FFFF,id:%stf_1" % (os.sep,os.sep) ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 50, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"division\")") shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 50, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sdivision)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 50, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sdivision);SYMBOL(c:#00FFFF,id:%stf_2" % (os.sep,os.sep) ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 55, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"corps\")" ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 55, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%scorps)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 55, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%scorps);SYMBOL(c:#00FFFF,id:%stf_3" % (os.sep,os.sep) ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 60, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"army\")" ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 60, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sarmy)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 60, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sarmy);SYMBOL(c:#00FFFF,id:%stf_4" % (os.sep,os.sep) ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 65, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"armygroup\")" ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 65, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sarmygroup)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 65, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sarmygroup);SYMBOL(c:#00FFFF,id:%stf_5" % (os.sep,os.sep) ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 10, 70, node=0 ) shape.set_property( "_gv_ogrfs", "LABEL(c:#00FFFF,t:\"region\")" ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 30, 70, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sregion)" % os.sep ) shapes.append( shape ) shape = gview.GvShape( type = gview.GVSHAPE_POINT ) shape.set_node( 50, 70, node=0 ) shape.set_property( "_gv_ogrfs", "SYMBOL(c:#00FFFF,id:%sregion);SYMBOL(c:#00FFFF,id:%stf_6" % (os.sep,os.sep) ) shapes.append( shape ) # Create the layer and display #turn off display lists for now. #gview.set_preference('display_lists', "OFF" ) layer = gview.GvShapesLayer( shapes ) layer.set_name( 'test' ) layer.set_property( "_gl_antialias", "1" ) self.view.add_layer( layer ) self.view.set_active_layer( layer ) self.view.fit_extents( 0, 0, 100, 100 )
def ogrfs_points(self): self.set_step_name('OGRFS Point Symbols') self.set_text( 'You should see two rows of yellow symbols.\n' + 'First Row: plus, circle, box, triangle, start\n' + 'Second Row: X, filled circle, box, triangle and star\n' + '\n' + 'Symbols should stay the same size when you zoom.\n' + '\n' + '\n' + '\n' + '') shapes = gview.GvShapes() gview.undo_register(shapes) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(15, 30, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFF00,s:3,id:ogr-sym-1)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(15, 15, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFF00,s:3,id:ogr-sym-0)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(30, 15, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFF00,s:3,id:ogr-sym-2)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(30, 30, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFF00,s:3,id:ogr-sym-3)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(45, 15, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFF00,s:3,id:ogr-sym-4)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(45, 30, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFF00,s:3,id:ogr-sym-5)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(60, 15, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFF00,s:3,id:ogr-sym-6)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(60, 30, 35, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFF00,s:3,id:ogr-sym-7)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(75, 15, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFF00,s:3,id:ogr-sym-8)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(75, 30, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFF00,s:3,id:ogr-sym-9)') shapes.append(shape) layer = gview.GvShapesLayer(shapes) layer.set_name('test') self.view.add_layer(layer) self.view.set_active_layer(layer) self.view.fit_extents(0, 0, 100, 100)
def SimpleScalebarLayer(xoffset, yoffset, dwidth, swidth, angle, units_label=None, stype=GVSCALE1, color1=(0.0, 0.0, 0.0, 1.0), color2=(1.0, 1.0, 1.0, 1.0), offset=-0.2, shapes_name="Scale Bar"): """ Create a layer with a Scale bar located at stretching from dmin to dmax on the display Input: xoffset,yoffset- where to center scale bar (in display coordinates) dwidth- width of scale bar in display coordinates swidth- width of scale bar in scale coordinates (same if scale units and geocoding units are the same; different if for example display is UTM- meters- and scale bar is in km) angle- angle of scale bar relative to display (in RADIANS) units_label- label for units (left out if None) stype- index of scale bar type (currently must be 0) color1- First color and outline color for scale bar. A tuple of 4 values between 0 and 1. color2- Second color (only used in alternating scale bars) offset- Vertical offset of labels for scale bar as a fraction of scale bar width. shapes_name- name to give the shapes that form the scalebar. """ shps = gview.GvShapes(name=shapes_name) gview.undo_register(shps) shps.add_field('label', 'string', 20) if os.name == 'nt': font = "-adobe-helvetica-medium-r-*-*-15-*-*-*-*-*-*-*" else: #font="-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*" #font="-urw-helvetica-medium-r-normal-*-9-*-*-*-p-*-iso8859-2" font = "-adobe-helvetica-medium-r-normal-*-8-*-*-*-p-*-iso10646-1" #font="-misc-fixed-medium-r-*-*-9-*-*-*-*-*-*-*" sc = dwidth / swidth svals, labels = GetScaleBlocks(swidth) cstr1=str(color1[0])+' '+str(color1[1])+' '+str(color1[2])+\ ' '+str(color1[3]) cstr2=str(color2[0])+' '+str(color2[1])+' '+str(color2[2])+\ ' '+str(color2[3]) if stype == GVSCALE1: # Rectangle with alternating filled/unfilled # sections. smax = svals[len(svals) - 1] # rectangle nodes before rotation hbr = (svals - (smax / 2.0)) * sc # horizontal- shift to -smax/2:+smax/2 # so that rectangle is centered about 0. # rectangle extends from -smax/20 (bbr) to +smax/20 (tbr) vertically, # labels are placed at + or - smax/5 tbr = smax / 20.0 * Numeric.ones(Numeric.shape(hbr)) bbr = -1 * smax / 20.0 * Numeric.ones(Numeric.shape(hbr)) lbr = offset * smax * Numeric.ones(Numeric.shape(hbr)) # units label location before rotation uxbr = (hbr[len(hbr) - 1] - hbr[0]) * 0.05 + hbr[len(hbr) - 1] # rotate ctheta = Numeric.cos(angle) stheta = Numeric.sin(angle) tx = hbr * ctheta - tbr * stheta + xoffset ty = hbr * stheta + tbr * ctheta + yoffset bx = hbr * ctheta - bbr * stheta + xoffset by = hbr * stheta + bbr * ctheta + yoffset lx = hbr * ctheta - lbr * stheta + xoffset ly = hbr * stheta + lbr * ctheta + yoffset ux = uxbr * ctheta + xoffset uy = uxbr * stheta + yoffset # LATER: once shape collections are working, use them instead # so that entire scale bar can be selected and shifted as # a whole rather than separate shapes... #shp=gview.GvShape(type=gview.GVSHAPE_COLLECTION) #shp.set_property('_gv_ogrfs_point', # 'LABEL(t:{label},f:"%s",c:#000000FF)' % font) #shps.append(shp) for idx in range(len(tx) - 1): nshp = gview.GvShape(type=gview.GVSHAPE_AREA) nshp.add_node(tx[idx], ty[idx], 0) nshp.add_node(tx[idx + 1], ty[idx + 1], 0) nshp.add_node(bx[idx + 1], by[idx + 1], 0) nshp.add_node(bx[idx], by[idx], 0) nshp.add_node(tx[idx], ty[idx], 0) if idx % 2: nshp.set_property('_gv_color', cstr1) nshp.set_property('_gv_fill_color', cstr2) else: nshp.set_property('_gv_color', cstr1) nshp.set_property('_gv_fill_color', cstr1) shps.append(nshp) for idx in range(len(lx)): if labels[idx] is not None: lshp = gview.GvShape(type=gview.GVSHAPE_POINT) lshp.set_node(lx[idx], ly[idx]) lshp.set_property('label', labels[idx]) shps.append(lshp) if units_label is not None: lshp = gview.GvShape(type=gview.GVSHAPE_POINT) lshp.set_node(ux, uy) lshp.set_property('label', units_label) shps.append(lshp) layer = gview.GvShapesLayer(shps) # Set antialias property so that lines look nice # when rotated. layer.set_property('_gl_antialias', '1') cstr3 = gvogrfs.gv_to_ogr_color(color1) if len(cstr3) < 9: cstr3 = cstr3 + "FF" layer.set_property('_gv_ogrfs_point', 'LABEL(t:{label},f:"%s",c:%s)' % (font, cstr3)) return layer
def ogrfs_labels(self): self.set_step_name('OGRFS Labels') self.set_text( \ 'At the top of the screen should be two labels (red and blue)\n' + 'The red label has a halo effect. The blue label has a drop\n' + 'shadow effect\n' + '\n' + 'In the middle of the screen should be four labels (red and\n' + 'yellow). They have different anchor positions, and should\n' + 'be arrayed around a center reference point (not shown).\n' + 'The labels indicate where they should be (ie. TOP_LEFT should\n' + 'be to the top, and right of the center point).\n' + '\n' + 'In the lower left quadrant is a yellow "PIXEL_OFFSET" label\n' + 'that should be right and down of the white reference point.\n' + 'The offset is in screen pixels, so as you zoom it should\n' + 'remain a constant distance away from the reference point.\n' + '\n' + 'In the bottom right quadrant is a similar situation but\n' + 'the GEO_OFFSET label is offset in georeference coordinates\n' + 'so it will move closer to the ref point as you zoom out, and\n' + 'further from it as you zoom in.\n' + '\n' + 'All labels should be selectable and manipulatable. When\n' + 'selected they should have a selection box around them.\n' + '\n' ) shapes = gview.GvShapes() gview.undo_register(shapes) # Test anchors. shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 50, node=0) shape.set_property('_gv_ogrfs', 'LABEL(c:#FFFF00,t:"TOP_RIGHT")') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 50, node=0) shape.set_property('_gv_ogrfs', 'LABEL(c:#FF0000,p:7,t:"BOTTOM_RIGHT")') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 50, node=0) shape.set_property('_gv_ogrfs', 'LABEL(c:#FFFF00,p:9,t:"BOTTOM_LEFT")') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 50, node=0) shape.set_property('_gv_ogrfs', 'LABEL(c:#FF0000,p:3,t:"TOP_LEFT")') shapes.append(shape) # more anchor tests shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 35, node=0) shape.set_property('_gv_ogrfs', 'LABEL(c:#00FF00,p:2,t:"TOP_CENTER");' + \ 'SYMBOL(id:ogr-sym-0)' ) shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 43, node=0) shape.set_property('_gv_ogrfs', 'LABEL(c:#00FF00,p:5,t:"CENTER_CENTER");' + \ 'SYMBOL(id:ogr-sym-0)' ) shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 35, node=0) shape.set_property('_gv_ogrfs', 'LABEL(c:#00FF00,p:8,t:"BOTTOM_CENTER");' + \ 'SYMBOL(id:ogr-sym-0)' ) shapes.append(shape) # Test geographic and pixel offsets. shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(25, 25, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFFFF,s:2,id:ogr-sym-0)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(25, 25, node=0) shape.set_property( '_gv_ogrfs', 'LABEL(c:#FFFF00,dx:20px,dy:10px,t:"PIXEL_OFFSET")') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(60, 25, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FFFFFF,s:2,id:ogr-sym-0)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(60, 25, node=0) shape.set_property('_gv_ogrfs', 'LABEL(c:#FFFF00,dx:6g,dy:3g,t:"GEO_OFFSET")') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 75, node=0) shape.set_property( '_gv_ogrfs', 'LABEL(c:#00FF00,b:#339933,t:"Text with shadow",sh:)') shapes.append(shape) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 80, node=0) shape.set_property('_gv_ogrfs', 'LABEL(c:#FF0000,b:#993333,t:"Text with halo",h:)') shapes.append(shape) layer = gview.GvShapesLayer(shapes) layer.set_name('test') self.view.add_layer(layer) self.view.set_active_layer(layer) self.view.fit_extents(0, 0, 100, 100)
def SimpleLatLongGrid(min_x, min_y, max_x, max_y, hdeg, hmin, hsec, vdeg, vmin, vsec, color=(0.5, 1.0, 0.5, 1.0), xoff=-0.18, yoff=1.04, label_type=None, shapes_name="Grid"): """ Create a reference graticule. min_x, min_y- minimum lat/longs, in decimal degrees max_x, max_y- minimum lat/longs, in decimal degrees hdeg/hmin/hsec- horizontal spacing (degrees/min/sec) vdeg/vmin/vsec- vertical spacing (degrees/min/sec) decimal degrees=degrees+(minutes/60.0)+(seconds/3600.0) xoff- horizontal offset of vertical labels, as a fraction of max_x-min_x. Offset is relative to min_x. yoff- vertical offset of horizontal labels, as a fraction of max_y-min_y. Offset is relative to min_y. color- start color for the grid label_type- not used yet; might be later for formatting. extents may be shifted slightly to generate 'nice' labels. Note that the min_x, min_y, max_x, max_y extents include a border 5% in from each side, and room for labels. """ shps = gview.GvShapes(name=shapes_name) gview.undo_register(shps) shps.add_field('position', 'string', 20) if os.name == 'nt': font = "-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*" else: #font="-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*" #font="-urw-helvetica-medium-r-normal-*-9-*-*-*-p-*-iso8859-2" font = "-adobe-helvetica-medium-r-normal-*-8-*-*-*-p-*-iso10646-1" #font="-misc-fixed-medium-r-*-*-9-*-*-*-*-*-*-*" x_spacing = float(hdeg) + (float(hmin) + (float(hsec) / 60.0)) / 60.0 y_spacing = float(vdeg) + (float(vmin) + (float(vsec) / 60.0)) / 60.0 # Round to nearest integer space max_x = min_x + Numeric.floor((max_x - min_x) / x_spacing) * x_spacing max_y = min_y + Numeric.floor((max_y - min_y) / y_spacing) * y_spacing lxoff = (max_x - min_x) * xoff # horizontal label placement lyoff = (max_y - min_y) * yoff # vertical label placement for hval in Numeric.arange(min_x, max_x + x_spacing / 100.0, x_spacing): nshp = gview.GvShape(type=gview.GVSHAPE_LINE) nshp.set_node(hval, max_y, 0, 0) nshp.set_node(hval, min_y, 0, 1) shps.append(nshp) pshp = gview.GvShape(type=gview.GVSHAPE_POINT) pshp.set_node(hval, min_y + lyoff) hstr = GetLatLongString(hval, 'longitude') pshp.set_property('position', hstr) shps.append(pshp) for vval in Numeric.arange(min_y, max_y + y_spacing / 100.0, y_spacing): nshp = gview.GvShape(type=gview.GVSHAPE_LINE) nshp.set_node(min_x, vval, 0, 0) nshp.set_node(max_x, vval, 0, 1) shps.append(nshp) pshp = gview.GvShape(type=gview.GVSHAPE_POINT) pshp.set_node(min_x + lxoff, vval) vstr = GetLatLongString(vval, 'latitude') pshp.set_property('position', vstr) shps.append(pshp) cstr = gvogrfs.gv_to_ogr_color(color) if len(cstr) < 9: cstr = cstr + "FF" clstr = str(color[0]) + ' ' + str(color[1]) + ' ' + str( color[2]) + ' ' + str(color[3]) layer = gview.GvShapesLayer(shps) layer.set_property('_line_color', clstr) layer.set_property('_point_color', clstr) # Set antialias property so that lines look nice # when rotated. layer.set_property('_gl_antialias', '1') layer.set_property('_gv_ogrfs_point', 'LABEL(t:{position},f:"' + font + '",c:' + cstr + ')') layer.set_read_only(gtk.TRUE) return layer
def SimpleMeasuredGrid(min_x, min_y, max_x, max_y, x_spacing, y_spacing, color=(0.5, 1.0, 0.5, 1.0), xoff=-0.14, yoff=1.04, label_type=None, shapes_name="Grid"): """ Create a reference grid for a utm-projected raster. min_x, min_y, max_x, max_y- extents that grid should cover x_spacing- line spacing in horizontal direction y_spacing- line spacing in vertical direction xoff- horizontal offset of vertical labels, as a fraction of max_x-min_x. Offset is relative to min_x. yoff- vertical offset of horizontal labels, as a fraction of max_y-min_y. Offset is relative to min_y. color- start color for the grid label_type- not used yet; might be later for formatting. shapes_name- name to give the shapes forming the layer. """ shps = gview.GvShapes(name=shapes_name) gview.undo_register(shps) shps.add_field('position', 'string', 20) if os.name == 'nt': font = "-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*" else: #font="-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*" #font="-urw-helvetica-medium-r-normal-*-9-*-*-*-p-*-iso8859-2" font = "-adobe-helvetica-medium-r-normal-*-8-*-*-*-p-*-iso10646-1" #font="-misc-fixed-medium-r-*-*-9-*-*-*-*-*-*-*" # Round to nearest integer space max_x = min_x + Numeric.floor((max_x - min_x) / x_spacing) * x_spacing max_y = min_y + Numeric.floor((max_y - min_y) / y_spacing) * y_spacing lxoff = (max_x - min_x) * xoff # horizontal label placement lyoff = (max_y - min_y) * yoff # vertical label placement for hval in Numeric.arange(min_x, max_x + x_spacing / 100.0, x_spacing): nshp = gview.GvShape(type=gview.GVSHAPE_LINE) nshp.set_node(hval, max_y, 0, 0) nshp.set_node(hval, min_y, 0, 1) shps.append(nshp) pshp = gview.GvShape(type=gview.GVSHAPE_POINT) pshp.set_node(hval, min_y + lyoff) pshp.set_property('position', "%d" % int(hval + 0.5)) shps.append(pshp) for vval in Numeric.arange(min_y, max_y + y_spacing / 100.0, y_spacing): nshp = gview.GvShape(type=gview.GVSHAPE_LINE) nshp.set_node(min_x, vval, 0, 0) nshp.set_node(max_x, vval, 0, 1) shps.append(nshp) pshp = gview.GvShape(type=gview.GVSHAPE_POINT) pshp.set_node(min_x + lxoff, vval) pshp.set_property('position', "%d" % int(vval + 0.5)) shps.append(pshp) cstr = gvogrfs.gv_to_ogr_color(color) if len(cstr) < 9: cstr = cstr + "FF" clstr = str(color[0]) + ' ' + str(color[1]) + ' ' + str( color[2]) + ' ' + str(color[3]) layer = gview.GvShapesLayer(shps) layer.set_property('_line_color', clstr) layer.set_property('_point_color', clstr) # Set antialias property so that lines look nice # when rotated. layer.set_property('_gl_antialias', '1') layer.set_property('_gv_ogrfs_point', 'LABEL(t:{position},f:"' + font + '",c:' + cstr + ')') layer.set_read_only(gtk.TRUE) return layer
def vector_symbol(self): self.set_step_name('OGRFS Vector Symbol') self.set_text( \ 'You should see two three symbols. In the middle of the screen\n' + 'an arrow pointing straight up. Up and right of that should\n' + 'be a crossed arrow (slightly larger) pointing northeast and\n' + 'north west. The north-west arrow should be green, and the\n' + 'north-east one red.\n' + '\n' + 'To the right of that should be a pair of blue arrows meeting\n' + 'at their bases.\n' + '\n' + '\n' ) shapes = gview.GvShapes() gview.undo_register(shapes) # Insert a vector symbol that looks like an arrow into the symbol # manager. sm = gview.GvSymbolManager() shape = gview.GvShape(type=gview.GVSHAPE_LINE) shape.set_node(0.0, -6, node=0) shape.set_node(0.0, 6, node=1) shape.set_node(-2, 4, node=2) shape.set_node(0.0, 6, node=3) shape.set_node(2, 4, node=4) shape.set_property('_gv_ogrfs', 'PEN(w:2)') if os.name == "nt": sym_name = "\\rendertest_arrow" else: sym_name = "/rendertest_arrow" sm.inject_vector_symbol(sym_name, shape) # Place the symbol. shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 50, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FF0000,s:2,id:"' + sym_name + '")') shapes.append(shape) # Insert a vector symbol consisting of crossed arrows. sm = gview.GvSymbolManager() shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(0.0, 0, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(a:45,c:#00FF00,id:"' + sym_name + '");' + \ 'SYMBOL(a:-45,id:"' + sym_name + '")' ) if os.name == "nt": sym_name2 = "\\rendertest_carrow" else: sym_name2 = "/rendertest_carrow" sm.inject_vector_symbol(sym_name2, shape) # Place the symbol. shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(60, 60, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FF0000,s:4,id:"' + sym_name2 + '")') shapes.append(shape) # Insert a vector symbol consisting scaled arrows with offsets. sm = gview.GvSymbolManager() shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(0.0, 0, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(s:0.3333,a:45,dx:-6px,dy:-6px,id:"' + sym_name + '");' + \ 'SYMBOL(s:0.666,a:-45,dx:12px,dy:-12px,id:"' + sym_name + '")') if os.name == "nt": sym_name2 = "\\rendertest_carrow2" else: sym_name2 = "/rendertest_carrow2" sm.inject_vector_symbol(sym_name2, shape) # Place the symbol. shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(85, 60, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#0000FF,s:4,id:"' + sym_name2 + '")') shapes.append(shape) # Create the layer and display layer = gview.GvShapesLayer(shapes) layer.set_name('test') self.view.add_layer(layer) self.view.set_active_layer(layer) self.view.fit_extents(0, 0, 100, 100)
def vector_symbol_from_file(self): symbols_dir = os.path.join(gview.home_dir, 'symbols') symbol1 = os.path.join(symbols_dir, 'square.xml') symbol2 = os.path.join(symbols_dir, 'square_filled.xml') symbol3 = os.path.join(symbols_dir, 'cross.xml') symbol4 = os.path.join(symbols_dir, 'x.xml') symbol5 = os.path.join(symbols_dir, 'triangle.xml') symbol6 = os.path.join(symbols_dir, 'triangle_filled.xml') symbol7 = os.path.join(symbols_dir, 'circle.xml') symbol8 = os.path.join(symbols_dir, 'circle_filled.xml') symbol9 = os.path.join(symbols_dir, 'dash.xml') self.set_step_name('OGRFS Vector Symbol from File') self.set_text( \ 'In the middle of the screen should be 9 green symbols.\n' 'Symbols loaded from the following files:\n' + symbol1 + '\n' + symbol2 + '\n' + symbol3 + '\n' + symbol4 + '\n' + symbol5 + '\n' + symbol6 + '\n' + symbol7 + '\n' + symbol8 + '\n' + symbol9 + '\n' + '\n' + '\n' ) shapes = gview.GvShapes() gview.undo_register(shapes) sm = gview.GvSymbolManager() sm.get_symbol(symbol1) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(40, 40, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FF0000,s:2,id:"' + symbol1 + '")') shapes.append(shape) sm.get_symbol(symbol2) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 40, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FF0000,s:2,id:"' + symbol2 + '")') shapes.append(shape) sm.get_symbol(symbol3) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(60, 40, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FF0000,s:2,id:"' + symbol3 + '")') shapes.append(shape) sm.get_symbol(symbol4) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(40, 50, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FF0000,s:2,id:"' + symbol4 + '")') shapes.append(shape) sm.get_symbol(symbol5) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 50, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FF0000,s:2,id:"' + symbol5 + '")') shapes.append(shape) sm.get_symbol(symbol6) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(60, 50, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FF0000,s:2,id:"' + symbol6 + '")') shapes.append(shape) sm.get_symbol(symbol7) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(40, 60, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FF0000,s:2,id:"' + symbol7 + '")') shapes.append(shape) sm.get_symbol(symbol8) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(50, 60, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FF0000,s:2,id:"' + symbol8 + '")') shapes.append(shape) sm.get_symbol(symbol9) shape = gview.GvShape(type=gview.GVSHAPE_POINT) shape.set_node(60, 60, node=0) shape.set_property('_gv_ogrfs', 'SYMBOL(c:#FF0000,s:2,id:"' + symbol9 + '")') shapes.append(shape) # Create the layer and display layer = gview.GvShapesLayer(shapes) layer.set_name('test') self.view.add_layer(layer) self.view.set_active_layer(layer) self.view.fit_extents(0, 0, 100, 100)