Comments (3)
FWIW I was able to get a regular pandas dataframe with the following code:
pd_df = pd.DataFrame(dict(zip(df.columns, df.to_numpy().T)))
Then I serialize via existing pandas methods.
I no longer need geopandas to change the behavior of to_json, but I figure this code could be useful for others who stumble across this problem.
from geopandas.
Thanks @paddymul for opening this issue. I wouldn't say this is a bug per se, but a mismatch of expectations. In the geospatial world the standard json representation of features is GeoJson - which specifies a specific layout for storing features separate to geometry alongside storing spatial metadata like a CRS (coordinate reference system).
(For instance compare the output of gdf.to_json(indent=2)
and pd.DataFrame(gdf.to_wkt()).to_json(indent=2)
in your example).
In principle I think we would be open to supporting other orientations, so long as that does not lead to confusion about what is a generic interoperable geojson format and what is a pandas specific format. It'd be good for other maintainers to weight in, but my initial proposal to support this would be to introduce an orient="GeoJSON"
which is the default value and support the other values via pandas. Geometry would be exported as WKT and we'd probably need to emit a warning about the loss of CRS metadata (and then perhaps a second stage would be to agree on a way to embed CRSs if there was an appetite for that.
from geopandas.
FWIW I was able to get a regular pandas dataframe with the following code:
pd_df = pd.DataFrame(dict(zip(df.columns, df.to_numpy().T)))
I haven't compared the performance, but I think a slightly clearer way to express this would be pd.DataFrame(gdf).astype({"geometry":"object"})
(or a generalisation of it if there are multiple geometry columns), but it is more verbose.
from geopandas.
Related Issues (20)
- GeoPandas 1.0 release HOT 11
- MAINT: Fiona 1.10 support HOT 4
- BUG: up to 4 times slower in Linux compared to Windows when using gpd.read_file to read vector data HOT 6
- BUG: Is it possible to use GeoPandas on Windows 7 ?
- BUG: Unable to append to a layer when using fiona backend HOT 3
- BUG: plotting_with_geoplot example is broken HOT 1
- ENH: Add a Voronoi Diagram algorithm HOT 1
- BUG: The dissolve feature generates a new geometry HOT 4
- REGR: incorrect order of left sjoin with within predicate HOT 1
- BUG: wrong foxpro DBF file read HOT 7
- Fiona 1.10a2 issues HOT 2
- ENH: support writing + filtered reading from bbox columns in GeoParquet HOT 4
- ENH: support reading and writing the geoarrow-based encodings of GeoParquet
- API: Series alignment for non binary op methods HOT 5
- PERF: optimize `==` and `!=` for GeoSeries (`GeometryArray.__eq__`)
- numpy dependency missing & numpy 2.0 support status? HOT 3
- ENH: inplace=True for .dissolve and .explode? HOT 4
- BUG: `pyogrio` doesn't like io.BytesIO? HOT 10
- BUG: Issue with webpage code interp HOT 1
- ENH: sjoin() should allow to return the distance when using the dwithin predicate, just like sjoin_nearest() HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geopandas.