mouad seghini
mouad seghini

Reputation: 49

Geopandas python empty geometries / missing values

i'm running a python code using geopandas to analyse a data. and i got an ERROR : The problem concernes the 5 last lines And here is the data i used : https://www.fr.freelancer.com/users/l.php?url=https:%2F%2Fapp.box.com%2Fshared%2Fstatic%2Fyig4yill3xl83n7361c5q88kehikhje0.zip&sig=ec739bd7319b7823aa4c1d776a8d5ffc3c2da5040abfa799549180c82f1f93bd
Here is the code

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import geopandas as gpd
from descartes.patch import PolygonPatch
from mpl_toolkits.axes_grid1 import make_axes_locatable

svi = gpd.read_file(r'C:\Users\Hamza\Desktop\Freelancer\SVI_IL2018.shp') # use a Tab key after you type data/ to select a file in the folder
svi.head() # show SVI by tracts in Ilinois

type(svi)
type(svi['geometry'])
svi['geometry'].geom_type
svi['geometry'].area
svi.crs
svi2 = svi.to_crs('epsg:3723')  # change CRS to UTM 16N
svi.plot()  # plot a GeoDataFrame. This shows tracts in Illinois
svi2 = svi.to_crs('epsg:3723')  # change CRS to UTM 16N
svi2.plot()
svi2.head()
ilcounty = svi2.dissolve(by='STCNTY')  # dissolve tracts by county
# map overall percentile ranking of social vulnerability
svi2.plot(column='RPL_THEMES', figsize=(6, 8), legend=True)  # figsize = (width, height) in inches, default (6.4, 4.8)
svi2['RPL_THEMES'].describe()  # get descriptive statistics of RPL_THEMES
svi2['RPL_THEMES'].hist()  # show histogram of RPL_THEMES
svi3 = svi2.replace(-999, np.nan)  # replace -999 with NaN (null values)
svi3['RPL_THEMES'].describe()
svi3.plot(column='RPL_THEMES', figsize=(8, 10), legend=True)
svi3.plot(column='RPL_THEMES', figsize=(8, 10), legend=True, cmap='YlOrBr')
svi3.plot(column='RPL_THEMES', figsize=(8, 10), legend=True, cmap='hot_r')
tri = gpd.read_file(r'C:\Users\Hamza\Desktop\Freelancer\TRI.geojson')
tri.crs
schools = gpd.read_file(r'C:\Users\Hamza\Desktop\Freelancer\schools.shp')
schools.head()
# 3) show the CRS of a GeoDataFrame schools. They should be in SPCS83
schools.crs
type(schools)
type(schools['geometry'])
tri.plot()
schools.plot()
svi3.plot()
# create fig (figure object) and ax (axis object)
fig, ax = plt.subplots(figsize=(8, 10))
# by default this creates a figure with one subplot (axis) as parameters for nrows and ncols are omitted
# if you create multiple axes, it would be good to name axes instead of ax

# plot three GeoDataFrames on the ax object created above
svi3.plot(ax=ax, column='RPL_THEMES')  # plot 'RPL_THEMES' on ax
tri.plot(ax=ax, color='r')  # plot tri on ax in red
schools.plot(ax=ax, color='g')  # plot schools on ax in green
svi4 = svi3.to_crs('epsg:3435')  # change CRS to UTM 16N
svi4.crs
# show three GeoDataFrames in one figure
fig, ax = plt.subplots(figsize=(8, 10))

svi4.plot(ax=ax, column='RPL_THEMES')  # map 'RPL_THEMES'
tri.plot(ax=ax, color='r')  # show tri in red
schools.plot(ax=ax, color='g')  # show schools in green
path = 'https://data.cityofchicago.org/api/geospatial/cauq-8yn6?method=export&format=GeoJSON'
comm = gpd.read_file(path)
comm.head()
comm.crs
comm = comm.to_crs('epsg:3435')  # change WGS84 to SPC IL East
comm.crs
# clip svi4 by comm
svi5 = gpd.clip(svi4, comm)

# clip tri by comm
tri2 = gpd.clip(tri, comm)
# warning of change in functionality. you can ignore this.

Here is the ERROR C:\Users\Hamza\AppData\Local\Programs\Python\Python37\lib\site-packages\geopandas\geoseries.py:358: UserWarning: GeoSeries.notna() previously returned False for both missing (None) and empty geometries. Now, it only returns False for missing values. Since the calling GeoSeries contains empty geometries, the result has changed compared to previous versions of GeoPandas. Given a GeoSeries 's', you can use '~s.is_empty & s.notna()' to get back the old behaviour.

To further ignore this warning, you can do: import warnings; warnings.filterwarnings('ignore', 'GeoSeries.notna', UserWarning) return self.notna()

Upvotes: 0

Views: 1783

Answers (1)

martinfleis
martinfleis

Reputation: 7814

That is not an error but a warning GeoPandas now shows after it changed a behaviour in one of the previous versions. If the issue is with last lines, it is likely caused by clip, so it should not be an issue. GeoPandas should mute the warning in this case. You can happily ignore it.

Upvotes: 0

Related Questions