# Chapter 3. Manipulating Vector Maps

By the end of this chapter you will be able to:

• Understand the relationship between a VectorMap and GISVector.

• Create GISVectors from sets of geometric coordinates.

• Create a vector map, add GISVectors to it and associate it with metadata

• Perform simple processing operations on vector maps

## 3.1 The structure of a vector map

In contrast with raster maps, vector maps are used to represent collections discrete spatial objects with known boundaries. Those objects may be points in space, lines, or areas defined by linear boundaries. A vector map may contain any number of these objects that may be separate from each other, joined, or overlapping.

Simple point, line and area features and their vector map representation.

An individual vector object (such as the red line, blue line, yellow or green rectangle or point above) is represented by the class GISVector. This stores the geometry of the object as a series of (x,y) coordinate pairs. Implicit in this model is that lines and area boundaries are defined by joining consecutive pairs with straight line segments. A GISVector also inherits SpatialObject just as the RasterMap class does. It therefore has methods for defining its bounds, performing simple spatial comparisons, and manipulating its attribute(s). The VectorMap class simply assembles a collection of the GISVectors into a single object that itself has bounds and other metadata attached to it.

## 3.2 Creating a simple vector map

Creating a vector map is a simple process and just requires calling one of VectorMap's constructors. Like the RasterMap class, you can define the bounds of the object at the point of creation, copy the contents of an existing spatial object, or simply create an empty vector map. Unlike rasters, it is more common for vector maps to grow and shrink as objects are added and removed, so it is quite usual initially to create an empty vector map object:

VectorMap myVectorMap = new VectorMap();

The geometry of an individual object within a vector map is stored in a GISVector object. The object also stores its type - one of GISVector.POINT, GISVector.LINE or GISVector.AREA, as well as its attribute value. These can all be set in GISVector's constructor, or added later using an appropriate method.

The class below shows how some simple vector objects may be created and added to a vector map which is then saved to disk.

Note the similarity with the way in which raster map metadata are added and saved to disk. The vector map that is created as a result of this class is shown below.

VectorMap output from the SimpleVectorMap class.

## 3.3 Manipulating Vector Maps

Vector maps can be read much as raster maps using the static method LandSerfIO.readVector(fileName). Altering the metadata associated with a vector map is identical to that of a raster. To manipulate an individual GISVector within a vector map, the set of GISVectors contained can be iteratively extracted using the method getGISVectors(). This method (slightly unfortunately for naming purposes) returns a Java Vector of GISVectors. To process each object in turn, it would be normal to create an iterator:

Iterator i = myVectorMap.getGISVectors().iterator();

while (i.hasNext())
{
GISVector gisVect = (GISVector)i.next();

// Do something with each GISVector here.
}

Note that LandSerf 2.3 does not use generics to organise collections, so Java 1.5 'for-each' loops with generics cannot be used. Future releases of LandSerf will require Java 1.5 or above and will make use of generics for all collections.

Depending on what you wish to do, it is sometime possible to avoid manipulating GISVector objects directly by calling appropriate methods from the VectorMap object. The example below shows how two vector maps can be combined with simple clone() and add() methods.