Combining the contents of two objects

Adding two rasters

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Adds the contents of two rasters together.
version(1.0);

# Change the directory below to correspond to your file location.
baseDir = "c:/Program Files/LandSerf/data/landscriptExamples/";

# Open elevation model and vegetation layer.
dem = open(baseDir&"dem.srf");
veg = open(baseDir&"vegetation.srf");

# Create combined surface
dsm = new(dem);
dsm = dem + veg;

# Add metadata and save combined raster.
edit(dsm,"title","Digital Surface Model");
edit(dsm,"notes","Combined DEM ground surface and vegetation layer");
save(dsm,baseDir&"dsm.srf");

Adding two vectors

In this example, the vector maps that are added have their own attribute tables. The numeric attribute that is used when adding values together can be set by changing column of the active attribute (lines 16 and 17). If the active attribute contains non-numeric values, the vector's ID is used instead. After addition, it no longer makes sense for the the new vector map (output) to retain its original attribute table, so it is removed (line 13).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Adds the contents of two vector maps with attribute tables. 
version(1.0); 
 
# Change the directory below to correspond to your file location. 
baseDir = "c:/Program Files/LandSerf/data/landscriptExamples/"; 
 
# Open a point map and an area map 
points = open(baseDir&"points.vec"); 
areas  = open(baseDir&"shapes.vec"); 
 
# Use the point map to define the output vector 
output = new(points,"true"); 
edit(output,"attributes","noTable"); 
 
# Define the attribute table columns to act as input 
edit(areas,"attCol",3); 
edit(points,"attCol",2); 
 
# Add the active attributes of points and area maps 
output = areas+points; 
 
# Set metadata and save the combined vector map. 
colouredit(output,"default"); 
save(output,baseDir&"points2.vec"); 

Adding the contents of a raster to objects in a vector map

The raster (a fractal surface in this example) is queried at the centroid of each vector object in the vector map. Each object then takes the value of that queried raster cell. If the vector object is outside the bounds of the raster, its value is set to null and is therefore not displayed.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Adds the contents of a raster map to objects in a vector map 
version(1.0); 
 
# Change the directory below to correspond to your file location. 
baseDir = "c:/Program Files/LandSerf/data/landscriptExamples/"; 
 
# Create a fractal raster map 
fracSurf = newraster(400,400,1,1,800,800); 
fractal(fracSurf, 2.01); 
 
# Open a point map 
points = open(baseDir&"points.vec"); 
 
# Set the value of each vector object to the raster cell at its location. 
points = fracSurf; 
edit(points,"attributes","noTable"); 
 
# Set metadata and save the new vector map. 
colouredit(points,"default"); 
save(points,baseDir&"points2.vec");