Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError : cell_to_boundary() got an unexpected keyword argument 'geo_json' #380

Closed
tomrussell-willdan opened this issue Jun 13, 2024 · 6 comments

Comments

@tomrussell-willdan
Copy link

cell_to_boundary() not accepting direct assingment of arguement for unpacking.
image

@ajfriend
Copy link
Contributor

Could you give an example of the behavior you're expecting?

Also, this is for v3.7. You may want to try the new v4.0: pip install h3 --pre

@tomrussell-willdan
Copy link
Author

when I use the function I try to pass it explicitly the assignment of a value to the geo_json argurment but it does not like when i do that. the example is

What I expect to do:

useGeoJsonFormat = True
cell_value = '827507fffffffff'
h3.cell_to_boundary(cell_value, geo_json=useGeoJsonFormat)

This thows the error in the title

What I end up having to do that works and is a work around

useGeoJsonFormat = True
cell_value = '827507fffffffff'
h3.cell_to_boundary(cell_value, useGeoJsonFormat)

@dfellis
Copy link
Collaborator

dfellis commented Jun 13, 2024

Looking through the source code, myself, I'm not sure that geo_json flag still exists?

EDIT: I don't see it in the Cython, either, though I didn't expect it there; more that it'd be at a higher level restructuring it's output.

EDIT2: I did a local check of the repo and there's only one place where the string geo_json exists in the 4.0 beta:

damocles@talyn:~/oss/h3-py(master)$ git grep geo_json
tests/polyfill/test_h3.py:def test_polyfill_geo_json_compliant():

So I think this feature was accidentally dropped during the rewrite for H3 4.0 vs 3.x. @tomrussell-willdan I would say if you need this feature, at the moment you should use h3-py's 3.7.x release, calling h3_to_geo_boundary and @ajfriend can either update the docs to drop this flag, or update the beta to restore this feature.

@tomrussell-willdan
Copy link
Author

thanks. I think for now we will stick on 4.0 and just flip the output ourselves. So is the plan to continue having arguements for geo_json conformity and it was just accidently not included or is the plan to not continue supporting it those arguements?

@SebKp
Copy link

SebKp commented Oct 20, 2024

@tomrussell-willdan with your solution I get:

TypeError: cell_to_boundary() takes 1 positional argument but 2 were given

It seems the flag is gone, and the documentation is out of date (deprecating the flag, and the new naming convention make more sense than before to me).


  • Edit: to get the result in geojson, an option now is to go through shapely:
from shapely import to_geojson
from shapely.geometry import Polygon

to_geojson(Polygon(h3.cell_to_boundary("827507fffffffff")))
  • Second edit:

NOTE this solution with shapely returns the coordinates in lat/lon ordering, not in lon/lat. If you are looking for lon/lat look under the @ajfriend message below.

  • Third edit:

Another option to get the geojson in lon/lat coordinates is

to_geojson(Polygon([a[::-1] for a in h3.cell_to_boundary(x)]))

@ajfriend
Copy link
Contributor

You can see the Python docs for the newly-released v4 here: https://uber.github.io/h3-py/polygon_tutorial.html

In v4, an easy way to get a __geo_interface__-style dictionary for the cell boundary would be:

d = h3.cells_to_geo(['827507fffffffff'])

giving:

{'type': 'Polygon',
 'coordinates': (((-3.4710946837530763, 6.357653288041298),
   (-2.159048476284375, 6.645580466394947),
   (-1.9395631182409523, 8.00719366148785),
   (-3.071080368716595, 9.072581251751162),
   (-4.392258230519222, 8.74778122110663),
   (-4.572995371627281, 7.395109809160045),
   (-3.4710946837530763, 6.357653288041298)),)}

which you could convert to a JSON string like:

import json
json.dumps(d)

giving:

{"type": "Polygon", "coordinates": [[[-3.4710946837530763, 6.357653288041298], [-2.159048476284375, 6.645580466394947], [-1.9395631182409523, 8.00719366148785], [-3.071080368716595, 9.072581251751162], [-4.392258230519222, 8.74778122110663], [-4.572995371627281, 7.395109809160045], [-3.4710946837530763, 6.357653288041298]]]}

We haven't yet added it, but maybe we should consider an option to give the GeoJSON string output, in addition to the dictionary output.

(@SebKp, your solution above is close, but it results in lat/lng ordering instead of the lng/lat ordering that GeoJSON expects.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants