0

I am attempting to create a map that shows the location of homes that experienced a level 3.5 intensity shaking for an earthquake. The shake-map file contains rings that represent where different levels of shaking were felt. When I run the code below, pointsInPolys returns a data frame with 0 rows (apparently no points fall within the shape-map area, which is false). Both of these will be overlaid on a US base-map. Please let me know if I need to clarify something. Many thanks in advance.

JSON shake-map file: https://earthquake.usgs.gov/archive/product/shakemap/ci39462536/ci/1591320887076/download/cont_mi.json

basemap US: https://drive.google.com/file/d/1tXBcg5V7NCTwXP79RhH_keQtTzJl3ddF/view?usp=sharing

csv file: https://drive.google.com/file/d/10bgfmzHhmLZf1KJzVI6QnzjmxNnO9Ch5/view?usp=sharing

What my map looks like now: https://drive.google.com/file/d/1rWf1UQ4GH7anvIXE8ohDtAAeduAL_5pT/view?usp=sharing

For security reasons, I cannot provide the full .csv file because it contains sensitive information. I can, however, provide the column that contains the geometries. My code for reference is below.

# Import Dependencies
import pandas as pd
import numpy as np
import geopandas
import descartes
from shapely.geometry import Point, Polygon

import seaborn as sns
import matplotlib.pyplot as plt

import os
import subprocess 


# Bring in json basemap
country = geopandas.read_file("gz_2010_us_040_00_5m.json")
country.head()

# Bring in csv policies file
policies = pd.read_csv('ermPAR_ALL.csv')
policies.info()

# Add column that contains the lat-long point of each policy
policies['coordinates'] = policies[['Longitude','Latitude']].values.tolist()
policies['coordinates'] = policies['coordinates'].apply(Point)
policies = geopandas.GeoDataFrame(policies, geometry='coordinates')
policies.rename(columns = {'coordinates':'geometry'})

fig, ax = plt.subplots(1, figsize = (30,20))

# Plot basemap
base = country[country['NAME'].isin(['Alaska','Hawaii','Puerto Rico']) == False].plot(figsize = (30,20), color='#3B3C6E')

#Bring in the shake-map
os.chdir('/Users/RDM032')

shakemap = geopandas.read_file('cont_mi (1).json')
shakemap4 = shakemap[shakemap['value'] == 3.5].geometry # We want policies that would have experience a >3.5 shaking

# Plot shake-map
shakemap4.plot(ax=base, label = 'Intensity')

## THIS IS WHERE I NEED TO SOLVE FOR pointsInPolys AND THEN PLOT IT ##
pointsInPolys = policies[policies.within(shakemap4)]

# Plot policies that fell within the shake-map
pointsInPolys.plot(ax=base, column='LOB', legend = True, label = "Lines of Business")
_= ax.axis('off')

plt.legend(policies['LOB'].values())



#Example Data
policies = [(-118.483757019043 34.1998443603516),(-118.46418762207 34.1509437561035),(-118.40697479248 34.0205154418945),(-118.453002929688 33.9679145812988)]




  • "cannot provide the full .csv file because it contains sensitive information." you should provide that dummy CSV that approximates the relevant columns of the one you're working with. – Paul H Jul 30 '20 at 17:07
  • https://stackoverflow.com/questions/48097742/geopandas-point-in-polygon – Paul H Jul 30 '20 at 17:08
  • Thank you for providing the link to a similar problem someone is experiencing. I believe my problem is related, but I guess my real question is if the JSON file from the USGS website is being interpreted as a polygon when I am checking if the policy points fall inside it. I only get FALSE as the return value, yet there are definitely policies that fall within the shake-map area – Ryan D McCrary Jul 30 '20 at 17:37
  • check the CRS of each dataset – Paul H Jul 30 '20 at 19:05
  • I checked, and the CRS of each dataset is the same. – Ryan D McCrary Jul 30 '20 at 19:20
  • and you post example data as StringIO objects? None of your google links work – Paul H Jul 30 '20 at 19:37
  • I added example data for the policies to the main post – Ryan D McCrary Jul 30 '20 at 19:53
  • This is where you can get the US base map. I used the 5m US States GeoJSON file. https://eric.clst.org/tech/usgeojson/ – Ryan D McCrary Jul 30 '20 at 19:56
  • I believe my issue is the points that are used to draw the shake-map are in a MULTILINESTRING. I need to convert this string to a Polygon and then I think it will work. – Ryan D McCrary Jul 30 '20 at 19:58
  • yeah linestrings are not polygons – Paul H Jul 30 '20 at 19:59

0 Answers0