Solving the pollution reporting problem

From what you have learned in this chapter, you can now solve the IoT pollution sensor data by congressional districts problem introduced earlier. Follow these general steps using either Python code or spatial query functions in a database such as PostGIS:

  1. Download a shapefile for U.S. Interstates such as the U.S. National Transportation Atlas Interstate Highways shapefile available from the University of Iowa (ftp://ftp.igsb.uiowa.edu/gis_library/USA/us_interstates.htm).
  2. Download a shapefile for US congressional districts such as the TIGER/Line Shapefile available from the US Census (https://www.census.gov/cgi-bin/geo/shapefiles/index.php?year=2016&layergroup=Congressional+Districts+%28115%29).
  3. Load the shapefiles into a geospatial database using ogr2ogr or into Python using the fiona package.
  4. Add a 1 km buffer to the Interstates MultiLineString using the shapely package or ST_Buffer in PostGIS.
  5. Use a mapping API such as Google Maps to geocode each device address in order to get the latitude and longitude point pairs. This was discussed in Chapter 7, Decorating Your Data - Adding External Datasets to Innovate.
  6. Load the IoT device locations as Point geometries.
  7. Optionally, apply R-tree indexes to the points and the congressional districts polygons to speed up calculations.
  8. Find Points contained within the buffered Interstates roadways polygon. The contains function would be one way to do this. Tag those points as within the bounds. Tag the remaining points as outside the range so they can be used as comparisons.
  1. For each point, search for the congressional district polygon that contains it and track the results. This would be a great place to leverage the spatial indexing created earlier.
  2. Calculate the pollution values for each device and combine with the congressional district and the in/out of Interstates buffer tags.
  3. Pivot and compare the data to compile the report.
  4. Go ask for a raise, you have earned it!
  5. You can also use the erosion option in the buffer function to create Interstate polygons that identify several distance ranges. Start with the largest range as the buffer, then erode your way back down for each range level. Create a buffered polygon for each range. Search the smallest buffered polygon first, the next biggest, then the next, and so on. The points that are not in any of those are outside the range.
  6. Go ask for another raise!
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.243.184