concept distance in category geoprocessing

This is an excerpt from Manning's book Geoprocessing with Python.
Chinese researchers Luo et al.[1] used spatial analysis, along with historical records, to pinpoint the locations of missing courier stations along the Silk Road. The historical records contained descriptions of the route, including distance traveled and general direction between stations. The locations of several stations were already known, and the researchers knew that ancient travelers were unlikely to follow a straight line, but instead follow rivers or other landforms. They used all of this information to determine likely geographic areas for the still-missing stations. They then used high-resolution satellite imagery to search these areas for geometric shapes that could be station ruins. After visiting the sites in person, they determined that one, in fact, was an old courier station, and two others were likely military facilities during the Han Dynasty.
Spatial analysis with vector data comes down to looking at the spatial relationships between two or more geometries. Possible studies range from the extremely simple, such as the distance between two points, to much more complex algorithms such as network analyses. Have you ever wondered how certain mapping websites can provide you with various route options from point A to point B, and even provide travel times? That’s network analysis. One easy exercise that I sometimes find entertaining is comparing the distance I hiked with the straight-line distance between the starting and ending points, because these two distances can be significantly different in mountainous terrain. There probably isn’t much use for that particular example in my life, other than to satisfy my curiosity, but it’s important information for search-and-rescue teams who need to know actual distances. There are plenty of other important questions out there waiting to be answered using spatial analysis techniques.
Now you’ve got a shapefile that uses meters, so let’s calculate the distance between each location. To do this, you need to select the points for an individual bird, so let’s write a function that will get unique values from an attribute column. You can use the function from the following listing to get tag_id values in later listings.
Listing 7.6. Function to get unique values from an attribute column
def get_unique(datasource, layer_name, field_name): sql = 'SELECT DISTINCT {0} FROM {1}'.format(field_name, layer_name) lyr = datasource.ExecuteSQL (sql) values = [] for row in lyr: values.append(row.GetField(field_name)) datasource.ReleaseResultSet(lyr) return valuesTo calculate distances, you’ll iterate through the points for each bird in order and then calculate the distance between each location and the previous one, so you’ll need to keep track of the previous point as you loop. The points should be in the correct order in the original .csv file, which means they’re also in order in the shapefile you created, but you’ll add code to check, just in case. If it does find something out of order, it will bail so that you can correct the problem. The following listing shows the process.
Before starting the loop, you save the timestamp and point geometry for the first location so that you can use it to calculate distance between it and the second feature. This increments the current feature, so the loop starts with the second feature instead of the first, and you calculate a distance between the first and second points in the first iteration. After saving the distance, you store the timestamp and geometry for the current feature in your “previous” variables, so that the next time through the loop you’ll have this information. If you hadn’t stored the current values, you’d always calculate the distance to the first point, because that’s the one originally stored in previous_pt.
Now it’s an easy matter to get information about the distances. For example, you could use SQL to find out which bird had the longest distance between GPS fixes: