Introduction to Ag Informatics

Module 6, Lecture 1
Tam Bureetes, tbureete@purdue.edu

Outline for Today

  • Spatial data
  • Introduction to geometry in Python
  • From geometry to spatial data
  • Putting spatial data to map in Django

Recap

Date Operation Operator Power Unit Location
2024-04-24 Spread/Spray Evan Hagie STS12 200
2024-04-27 Spread/Spray Bryan Hagie STS12 6
2024-04-27 Spread/Spray Bryan Hagie STS12 5

Field 200

Lat = 40.47693586173173

Lon = -87.01022508566594

Tools

ACRE Map

Geometry fundamental elements

Geometry fundamental elements

Point

Properties

Coordinates

Geometry fundamental elements

Line

Properties

Coordinates

Length

Geometry fundamental elements

Polygon

Properties

Coordinates

Length

Area

Geometry in action

Reference: Purdue Introduction to Agricultural Informatics Module 2
Reference: Purdue Introduction to Agricultural Informatics Module 6
Reference: Purdue Introduction to Agricultural Informatics Module 1

Geometric Object In Python

Shapely

Manipulation and analysis of geometric objects in the Cartesian plane

docs
Loading
Reference: Purdue Introduction to Agricultural Informatics Module 6

Live Demo

Check out this Jupiter Notebook

From Geometry To GeoSpatial

GeoPy Link with map services
PySAL, GeoPlot Visualize Geospatial data
ArcPy Working with ArcGIS
GDAL Driver for GIS software
GeoPandas Pandas with GeoSpatial functionalities

GeoPandas

Pandas + Shapely
geometry column contains shapely objects

            import geopandas as gpd
            world_df = gpd.read_file(
                    gpd.datasets.get_path('naturalearth_lowres')
            )
        
pop_est continent name iso_a3 gdp_md_est geometry
0 889953.0 Oceania Fiji FJI 5496 MULTIPOLYGON (((180.00000 -16.06713, 180.00000...
1 58005463.0 Africa Tanzania TZA 63177 POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
2 603253.0 Africa W. Sahara ESH 907 POLYGON ((-8.66559 27.65643, -8.66512 27.58948...
3 37589262.0 North America Canada CAN 1736425 MULTIPOLYGON (((-122.84000 49.00000, -122.9742...
4 328239523.0 North America United States of America USA 21433226 MULTIPOLYGON (((-122.84000 49.00000, -120.0000...
Visualize GeoSpatial data

                world_df.plot()
            
world map
Process data using Pandas built-in functions

            import numpy as np
            world_df['log_gdp'] = np.log(world_df['gdp_md_est'])
            world_df.plot("log_gdp")
        
world GDP
True country area

            world_df = world_df.to_crs(
                "+proj=eck4 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
            )
            world_df.area
        
https://www.learndatasci.com/tutorials/geospatial-data-python-geopandas-shapely/

Common File types

ShapeFile ESRI standard. Commonly used by GIS software like ArcGIS etc.
GeoJSON JSON-style with standard specificationfor holding spatial data.
KML XML format with spatial data. Commonly used with Google Earth.
Geo-Database Database with spatial data feature e.g. SpatiaLite, PostGIS.

Open Data Source

Questions?

License

This course is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license. This is a human-readable summary of (and not a substitute for) the license. Official translations of this license are available in other languages.

You are free to:

  • Share — copy and redistribute the material in any medium or format
  • Adapt — remix, transform, and build upon the material

Under the following terms:

  • Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • NonCommercial — You may not use the material for commercial purposes.
  • ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
  • No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.