vector2raster.sml

  Download

More scripts: Convert

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
clear();
# declare output raster
class Raster Rref, Rout1, Rout2;
class Georef rgeoref, vgeoref1, vgeoref2;
# get input objects from the user
numeric numInputs = GetInputVectorList(InputList,"Input Vectors");
GetInputRaster(Rref);
# set up georef objects
vgeoref1 = GetLastUsedGeorefObject(InputList[1]); # create one of these for each Vector obj
vgeoref2 = GetLastUsedGeorefObject(InputList[2]);
rgeoref = GetLastUsedGeorefObject(Rref);
# create output based on reference raster
GetOutputRaster(Rout1, NumLins(Rref), NumCols(Rref), RastType(Rref)); # change type if you like
GetOutputRaster(Rout2, NumLins(Rref), NumCols(Rref), RastType(Rref)); # change type if you like
CopySubobjects(Rref, Rout1, "georef");
CopySubobjects(Rref, Rout2, "georef");
# write to the raster (1 loop per Vector)
numeric lineNumber = 0;
numeric rastVal = 1;
foreach line in InputList[1]
{
	VectorElementToRaster(InputList[1], Rout1, "line", lineNumber, rastVal, vgeoref1, rgeoref);
	lineNumber = lineNumber + 1;
}
lineNumber = 0;
foreach line in InputList[2]
{
	VectorElementToRaster(InputList[2], Rout2, "line", lineNumber, rastVal, vgeoref2, rgeoref);
	lineNumber = lineNumber + 1;
}
GeorefFree(rgeoref);
GeorefFree(vgeoref1);
GeorefFree(vgeoref2);
CloseRaster(Rout1);
CloseRaster(Rref);
print("Done!");