concept number in category geoprocessing

This is an excerpt from Manning's book Geoprocessing with Python.
Using digital data, you have the advantage of attaching multiple attribute values to each feature, whether you plan to display the information on a map or not. For each road, you can store information such as its name, speed limit, number of lanes, or anything else you can think of. Figure 1.2 shows an example of data you might store with each country in a dataset.
In many ways this example is similar to listing 9.4, except that the numbers of output rows and columns are halved instead of doubled, and the pixel size is doubled instead of halved. Notice that in this case you need to ensure that the numbers of rows and columns are integers, because the result of the division might be floating-point, and the dataset creation function doesn’t like that.
The NumPy empty function creates an array that hasn’t been initialized with any values, so it contains garbage until you fill it somehow. The first parameter to the function is a tuple containing the dimensions of the array to create. If it’s a two-dimensional array, the tuple contains the number of rows and then the number of columns. The dtype parameter is optional and specifies the type of data that the array will hold. If not provided, the array will hold floating-point numbers.
You can probably figure out what’s happening at the beginning of this example. You open the dataset and get information about the band, including the size of its blocks and its NoData value. After creating the output dataset, you start looping through the blocks in the horizontal (x) direction. You start at column 0 and go up to the last column, represented with index xsize. The twist is that each time through the loop, you increment x by the number of columns in a block (the third argument to range is the amount to increment by), so you skip from the beginning of one block to the beginning of the next. Then you store the number of columns to read in a variable called cols. If there’s a full block’s worth of columns left to read, this variable is set to the number of columns in a block. But if there aren’t enough columns, as would be the case when x is equal to 10 in figure 9.10, the number of remaining columns (three in the figure) is used instead. You need to do this because you’ll get an error if you try to read more rows or columns than exist.
Figure 9.10. A small example image with a block size of five rows and five columns. Alternating blocks are shaded to make it easy to see. The upper-left pixel has offset 0,0.
![]()
After computing the number of columns to read, you repeat the process for the number of rows. As shown in figure 9.10, the first two times through that second loop you read five rows, but the third time there’s only one row left to read. After processing the first five columns of all rows, you go to the next iteration of the outer loop and process the next five columns, and then the last three columns.