|
9 | 9 | from tempfile import NamedTemporaryFile
|
10 | 10 |
|
11 | 11 | import numpy as np
|
12 |
| -from packaging.version import Version |
13 | 12 |
|
14 | 13 |
|
15 | 14 | def unique_name() -> str:
|
@@ -144,34 +143,16 @@ def tempfile_from_geojson(geojson):
|
144 | 143 | # https://github.com/geopandas/geopandas/issues/967#issuecomment-842877704
|
145 | 144 | # https://github.com/GenericMappingTools/pygmt/issues/2497
|
146 | 145 | int32_info = np.iinfo(np.int32)
|
147 |
| - # TODO(GeoPandas>=1.0): Remove the workaround for GeoPandas < 1. |
148 |
| - # The default engine is "fiona" in v0.x and "pyogrio" in v1.x. |
149 |
| - if Version(gpd.__version__).major < 1: # GeoPandas v0.x |
150 |
| - # The default engine 'fiona' supports the 'schema' parameter. |
151 |
| - if geojson.index.name is None: |
152 |
| - geojson.index.name = "index" |
153 |
| - geojson = geojson.reset_index(drop=False) |
154 |
| - schema = gpd.io.file.infer_schema(geojson) |
155 |
| - for col, dtype in schema["properties"].items(): |
156 |
| - if dtype in {"int", "int64"}: |
157 |
| - overflow = ( |
158 |
| - geojson[col].max() > int32_info.max |
159 |
| - or geojson[col].min() < int32_info.min |
160 |
| - ) |
161 |
| - schema["properties"][col] = "float" if overflow else "int32" |
162 |
| - geojson[col] = geojson[col].astype(schema["properties"][col]) |
163 |
| - ogrgmt_kwargs["schema"] = schema |
164 |
| - else: # GeoPandas v1.x. |
165 |
| - # The default engine "pyogrio" doesn't support the 'schema' parameter |
166 |
| - # but we can change the dtype directly. |
167 |
| - for col in geojson.columns: |
168 |
| - if geojson[col].dtype.name in {"int", "int64", "Int64"}: |
169 |
| - overflow = ( |
170 |
| - geojson[col].max() > int32_info.max |
171 |
| - or geojson[col].min() < int32_info.min |
172 |
| - ) |
173 |
| - dtype = "float" if overflow else "int32" |
174 |
| - geojson[col] = geojson[col].astype(dtype) |
| 146 | + # The default engine "pyogrio" doesn't support the 'schema' parameter |
| 147 | + # but we can change the dtype directly. |
| 148 | + for col in geojson.columns: |
| 149 | + if geojson[col].dtype.name in {"int", "int64", "Int64"}: |
| 150 | + overflow = ( |
| 151 | + geojson[col].max() > int32_info.max |
| 152 | + or geojson[col].min() < int32_info.min |
| 153 | + ) |
| 154 | + dtype = "float" if overflow else "int32" |
| 155 | + geojson[col] = geojson[col].astype(dtype) |
175 | 156 | # Using geopandas.to_file to directly export to OGR_GMT format
|
176 | 157 | geojson.to_file(**ogrgmt_kwargs)
|
177 | 158 | except AttributeError:
|
|
0 commit comments