Book Image

Geospatial Development By Example with Python

By : Pablo Carreira
5 (1)
Book Image

Geospatial Development By Example with Python

5 (1)
By: Pablo Carreira

Overview of this book

From Python programming good practices to the advanced use of analysis packages, this book teaches you how to write applications that will perform complex geoprocessing tasks that can be replicated and reused. Much more than simple scripts, you will write functions to import data, create Python classes that represent your features, and learn how to combine and filter them. With pluggable mechanisms, you will learn how to visualize data and the results of analysis in beautiful maps that can be batch-generated and embedded into documents or web pages. Finally, you will learn how to consume and process an enormous amount of data very efficiently by using advanced tools and modern computers’ parallel processing capabilities.
Table of Contents (17 chapters)
Geospatial Development By Example with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting the attributes' values


Let's explore the attributes of the world borders to find out why we were unable to get the names.

  1. Edit the if __name__ == '__main__': block:

    if __name__ == '__main__':
        world = BoundaryCollection("../data/world_borders_simple.shp")
        print(world.data[0].attributes.keys())
  2. Run the code and look at the output:

    File imported: ../data/world_borders_simple.shp
    ['SUBREGION', 'POP2005', 'REGION', 'ISO3', 'ISO2', 'FIPS', 'UN', 'NAME']
    
    Process finished with exit code 0

    What we did was we got the first item in world.data and then printed its attribute keys. The list shown in the output has a NAME key, but it is all in the uppercase. This is very common for Shapefiles whose data is contained in the DBF files.

    Since we don't want to worry if the attributes' names are in the uppercase or lowercase, we have two possible solutions: convert the names at the moment of the import or convert the names on the fly when the attribute value is requested. Depending on your application...