1

GeoPandas 0.6.1

Almost every shapefile from Census Bureau is giving the same error.

In this case is the Block data shapes from Maine. The file is "tl_2019_23_tabblock10.shp"

gdf.plot(figsize=(32, 16), column='INTPTLAT10', linewidth = 0)

enter image description here

EDIT: full code

import numpy as np
import pandas as pd
import shapefile as shp
import matplotlib.pyplot as plt
import seaborn as sns
import descartes
import geopandas as gp

from shapely.geometry import Polygon

sns.set(style="whitegrid", palette="pastel", color_codes=True)
sns.mpl.rc("figure", figsize=(10,6))
%matplotlib inline

shp_path = "./tl_2019_23_tabblock10/tl_2019_23_tabblock10.shp"
sf = shp.Reader(shp_path)

def read_shapefile(sf):

    fields = [x[0] for x in sf.fields][1:]
    records = sf.records()
    shps = [s.points for s in sf.shapes()]
    df = pd.DataFrame(columns=fields, data=records)
    df = df.assign(coords=shps)
    return df

df = read_shapefile(sf)

df.INTPTLAT10 = df.INTPTLAT10.astype(float)
df.INTPTLON10 = df.INTPTLON10.astype(float)
df.STATEFP10 = df.STATEFP10.astype(int)

df.coords = [Polygon(list(i)) for i in df.coords]
gdf = gp.GeoDataFrame(df, geometry=df.coords)

gdf.plot(figsize=(32, 16), column='INTPTLAT10', linewidth = 0)
2
  • 1
    And what exactly is the error?
    – Erik
    Oct 25 '19 at 14:15
  • I was making a mistake, please see my answer.
    – Hector
    Oct 25 '19 at 14:56
1

I was using read_shapefile(sf) function that I got from a tutorial somewhere to upload data into a DataFrame, then make a GeoDataFrame from the DataFrame. That was a mistake.

This is the correct code:

import pandas as pd
import seaborn as sns
import geopandas as gpenter code here

sns.set(style="whitegrid", palette="pastel", color_codes=True)
sns.mpl.rc("figure", figsize=(10,6))
%matplotlib inline

df = gp.read_file("./tl_2019_23_tabblock10/tl_2019_23_tabblock10.shp")

df.INTPTLAT10 = df.INTPTLAT10.astype(float)
df.plot(figsize=(24, 12), column='INTPTLAT10', linewidth = 0)

And the map without the weird looking white triangles.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.