question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implemented conversion to a "mapping"

See original GitHub issue

Shapely has a mapping function (https://shapely.readthedocs.io/en/latest/manual.html#shapely.geometry.mapping), which can convert a geometry into a dict (in geojson form):

In [59]: from shapely.geometry import mapping, LineString

In [60]: mapping(LineString([(1, 1), (3, 4)])) 
Out[60]: {'type': 'LineString', 'coordinates': ((1.0, 1.0), (3.0, 4.0))}

In geopandas, this is for example used in the iterfeatures / __geo_interface__ and so also in to_json (a method that can convert to a geojson like string, which doesn’t use fiona / GDAL like to_file, this is already faster as to_file, and can eg be used for in memory serialization to geojson).

From profiling iterfeatures in geopandas (for the countries dataset, so for polygons/multipolygons), the mapping of the geometries takes around 75% of the total time converting the dataframe to a dict.

So this mapping could be a target for (vectorized) optimization. Since it involves creating python dicts and lists, it might be better suited to do this in cython, and also given that, I am not fully sure it will necessarily give a big speedup (experiments will need to tell).

This is related to https://github.com/pygeos/pygeos/issues/65 in the sense that the same dict needs to be created for both.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
aprilmaycommented, Feb 2, 2020

A fast/direct way to generate a geojson representation would be great for using with many visualization libraries (Mapbox, Leaflet, etc). No idea if that’s useful, but gdal has a function: https://gdal.org/api/vector_c_api.html#_CPPv418OGR_G_ExportToJson12OGRGeometryH

0reactions
caspervdwcommented, Nov 13, 2021

Closing; this is solved by #413

Read more comments on GitHub >

github_iconTop Results From Across the Web

MetaDapper: Data Mapping and Conversion Made ... - Toptal
See how my favorite data mapping and conversion tool, MetaDapper, can make tedious tasks easier to undertake in this detailed tutorial.
Read more >
New Feature: The Conversion Data Mapping - AnyTrack
The conversion data mapping allows you to send conversion data to your pixels, so you can build custom audiences according to each step...
Read more >
Implementing the solution for the message map conversion ...
Implementing the solution in this scenario involves converting the message mapping solution to a graphical data map.
Read more >
7 Mapping Implementation
Create type conversion mappings with the TypeConversionMapping class. The following elements are required for a type conversion mapping:.
Read more >
Implementing & Evaluating A Standardised Map Representation
possess a lot of ROS Gridmaps but realize the implementation of PCD Pointclouds into their maps could be very beneficial. By converting both...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found