Skip to content

Instantly share code, notes, and snippets.

@Paul-Aime
Last active January 7, 2023 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Paul-Aime/4869dcaa3f94ca46c699d9d3244da261 to your computer and use it in GitHub Desktop.
Save Paul-Aime/4869dcaa3f94ca46c699d9d3244da261 to your computer and use it in GitHub Desktop.
Sample file for geopandas issue #2752

See geopandas issue #2752

import geopandas as gpd
# Shapefile contains three fields: "date", "geometry", "geometry_2"
# Both "geometry" and "geometry_2" are identical
# and are a 1 decimal rounding of the layer initrinsic geometry
fpath = "https://gist.github.com/Paul-Aime/4869dcaa3f94ca46c699d9d3244da261/raw/609b2819cfb647f32517835bf66bf673f829012d/products.zip"
# Reading with `engine=pyogrio` works
# the field "geometry" is overridden by the layer geometry
# it is known because otherwise "geometry" and "geometry_2" would have been identical
df1 = gpd.read_file(fpath, engine="pyogrio")
print(df1)
# date geometry geometry_2
# 0 2022-12-04T11:16:25.555Z POLYGON ((-1.61123 43.42786, -1.61095 43.54664... POLYGON ((-1.6 43.4, -1.6 43.5, -1.6 43.5, -1....
# 1 2022-07-21T11:12:31.329Z POLYGON ((-1.60609 43.38495, -1.60602 43.56857... POLYGON ((-1.6 43.3, -1.6 43.5, -1.4 43.5, -1....
# Reading with `engine=fiona` raises a ValueError
# This is because `geopandas.io.file._read_file_fiona` adds a "geometry" column by itself.
try:
df = gpd.read_file(fpath, engine="fiona")
except ValueError as e:
print(e)
# GeoDataFrame does not support multiple columns using the geometry column name 'geometry'.
# Reading with `engine=fiona` AND `ignore_fields=["geometry"]`
# leads the same result as reading with `engine=pyogrio`
# i.e. the "geometry" column is the one derived from the layer intrinsic geometry
df2 = gpd.read_file(fpath, engine="fiona", ignore_fields=["geometry"])
print(df2)
print(df1["geometry"].equals(df2["geometry"]))
# date geometry_2 geometry
# 0 2022-12-04T11:16:25.555Z POLYGON ((-1.6 43.4, -1.6 43.5, -1.6 43.5, -1.... POLYGON ((-1.61123 43.42786, -1.61095 43.54664...
# 1 2022-07-21T11:12:31.329Z POLYGON ((-1.6 43.3, -1.6 43.5, -1.4 43.5, -1.... POLYGON ((-1.60609 43.38495, -1.60602 43.56857...
# True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment