Developer Tutorial 1: Working with Vectors

The first part of this tutorial demonstrates the mechanism that OpenEV uses for displaying points and polygons. Start by loading up the shapefile examined in the General Overview (if you are continuing directly from the first tutorial and still have the classified shapes view, use it and skip the first four steps):

After the classification ramp has been applied, re-select a shape to refresh the vector properties dialog. A new field, "_gv_ogrfs" appears as a property in each shape. This is the field that openev uses to specify how that shape should be displayed. The "BRUSH" section indicates fill colour (for the "office" class, this is yellow, or "ffff00ff" when expressed in red-green-blue-alpha form). The "PEN" section indicates edge colour. The vector attributes dialog specifies properties of a layer; these are over-ridden by the "_gv_ogrfs" field. For point shapes, this field can also be used to specify the symbol to use to represent the point, and to indicate any labelling. For instance, setting _gv_ogrfs for a point shape to the string:

creates a magenta (c:#FF00FFFF) filled square (id:ogr-sym-5) symbol with a yellow (c:#FEFF06) helvetica font (f:"-adobe-helvetica-medium-r-normal-*-*-240-*-*-p-*-iso10646-1") label based on the contents of the point shape's Alias field (t:{Alias}). The label is offset 10 pixels in the x and y directions from the symbol (dy:-10.0,dx:10.0). The symbol may be one of the vector symbols (ogr-sym-*) or a raster symbol (in this case, id should be a path to the raster file to use). The label text can be derived from a field (as above), or specified directly (eg. t:"Hello" instead of t:{Alias} would write "Hello" as a label). The next part of this tutorial manipulates vector (GvShapes) objects in the OpenEV Python shell to demonstrate some of their features. Create a shapefile:
  1. Launch a new view
  2. Launch toolbar (Edit->toolbar)
  3. Select "Draw Rectangle" on the toolbar
  4. On layer dialog, click the icon
  5. On the view, left-click and drag out two rectangles
  6. Launch the vector attributes dialog (Edit->Vector Layer Attributes)
  7. Select "Select" on the toolbar
  8. Left click on a shape to select it
  9. Add a property to the shape by typing "property1: 'hello' in the shape attributes box. Click "Yes" when it asks you if you want to create the new property- this will allow it to be saved later.
  10. In the Shape Attributes dialog, select "integer" from the field properties menu and add a new property "property2: 3"
  11. Add these properties to the second rectangle, using different values.

In the Python shell, enter (note that path names are case-sensitive, even on Windows): This reads in the shapefile and creates a GvShapes object (sshapes) from its contents. Now enter: This gets a list of the properties stored in the shapefile. Now enter: This accesses the first GvShape in sshapes, and will show the values of the properties you entered for it. Now enter: This returns the number of nodes in the shape- 5 for a rectangle, because the last and first nodes are the same. You can use: To get the location of the first node (and similar for the others). There is also a set_node function. More complicated shapes may have multiple "rings" (the main encompassing ring plus areas cut out of it). In these cases, you must enter the ring number along with the node number in the get_node and set_node functions, to specify which ring's nodes you are accessing (the default is ring 0, which is fine for simple, 1-ring shapes)

You can type dir(gview.GvShapes) and dir(gview.GvShape) to see other functions associated with shape collections and individual shapes.

OpenEV allows you to draw 3 types of shapes: points, lines, and polygons, and it will allow you to draw any of them in a given layer. However, it is important to note that the specification only allows one type of shape to be saved to a given shapefile, so saving the layer as a vector file will only save the shapes of one type.

Next, we will turn the GvShapes object into a GvShapesLayer, ie. a collection of shapes that knows how to draw itself, as opposed to just a collection of shapes:

Create a new view to work in (File->New View), and make sure it is the active one by clicking on it, and by making sure it appears as the current view in the layer dialog box.

Get a handle to the GvViewArea in this view using the fact that openev set to the main application during initialization:

This grabs the active view through the selection manager, which is an object that keeps track of all layers, views, and selections in the application. Now, add the layer to the view: Now create a new shape: Add it to the collection: The new shape should appear in the view.

Developer Course Outline
OpenEV Main