Geopandas, living In the realm of Libraries

The basics of the work with programming languages involve getting your hands dirty with libraries. This implies entering a completely different world, where the Dewey Decimal system does not play a significant role.

To clarify what libraries are, we need some definitions first of key terms. Then, off to the discovery of libraries for geospatial data analysis, my growing passion. 

First, some definitions

What is the difference between library, package, module, and framework? Mohammed Ibrahim provides a cool analogy for each. He says a module is the fingers of a hand. A package is the hand that controls the module (fingers). The library is comparable to building your own house, while a framework is an already built house. It’s pretty straightforward. 

My interest in geospatial analysis brought me in front of libraries used for that end: geopandas, folium, ipyleaflet, rasterio, rasterstats, shapely, Fiona, arcpy, RSGISLib, and others. I chose one to dive into.

A library for geospatial analysis

The first wall I hit was with Geopandas. Who are “Geopandas”? Well, the question is a bit distorting, I admit. Geopandas is the geospatial extension of the pandas library. Pandas library manipulates data. Geopandas manipulates geospatial data, meaning data with spatial geometry information. Here are a few main aspects of Geopandas.

Example of scripts using Geopandas

To read a shapefile, its Coordinate Reference System (CRS), and its geometry type:

import geopandas as gpd

#Read a shapefile
file_path = ‘path/to/your/shapefile.shp’
gdf = gpd.read_file(file_path)

#Access and print the CRS information
crs_info = gdf.crs
print(“Coordinate Reference System (CRS) information:”)
print(crs_info)

#Access and print the geometry types
geometry_types = gdf.geom_type
print(“Geometry Types:”)
print(geometry_types)

#Display the GeoDataFrame
print(gdf.head())

What about you? With which library did you hit the first wall in programming?

Leave a comment