Skip to content

Commit

Permalink
Update most functions to v4.0 names (#272)
Browse files Browse the repository at this point in the history
* grid_distance

* cell_to_parent

* get_resolution

* is_pentagon

* is_res_class_III

* get_pentagons

* get_res0_cells

* get_base_cell_number

* compact and uncompact

* get_faces

* cell_to_boundary

* cell_to_latlng

* latlng_to_cell

* cell_to_children

* int_to_string and string_to_int

* cell_to_center_child

* moving things around

* is_valid_directed_edge

* grid_path_cells

* moving around

* cells_to_multi_polygon

* are_neighbor_cells

* cell_to_local_ij and local_ij_to_cell

* get_icosahedron_faces

* great_circle_distance

* get_num_cells

* note

* remove hex_range_distances and hex_ranges (easily implementable by user)

* grid_ring

* grid_disk

* moving around

* origin_to_directed_edges

* directed_edge_to_boundary

* cells_to_directed_edge

* directed_edge_to_cells

* todo: directedEdgeToCells

* get_directed_edge_origin

* get_directed_edge_destination

* grouping functions

* more grouping

* _binding to _b

* todos

* average_hexagon_area

* average_edge_length

* average_edge_length and edge_length

* average_hexagon_edge_length

* ordering

* more ordering
  • Loading branch information
ajfriend authored Aug 16, 2022
1 parent e7e8664 commit c3fc0a2
Show file tree
Hide file tree
Showing 25 changed files with 593 additions and 733 deletions.
32 changes: 16 additions & 16 deletions docs/api_comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ needs, based on speed and convenience.

```{tip}
Note that the APIs are all 100% compatible, and it is easy to convert
between them with functions like `h3_to_string` (links!) and `string_to_h3`.
between them with functions like `int_to_string` (links!) and `string_to_int`.
For example, one common pattern is to use `h3.api.numpy_int` for any
computationally-heavy work, and convert the output to `str` and `list`/`set`
Expand All @@ -54,11 +54,11 @@ using `list` and `set` for collections.

```python
>>> import h3
>>> h = h3.geo_to_h3(0, 0, 0)
>>> h = h3.latlng_to_cell(0, 0, 0)
>>> h
'8075fffffffffff'

>>> h3.hex_ring(h, 1)
>>> h3.grid_ring(h, 1)
{'8055fffffffffff',
'8059fffffffffff',
'807dfffffffffff',
Expand Down Expand Up @@ -87,11 +87,11 @@ H3 indexes are represented as Python `int`s, using `list` and `set` for collecti

```python
>>> import h3.api.basic_int as h3
>>> h = h3.geo_to_h3(0, 0, 0)
>>> h = h3.latlng_to_cell(0, 0, 0)
>>> h
578536630256664575

>>> h3.hex_ring(h, 1)
>>> h3.grid_ring(h, 1)
{577973680303243263,
578044049047420927,
578677367745019903,
Expand All @@ -110,11 +110,11 @@ no-copy `numpy` arrays instead of Python `list`s and `set`s.

```python
>>> import h3.api.numpy_int as h3
>>> h = h3.geo_to_h3(0, 0, 0)
>>> h = h3.latlng_to_cell(0, 0, 0)
>>> h
578536630256664575

>>> h3.hex_ring(h, 1)
>>> h3.grid_ring(h, 1)
array([578782920861286399, 578044049047420927, 577973680303243263,
578677367745019903, 579169948954263551], dtype=uint64)
```
Expand All @@ -141,11 +141,11 @@ In fact, `h3.api.numpy_int` is essentially just a light wrapper around

```python
>>> import h3.api.memview_int as h3
>>> h = h3.geo_to_h3(0, 0, 0)
>>> h = h3.latlng_to_cell(0, 0, 0)
>>> h
578536630256664575

>>> mv = h3.hex_ring(h, 1)
>>> mv = h3.grid_ring(h, 1)
>>> mv
<MemoryView of 'array' at 0x11188c710>

Expand Down Expand Up @@ -175,8 +175,8 @@ For example, consider the setup:
```python
>>> import h3.api.memview_int as h3
>>> import numpy as np
>>> h = h3.geo_to_h3(0, 0, 0)
>>> mv = h3.hex_ring(h, 1)
>>> h = h3.latlng_to_cell(0, 0, 0)
>>> mv = h3.grid_ring(h, 1)
>>> list(mv)
[578782920861286399,
578044049047420927,
Expand All @@ -200,7 +200,7 @@ Running `a = np.asarray(mv)` **does not create a copy**, so modifying `mv` also
modifies `a`:
```python
>>> mv = h3.hex_ring(h, 1)
>>> mv = h3.grid_ring(h, 1)
>>> a = np.asarray(mv)
>>> mv[0] = 0
>>> a
Expand Down Expand Up @@ -228,15 +228,15 @@ import h3.api.numpy_int


def compute(h3_lib, N=100):
h = h3_lib.geo_to_h3(0, 0, 9)
out = h3_lib.k_ring(h, N)
out = h3_lib.compact(out)
h = h3_lib.latlng_to_cell(0, 0, 9)
out = h3_lib.grid_disk(h, N)
out = h3_lib.compact_cells(out)

return out

def compute_and_convert(h3_lib, N=100):
out = compute(h3_lib, N)
out = [h3.h3_to_string(h) for h in out]
out = [h3.int_to_string(h) for h in out]

return out
```
Expand Down
74 changes: 36 additions & 38 deletions docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ but we'll try to group functions in a reasonably logical manner.
.. autosummary::
is_valid_cell
h3_is_pentagon
h3_is_res_class_III
h3_unidirectional_edge_is_valid
is_pentagon
is_res_class_III
is_valid_directed_edge
versions
```

Expand All @@ -32,16 +32,16 @@ but we'll try to group functions in a reasonably logical manner.
.. currentmodule:: h3
.. autosummary::
geo_to_h3
h3_to_geo
h3_to_string
string_to_h3
get_res0_indexes
get_pentagon_indexes
num_hexagons
h3_get_resolution
compact
uncompact
latlng_to_cell
cell_to_latlng
int_to_string
string_to_int
get_res0_cells
get_pentagons
get_num_cells
get_resolution
compact_cells
uncompact_cells
```

### Geographic coordinates
Expand All @@ -52,17 +52,17 @@ Functions relating H3 objects to geographic (lat/lng) coordinates.
.. currentmodule:: h3
.. autosummary::
point_dist
hex_area
great_circle_distance
average_hexagon_area
cell_area
edge_length
exact_edge_length
h3_to_geo_boundary
get_h3_unidirectional_edge_boundary
average_hexagon_edge_length
cell_to_boundary
directed_edge_to_boundary
polyfill
polyfill_geojson
polyfill_polygon
h3_set_to_multi_polygon
cells_to_multi_polygon
```

### Hierarchical relationships
Expand All @@ -71,9 +71,9 @@ Functions relating H3 objects to geographic (lat/lng) coordinates.
.. currentmodule:: h3
.. autosummary::
h3_to_parent
h3_to_children
h3_to_center_child
cell_to_parent
cell_to_children
cell_to_center_child
```

### Cell grid relationships
Expand All @@ -82,13 +82,11 @@ Functions relating H3 objects to geographic (lat/lng) coordinates.
.. currentmodule:: h3
.. autosummary::
hex_range_distances
hex_ranges
hex_ring
k_ring
h3_distance
h3_indexes_are_neighbors
h3_line
grid_ring
grid_disk
grid_distance
are_neighbor_cells
grid_path_cells
```

### Edges
Expand All @@ -97,11 +95,11 @@ Functions relating H3 objects to geographic (lat/lng) coordinates.
.. currentmodule:: h3
.. autosummary::
get_h3_unidirectional_edge
get_destination_h3_index_from_unidirectional_edge
get_h3_indexes_from_unidirectional_edge
get_h3_unidirectional_edges_from_hexagon
get_origin_h3_index_from_unidirectional_edge
cells_to_directed_edge
get_directed_edge_destination
directed_edge_to_cells
origin_to_directed_edges
get_directed_edge_origin
```

### IJ-indexing
Expand All @@ -110,10 +108,10 @@ Functions relating H3 objects to geographic (lat/lng) coordinates.
.. currentmodule:: h3
.. autosummary::
h3_get_base_cell
h3_get_faces
experimental_h3_to_local_ij
experimental_local_ij_to_h3
get_base_cell_number
get_icosahedron_faces
cell_to_local_ij
local_ij_to_cell
```


Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ conda install h3-py
>>> import h3
>>> lat, lng = 37.769377, -122.388903
>>> resolution = 9
>>> h3.geo_to_h3(lat, lng, resolution)
>>> h3.latlng_to_cell(lat, lng, resolution)
'89283082e73ffff'
```

Expand Down
64 changes: 32 additions & 32 deletions src/h3/_cy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,53 @@
from .cells import (
is_valid_cell,
is_pentagon,
get_base_cell,
resolution,
parent,
distance,
disk,
ring,
children,
compact,
uncompact,
num_hexagons,
mean_hex_area,
get_base_cell_number,
get_resolution,
cell_to_parent,
grid_distance,
grid_disk,
grid_ring,
cell_to_children,
compact_cells,
uncompact_cells,
get_num_cells,
average_hexagon_area,
cell_area,
line,
grid_path_cells,
is_res_class_iii,
get_pentagon_indexes,
get_res0_indexes,
center_child,
get_faces,
experimental_h3_to_local_ij,
experimental_local_ij_to_h3,
get_pentagons,
get_res0_cells,
cell_to_center_child,
get_icosahedron_faces,
cell_to_local_ij,
local_ij_to_cell,
)

from .edges import (
are_neighbors,
edge,
is_edge,
edge_origin,
edge_destination,
edge_cells,
edges_from_cell,
mean_edge_length,
are_neighbor_cells,
cells_to_directed_edge,
is_valid_directed_edge,
get_directed_edge_origin,
get_directed_edge_destination,
directed_edge_to_cells,
origin_to_directed_edges,
average_hexagon_edge_length,
edge_length,
)

from .geo import (
geo_to_h3,
h3_to_geo,
latlng_to_cell,
cell_to_latlng,
polyfill_polygon,
polyfill_geojson,
polyfill,
cell_boundary,
edge_boundary,
point_dist,
cell_to_boundary,
directed_edge_to_boundary,
great_circle_distance,
)

from .to_multipoly import (
h3_set_to_multi_polygon
cells_to_multi_polygon
)

from .util import (
Expand Down
37 changes: 18 additions & 19 deletions src/h3/_cy/cells.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@ from .h3lib cimport bool, int64_t, H3int

cpdef bool is_valid_cell(H3int h)
cpdef bool is_pentagon(H3int h)
cpdef int get_base_cell(H3int h) except -1
cpdef int resolution(H3int h) except -1
cpdef int distance(H3int h1, H3int h2) except -1
cpdef H3int[:] disk(H3int h, int k)
cpdef H3int[:] _ring_fallback(H3int h, int k)
cpdef H3int[:] ring(H3int h, int k)
cpdef H3int parent(H3int h, res=*) except 0
cpdef H3int[:] children(H3int h, res=*)
cpdef H3int center_child(H3int h, res=*) except 0
cpdef H3int[:] compact(const H3int[:] hu)
cpdef H3int[:] uncompact(const H3int[:] hc, int res)
cpdef int64_t num_hexagons(int resolution) except -1
cpdef double mean_hex_area(int resolution, unit=*) except -1
cpdef int get_base_cell_number(H3int h) except -1
cpdef int get_resolution(H3int h) except -1
cpdef int grid_distance(H3int h1, H3int h2) except -1
cpdef H3int[:] grid_disk(H3int h, int k)
cpdef H3int[:] grid_ring(H3int h, int k)
cpdef H3int cell_to_parent(H3int h, res=*) except 0
cpdef H3int[:] cell_to_children(H3int h, res=*)
cpdef H3int cell_to_center_child(H3int h, res=*) except 0
cpdef H3int[:] compact_cells(const H3int[:] hu)
cpdef H3int[:] uncompact_cells(const H3int[:] hc, int res)
cpdef int64_t get_num_cells(int resolution) except -1
cpdef double average_hexagon_area(int resolution, unit=*) except -1
cpdef double cell_area(H3int h, unit=*) except -1
cpdef H3int[:] line(H3int start, H3int end)
cpdef H3int[:] grid_path_cells(H3int start, H3int end)
cpdef bool is_res_class_iii(H3int h)
cpdef H3int[:] get_pentagon_indexes(int res)
cpdef H3int[:] get_res0_indexes()
cpdef get_faces(H3int h)
cpdef (int, int) experimental_h3_to_local_ij(H3int origin, H3int h) except *
cpdef H3int experimental_local_ij_to_h3(H3int origin, int i, int j) except 0
cpdef H3int[:] get_pentagons(int res)
cpdef H3int[:] get_res0_cells()
cpdef get_icosahedron_faces(H3int h)
cpdef (int, int) cell_to_local_ij(H3int origin, H3int h) except *
cpdef H3int local_ij_to_cell(H3int origin, int i, int j) except 0
Loading

0 comments on commit c3fc0a2

Please sign in to comment.