diff --git a/docs/api_comparison.md b/docs/api_comparison.md index 3700f1c9..2378702c 100644 --- a/docs/api_comparison.md +++ b/docs/api_comparison.md @@ -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` @@ -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', @@ -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, @@ -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) ``` @@ -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 @@ -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, @@ -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 @@ -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 ``` diff --git a/docs/api_reference.md b/docs/api_reference.md index b48543ae..efdc1152 100644 --- a/docs/api_reference.md +++ b/docs/api_reference.md @@ -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 ``` @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 ``` diff --git a/readme.md b/readme.md index e060f059..3ab38036 100644 --- a/readme.md +++ b/readme.md @@ -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' ``` diff --git a/src/h3/_cy/__init__.py b/src/h3/_cy/__init__.py index 303febb6..e341b3a9 100644 --- a/src/h3/_cy/__init__.py +++ b/src/h3/_cy/__init__.py @@ -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 ( diff --git a/src/h3/_cy/cells.pxd b/src/h3/_cy/cells.pxd index 7c8c078b..b6a36d18 100644 --- a/src/h3/_cy/cells.pxd +++ b/src/h3/_cy/cells.pxd @@ -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 diff --git a/src/h3/_cy/cells.pyx b/src/h3/_cy/cells.pyx index bdd31efa..6a215769 100644 --- a/src/h3/_cy/cells.pyx +++ b/src/h3/_cy/cells.pyx @@ -35,13 +35,13 @@ cpdef bool is_pentagon(H3int h): return h3lib.isPentagon(h) == 1 -cpdef int get_base_cell(H3int h) except -1: +cpdef int get_base_cell_number(H3int h) except -1: check_cell(h) return h3lib.getBaseCellNumber(h) -cpdef int resolution(H3int h) except -1: +cpdef int get_resolution(H3int h) except -1: """Returns the resolution of an H3 Index 0--15 """ @@ -50,7 +50,7 @@ cpdef int resolution(H3int h) except -1: return h3lib.getResolution(h) -cpdef int distance(H3int h1, H3int h2) except -1: +cpdef int grid_distance(H3int h1, H3int h2) except -1: """ Compute the grid distance between two cells """ cdef: @@ -65,7 +65,7 @@ cpdef int distance(H3int h1, H3int h2) except -1: return distance -cpdef H3int[:] disk(H3int h, int k): +cpdef H3int[:] grid_disk(H3int h, int k): """ Return cells at grid distance `<= k` from `h`. """ cdef: @@ -122,7 +122,7 @@ cpdef H3int[:] _ring_fallback(H3int h, int k): return mv -cpdef H3int[:] ring(H3int h, int k): +cpdef H3int[:] grid_ring(H3int h, int k): """ Return cells at grid distance `== k` from `h`. Collection is "hollow" for k >= 1. """ @@ -139,14 +139,14 @@ cpdef H3int[:] ring(H3int h, int k): return mv -cpdef H3int parent(H3int h, res=None) except 0: +cpdef H3int cell_to_parent(H3int h, res=None) except 0: cdef: H3int parent check_cell(h) # todo: do we want to check for validity here? or leave correctness to the user? if res is None: - res = resolution(h) - 1 + res = get_resolution(h) - 1 err = h3lib.cellToParent(h, res, &parent) if err: @@ -157,14 +157,14 @@ cpdef H3int parent(H3int h, res=None) except 0: return parent -cpdef H3int[:] children(H3int h, res=None): +cpdef H3int[:] cell_to_children(H3int h, res=None): cdef: int64_t n check_cell(h) if res is None: - res = resolution(h) + 1 + res = get_resolution(h) + 1 err = h3lib.cellToChildrenSize(h, res, &n) if err: @@ -181,14 +181,14 @@ cpdef H3int[:] children(H3int h, res=None): return mv -cpdef H3int center_child(H3int h, res=None) except 0: +cpdef H3int cell_to_center_child(H3int h, res=None) except 0: cdef: H3int child check_cell(h) if res is None: - res = resolution(h) + 1 + res = get_resolution(h) + 1 err = h3lib.cellToCenterChild(h, res, &child) if err: @@ -200,7 +200,7 @@ cpdef H3int center_child(H3int h, res=None) except 0: -cpdef H3int[:] compact(const H3int[:] hu): +cpdef H3int[:] compact_cells(const H3int[:] hu): # todo: fix this with my own Cython object "wrapper" class? # everything has a .ptr interface? # todo: the Clib can handle 0-len arrays because it **avoids** @@ -227,7 +227,7 @@ cpdef H3int[:] compact(const H3int[:] hu): # todo: https://stackoverflow.com/questions/50684977/cython-exception-type-for-a-function-returning-a-typed-memoryview # apparently, memoryviews are python objects, so we don't need to do the except clause -cpdef H3int[:] uncompact(const H3int[:] hc, int res): +cpdef H3int[:] uncompact_cells(const H3int[:] hc, int res): # todo: the Clib can handle 0-len arrays because it **avoids** # dereferencing the pointer, but Cython's syntax of # `&hc[0]` **requires** a dereference. For Cython, checking for array @@ -263,7 +263,7 @@ cpdef H3int[:] uncompact(const H3int[:] hc, int res): return mv -cpdef int64_t num_hexagons(int resolution) except -1: +cpdef int64_t get_num_cells(int resolution) except -1: cdef: int64_t num_cells @@ -274,7 +274,7 @@ cpdef int64_t num_hexagons(int resolution) except -1: return num_cells -cpdef double mean_hex_area(int resolution, unit='km^2') except -1: +cpdef double average_hexagon_area(int resolution, unit='km^2') except -1: cdef: double area @@ -320,7 +320,7 @@ cdef _could_not_find_line(err, start, end): check_for_error_msg(err, msg) -cpdef H3int[:] line(H3int start, H3int end): +cpdef H3int[:] grid_path_cells(H3int start, H3int end): cdef: int64_t n @@ -345,7 +345,7 @@ cpdef bool is_res_class_iii(H3int h): return h3lib.isResClassIII(h) == 1 -cpdef H3int[:] get_pentagon_indexes(int res): +cpdef H3int[:] get_pentagons(int res): n = h3lib.pentagonCount() hmm = H3MemoryManager(n) @@ -357,7 +357,7 @@ cpdef H3int[:] get_pentagon_indexes(int res): return mv -cpdef H3int[:] get_res0_indexes(): +cpdef H3int[:] get_res0_cells(): n = h3lib.res0CellCount() hmm = H3MemoryManager(n) @@ -370,7 +370,7 @@ cpdef H3int[:] get_res0_indexes(): # oh, this is returning a set?? # todo: convert to int[:]? -cpdef get_faces(H3int h): +cpdef get_icosahedron_faces(H3int h): cdef: int n int[:] faces ## todo: weird, this needs to be specified to avoid errors. cython bug? @@ -391,7 +391,7 @@ cpdef get_faces(H3int h): return out -cpdef (int, int) experimental_h3_to_local_ij(H3int origin, H3int h) except *: +cpdef (int, int) cell_to_local_ij(H3int origin, H3int h) except *: cdef: h3lib.CoordIJ c @@ -403,7 +403,7 @@ cpdef (int, int) experimental_h3_to_local_ij(H3int origin, H3int h) except *: return c.i, c.j -cpdef H3int experimental_local_ij_to_h3(H3int origin, int i, int j) except 0: +cpdef H3int local_ij_to_cell(H3int origin, int i, int j) except 0: cdef: h3lib.CoordIJ c H3int out diff --git a/src/h3/_cy/edges.pxd b/src/h3/_cy/edges.pxd index bf4c5c4a..b7fcf849 100644 --- a/src/h3/_cy/edges.pxd +++ b/src/h3/_cy/edges.pxd @@ -1,11 +1,11 @@ from .h3lib cimport bool, H3int -cpdef bool are_neighbors(H3int h1, H3int h2) -cpdef H3int edge(H3int origin, H3int destination) except * -cpdef bool is_edge(H3int e) -cpdef H3int edge_origin(H3int e) except 1 -cpdef H3int edge_destination(H3int e) except 1 -cpdef (H3int, H3int) edge_cells(H3int e) except * -cpdef H3int[:] edges_from_cell(H3int origin) -cpdef double mean_edge_length(int resolution, unit=*) except -1 +cpdef bool are_neighbor_cells(H3int h1, H3int h2) +cpdef H3int cells_to_directed_edge(H3int origin, H3int destination) except * +cpdef bool is_valid_directed_edge(H3int e) +cpdef H3int get_directed_edge_origin(H3int e) except 1 +cpdef H3int get_directed_edge_destination(H3int e) except 1 +cpdef (H3int, H3int) directed_edge_to_cells(H3int e) except * +cpdef H3int[:] origin_to_directed_edges(H3int origin) +cpdef double average_hexagon_edge_length(int resolution, unit=*) except -1 cpdef double edge_length(H3int e, unit=*) except -1 diff --git a/src/h3/_cy/edges.pyx b/src/h3/_cy/edges.pyx index 9a4fd152..3503e758 100644 --- a/src/h3/_cy/edges.pyx +++ b/src/h3/_cy/edges.pyx @@ -6,7 +6,7 @@ from .error_system cimport check_for_error from .memory cimport H3MemoryManager # todo: make bint -cpdef bool are_neighbors(H3int h1, H3int h2): +cpdef bool are_neighbor_cells(H3int h1, H3int h2): cdef: int out @@ -21,7 +21,7 @@ cpdef bool are_neighbors(H3int h1, H3int h2): return out == 1 -cpdef H3int edge(H3int origin, H3int destination) except *: +cpdef H3int cells_to_directed_edge(H3int origin, H3int destination) except *: cdef: int neighbor_out H3int out @@ -33,10 +33,10 @@ cpdef H3int edge(H3int origin, H3int destination) except *: return out -cpdef bool is_edge(H3int e): +cpdef bool is_valid_directed_edge(H3int e): return h3lib.isValidDirectedEdge(e) == 1 -cpdef H3int edge_origin(H3int e) except 1: +cpdef H3int get_directed_edge_origin(H3int e) except 1: cdef: H3int out @@ -46,7 +46,7 @@ cpdef H3int edge_origin(H3int e) except 1: return out -cpdef H3int edge_destination(H3int e) except 1: +cpdef H3int get_directed_edge_destination(H3int e) except 1: cdef: H3int out @@ -56,10 +56,11 @@ cpdef H3int edge_destination(H3int e) except 1: return out -cpdef (H3int, H3int) edge_cells(H3int e) except *: - return edge_origin(e), edge_destination(e) +cpdef (H3int, H3int) directed_edge_to_cells(H3int e) except *: + # todo: use directed_edge_to_cells in h3lib + return get_directed_edge_origin(e), get_directed_edge_destination(e) -cpdef H3int[:] edges_from_cell(H3int origin): +cpdef H3int[:] origin_to_directed_edges(H3int origin): """ Returns the 6 (or 5 for pentagons) directed edges for the given origin cell """ @@ -73,7 +74,7 @@ cpdef H3int[:] edges_from_cell(H3int origin): return mv -cpdef double mean_edge_length(int resolution, unit='km') except -1: +cpdef double average_hexagon_edge_length(int resolution, unit='km') except -1: cdef: double length diff --git a/src/h3/_cy/geo.pxd b/src/h3/_cy/geo.pxd index 1a2c1c33..40dfc349 100644 --- a/src/h3/_cy/geo.pxd +++ b/src/h3/_cy/geo.pxd @@ -1,7 +1,7 @@ from .h3lib cimport H3int -cpdef H3int geo_to_h3(double lat, double lng, int res) except 1 -cpdef (double, double) h3_to_geo(H3int h) except * -cpdef double point_dist( +cpdef H3int latlng_to_cell(double lat, double lng, int res) except 1 +cpdef (double, double) cell_to_latlng(H3int h) except * +cpdef double great_circle_distance( double lat1, double lng1, double lat2, double lng2, unit=*) except -1 diff --git a/src/h3/_cy/geo.pyx b/src/h3/_cy/geo.pyx index f6a52215..001aca29 100644 --- a/src/h3/_cy/geo.pyx +++ b/src/h3/_cy/geo.pyx @@ -24,7 +24,7 @@ from libc.stdlib cimport ( ) -cpdef H3int geo_to_h3(double lat, double lng, int res) except 1: +cpdef H3int latlng_to_cell(double lat, double lng, int res) except 1: cdef: h3lib.LatLng c H3int out @@ -38,7 +38,7 @@ cpdef H3int geo_to_h3(double lat, double lng, int res) except 1: return out -cpdef (double, double) h3_to_geo(H3int h) except *: +cpdef (double, double) cell_to_latlng(H3int h) except *: """Map an H3 cell into its centroid geo-coordinate (lat/lng)""" cdef: h3lib.LatLng c @@ -237,7 +237,7 @@ def polyfill(dict geojson, int res, bool geo_json_conformant=False): return out -def cell_boundary(H3int h, bool geo_json=False): +def cell_to_boundary(H3int h, bool geo_json=False): """Compose an array of geo-coordinates that outlines a hexagonal cell""" cdef: h3lib.CellBoundary gb @@ -259,7 +259,7 @@ def cell_boundary(H3int h, bool geo_json=False): return verts -def edge_boundary(H3int edge, bool geo_json=False): +def directed_edge_to_boundary(H3int edge, bool geo_json=False): """ Returns the CellBoundary containing the coordinates of the edge """ cdef: @@ -283,7 +283,7 @@ def edge_boundary(H3int edge, bool geo_json=False): return verts -cpdef double point_dist( +cpdef double great_circle_distance( double lat1, double lng1, double lat2, double lng2, unit='km') except -1: diff --git a/src/h3/_cy/h3lib.pxd b/src/h3/_cy/h3lib.pxd index ec225bd3..150b549b 100644 --- a/src/h3/_cy/h3lib.pxd +++ b/src/h3/_cy/h3lib.pxd @@ -138,6 +138,7 @@ cdef extern from 'h3api.h': H3Error getDirectedEdgeOrigin(H3int edge, H3int *out) nogil H3Error getDirectedEdgeDestination(H3int edge, H3int *out) nogil H3Error originToDirectedEdges(H3int origin, H3int *edges) nogil + # todo: directedEdgeToCells H3Error getHexagonEdgeLengthAvgKm(int res, double *out) nogil H3Error getHexagonEdgeLengthAvgM(int res, double *out) nogil diff --git a/src/h3/_cy/to_multipoly.pyx b/src/h3/_cy/to_multipoly.pyx index 7a421f7c..588e2838 100644 --- a/src/h3/_cy/to_multipoly.pyx +++ b/src/h3/_cy/to_multipoly.pyx @@ -59,7 +59,7 @@ def _geojson_loop(loop): return loop -def h3_set_to_multi_polygon(const H3int[:] hexes, geo_json=False): +def cells_to_multi_polygon(const H3int[:] hexes, geo_json=False): # todo: gotta be a more elegant way to handle these... if len(hexes) == 0: return [] diff --git a/src/h3/api/_api_template.py b/src/h3/api/_api_template.py index 0274e7fa..bc837bcf 100644 --- a/src/h3/api/_api_template.py +++ b/src/h3/api/_api_template.py @@ -78,7 +78,7 @@ def versions(): return v @staticmethod - def string_to_h3(h): + def string_to_int(h): """ Converts a hexadecimal string to an H3 64-bit integer index. @@ -95,7 +95,7 @@ def string_to_h3(h): return _cy.hex2int(h) @staticmethod - def h3_to_string(x): + def int_to_string(x): """ Converts an H3 64-bit integer index to a hexadecimal string. @@ -112,7 +112,7 @@ def h3_to_string(x): return _cy.int2hex(x) @staticmethod - def num_hexagons(resolution): + def get_num_cells(resolution): """ Return the total number of *cells* (hexagons and pentagons) for the given resolution. @@ -121,10 +121,10 @@ def num_hexagons(resolution): ------- int """ - return _cy.num_hexagons(resolution) + return _cy.get_num_cells(resolution) @staticmethod - def hex_area(resolution, unit='km^2'): + def average_hexagon_area(resolution, unit='km^2'): """ Return the average area of an H3 *hexagon* for the given resolution. @@ -135,11 +135,10 @@ def hex_area(resolution, unit='km^2'): ------- float """ - # todo: `mean_hex_area` in 4.0 - return _cy.mean_hex_area(resolution, unit) + return _cy.average_hexagon_area(resolution, unit) @staticmethod - def edge_length(resolution, unit='km'): + def average_hexagon_edge_length(resolution, unit='km'): """ Return the average *hexagon* edge length for the given resolution. @@ -150,8 +149,7 @@ def edge_length(resolution, unit='km'): ------- float """ - # todo: `mean_edge_length` in 4.0 - return _cy.mean_edge_length(resolution, unit) + return _cy.average_hexagon_edge_length(resolution, unit) def is_valid_cell(self, h): """ @@ -167,7 +165,7 @@ def is_valid_cell(self, h): except (ValueError, TypeError): return False - def h3_unidirectional_edge_is_valid(self, edge): + def is_valid_directed_edge(self, edge): """ Validates an H3 unidirectional edge. @@ -177,11 +175,11 @@ def h3_unidirectional_edge_is_valid(self, edge): """ try: e = self._in_scalar(edge) - return _cy.is_edge(e) + return _cy.is_valid_directed_edge(e) except (ValueError, TypeError): return False - def geo_to_h3(self, lat, lng, resolution): + def latlng_to_cell(self, lat, lng, resolution): """ Return the cell containing the (lat, lng) point for a given resolution. @@ -191,9 +189,9 @@ def geo_to_h3(self, lat, lng, resolution): H3Cell """ - return self._out_scalar(_cy.geo_to_h3(lat, lng, resolution)) + return self._out_scalar(_cy.latlng_to_cell(lat, lng, resolution)) - def h3_to_geo(self, h): + def cell_to_latlng(self, h): """ Return the center point of an H3 cell as a lat/lng pair. @@ -208,9 +206,9 @@ def h3_to_geo(self, h): lng : float Longitude """ - return _cy.h3_to_geo(self._in_scalar(h)) + return _cy.cell_to_latlng(self._in_scalar(h)) - def h3_get_resolution(self, h): + def get_resolution(self, h): """ Return the resolution of an H3 cell. @@ -223,9 +221,9 @@ def h3_get_resolution(self, h): int """ # todo: could also work for edges - return _cy.resolution(self._in_scalar(h)) + return _cy.get_resolution(self._in_scalar(h)) - def h3_to_parent(self, h, res=None): + def cell_to_parent(self, h, res=None): """ Get the parent of a cell. @@ -241,12 +239,12 @@ def h3_to_parent(self, h, res=None): H3Cell """ h = self._in_scalar(h) - p = _cy.parent(h, res) + p = _cy.cell_to_parent(h, res) p = self._out_scalar(p) return p - def h3_distance(self, h1, h2): + def grid_distance(self, h1, h2): """ Compute the H3 distance between two cells. @@ -269,11 +267,11 @@ def h3_distance(self, h1, h2): h1 = self._in_scalar(h1) h2 = self._in_scalar(h2) - d = _cy.distance(h1, h2) + d = _cy.grid_distance(h1, h2) return d - def h3_to_geo_boundary(self, h, geo_json=False): + def cell_to_boundary(self, h, geo_json=False): """ Return tuple of lat/lng pairs describing the cell boundary. @@ -291,9 +289,9 @@ def h3_to_geo_boundary(self, h, geo_json=False): ------- tuple of (float, float) tuples """ - return _cy.cell_boundary(self._in_scalar(h), geo_json) + return _cy.cell_to_boundary(self._in_scalar(h), geo_json) - def k_ring(self, h, k=1): + def grid_disk(self, h, k=1): """ Return unordered set of cells with H3 distance ``<= k`` from ``h``. That is, the "filled-in" disk. @@ -308,11 +306,11 @@ def k_ring(self, h, k=1): ------- unordered collection of H3Cell """ - mv = _cy.disk(self._in_scalar(h), k) + mv = _cy.grid_disk(self._in_scalar(h), k) return self._out_unordered(mv) - def hex_ring(self, h, k=1): + def grid_ring(self, h, k=1): """ Return unordered set of cells with H3 distance ``== k`` from ``h``. That is, the "hollow" ring. @@ -327,49 +325,11 @@ def hex_ring(self, h, k=1): ------- unordered collection of H3Cell """ - mv = _cy.ring(self._in_scalar(h), k) + mv = _cy.grid_ring(self._in_scalar(h), k) return self._out_unordered(mv) - def hex_range_distances(self, h, K): - """ - Ordered list of the "hollow" rings around ``h``, - up to and including distance ``K``. - - Parameters - ---------- - h : H3Cell - K : int - Largest distance considered. - - Returns - ------- - ordered collection of (unordered collection of H3Cell) - """ - h = self._in_scalar(h) - - out = [ - self._out_unordered(_cy.ring(h, k)) - for k in range(K + 1) - ] - - return out - - def hex_ranges(self, hexes, K): - """ - Returns the dictionary ``{h: hex_range_distances(h, K) for h in hexes}`` - - Returns - ------- - Dict[H3Cell, List[ UnorderedCollection[H3Cell] ]] - """ - # todo: can we drop this function? the user can implement if needed. - # TODO: should we call `out_scalar` on the dict keys? - out = {h: self.hex_range_distances(h, K) for h in hexes} - - return out - - def h3_to_children(self, h, res=None): + def cell_to_children(self, h, res=None): """ Children of a hexagon. @@ -384,12 +344,12 @@ def h3_to_children(self, h, res=None): ------- unordered collection of H3Cell """ - mv = _cy.children(self._in_scalar(h), res) + mv = _cy.cell_to_children(self._in_scalar(h), res) return self._out_unordered(mv) # todo: nogil for expensive C operation? - def compact(self, hexes): + def compact_cells(self, hexes): """ Compact a collection of H3 cells by combining smaller cells into larger cells, if all child cells @@ -403,15 +363,15 @@ def compact(self, hexes): ------- unordered collection of H3Cell """ - # todo: does compact work on mixed-resolution collections? + # todo: does compact_cells work on mixed-resolution collections? hu = self._in_collection(hexes) - hc = _cy.compact(hu) + hc = _cy.compact_cells(hu) return self._out_unordered(hc) - def uncompact(self, hexes, res): + def uncompact_cells(self, hexes, res): """ - Reverse the `compact` operation. + Reverse the `compact_cells` operation. Return a collection of H3 cells, all of resolution ``res``. @@ -432,11 +392,11 @@ def uncompact(self, hexes, res): https://github.com/uber/h3/blob/master/src/h3lib/lib/h3Index.c#L425 """ hc = self._in_collection(hexes) - hu = _cy.uncompact(hc, res) + hu = _cy.uncompact_cells(hc, res) return self._out_unordered(hu) - def h3_set_to_multi_polygon(self, hexes, geo_json=False): + def cells_to_multi_polygon(self, hexes, geo_json=False): """ Get GeoJSON-like MultiPolygon describing the outline of the area covered by a set of H3 cells. @@ -463,7 +423,7 @@ def h3_set_to_multi_polygon(self, hexes, geo_json=False): # This function returns a list of polygons, while `polyfill` returns # a GeoJSON-like dictionary object. hexes = self._in_collection(hexes) - return _cy.h3_set_to_multi_polygon(hexes, geo_json=geo_json) + return _cy.cells_to_multi_polygon(hexes, geo_json=geo_json) def polyfill_polygon(self, outer, res, holes=None, lnglat_order=False): mv = _cy.polyfill_polygon(outer, res, holes=holes, lnglat_order=lnglat_order) @@ -514,7 +474,7 @@ def polyfill(self, geojson, res, geo_json_conformant=False): return self._out_unordered(mv) - def h3_is_pentagon(self, h): + def is_pentagon(self, h): """ Identify if an H3 cell is a pentagon. @@ -534,7 +494,7 @@ def h3_is_pentagon(self, h): """ return _cy.is_pentagon(self._in_scalar(h)) - def h3_get_base_cell(self, h): + def get_base_cell_number(self, h): """ Return the base cell *number* (``0`` to ``121``) of the given cell. @@ -554,9 +514,9 @@ def h3_get_base_cell(self, h): ------- int """ - return _cy.get_base_cell(self._in_scalar(h)) + return _cy.get_base_cell_number(self._in_scalar(h)) - def h3_indexes_are_neighbors(self, h1, h2): + def are_neighbor_cells(self, h1, h2): """ Returns ``True`` if ``h1`` and ``h2`` are neighboring cells. @@ -572,9 +532,9 @@ def h3_indexes_are_neighbors(self, h1, h2): h1 = self._in_scalar(h1) h2 = self._in_scalar(h2) - return _cy.are_neighbors(h1, h2) + return _cy.are_neighbor_cells(h1, h2) - def get_h3_unidirectional_edge(self, origin, destination): + def cells_to_directed_edge(self, origin, destination): """ Create an H3 Index denoting a unidirectional edge. @@ -597,12 +557,12 @@ def get_h3_unidirectional_edge(self, origin, destination): """ o = self._in_scalar(origin) d = self._in_scalar(destination) - e = _cy.edge(o, d) + e = _cy.cells_to_directed_edge(o, d) e = self._out_scalar(e) return e - def get_origin_h3_index_from_unidirectional_edge(self, e): + def get_directed_edge_origin(self, e): """ Origin cell from an H3 directed edge. @@ -615,12 +575,12 @@ def get_origin_h3_index_from_unidirectional_edge(self, e): H3Cell """ e = self._in_scalar(e) - o = _cy.edge_origin(e) + o = _cy.get_directed_edge_origin(e) o = self._out_scalar(o) return o - def get_destination_h3_index_from_unidirectional_edge(self, e): + def get_directed_edge_destination(self, e): """ Destination cell from an H3 directed edge. @@ -633,12 +593,12 @@ def get_destination_h3_index_from_unidirectional_edge(self, e): H3Cell """ e = self._in_scalar(e) - d = _cy.edge_destination(e) + d = _cy.get_directed_edge_destination(e) d = self._out_scalar(d) return d - def get_h3_indexes_from_unidirectional_edge(self, e): + def directed_edge_to_cells(self, e): """ Return (origin, destination) tuple from H3 directed edge @@ -654,12 +614,12 @@ def get_h3_indexes_from_unidirectional_edge(self, e): Destination cell of edge """ e = self._in_scalar(e) - o, d = _cy.edge_cells(e) + o, d = _cy.directed_edge_to_cells(e) o, d = self._out_scalar(o), self._out_scalar(d) return o, d - def get_h3_unidirectional_edges_from_hexagon(self, origin): + def origin_to_directed_edges(self, origin): """ Return all directed edges starting from ``origin`` cell. @@ -671,14 +631,14 @@ def get_h3_unidirectional_edges_from_hexagon(self, origin): ------- unordered collection of H3Edge """ - mv = _cy.edges_from_cell(self._in_scalar(origin)) + mv = _cy.origin_to_directed_edges(self._in_scalar(origin)) return self._out_unordered(mv) - def get_h3_unidirectional_edge_boundary(self, edge, geo_json=False): - return _cy.edge_boundary(self._in_scalar(edge), geo_json=geo_json) + def directed_edge_to_boundary(self, edge, geo_json=False): + return _cy.directed_edge_to_boundary(self._in_scalar(edge), geo_json=geo_json) - def h3_line(self, start, end): + def grid_path_cells(self, start, end): """ Returns the ordered collection of cells denoting a minimum-length non-unique path between cells. @@ -693,11 +653,11 @@ def h3_line(self, start, end): ordered collection of H3Cell Starting with ``start``, and ending with ``end``. """ - mv = _cy.line(self._in_scalar(start), self._in_scalar(end)) + mv = _cy.grid_path_cells(self._in_scalar(start), self._in_scalar(end)) return self._out_ordered(mv) - def h3_is_res_class_III(self, h): + def is_res_class_III(self, h): """ Determine if cell has orientation "Class II" or "Class III". @@ -726,7 +686,7 @@ def h3_is_res_class_III(self, h): """ return _cy.is_res_class_iii(self._in_scalar(h)) - def get_pentagon_indexes(self, resolution): + def get_pentagons(self, resolution): """ Return all pentagons at a given resolution. @@ -738,11 +698,11 @@ def get_pentagon_indexes(self, resolution): ------- unordered collection of H3Cell """ - mv = _cy.get_pentagon_indexes(resolution) + mv = _cy.get_pentagons(resolution) return self._out_unordered(mv) - def get_res0_indexes(self): + def get_res0_cells(self): """ Return all cells at resolution 0. @@ -754,11 +714,11 @@ def get_res0_indexes(self): ------- unordered collection of H3Cell """ - mv = _cy.get_res0_indexes() + mv = _cy.get_res0_cells() return self._out_unordered(mv) - def h3_to_center_child(self, h, res=None): + def cell_to_center_child(self, h, res=None): """ Get the center child of a cell at some finer resolution. @@ -774,12 +734,12 @@ def h3_to_center_child(self, h, res=None): H3Cell """ h = self._in_scalar(h) - p = _cy.center_child(h, res) + p = _cy.cell_to_center_child(h, res) p = self._out_scalar(p) return p - def h3_get_faces(self, h): + def get_icosahedron_faces(self, h): """ Return icosahedron faces intersecting a given H3 cell. @@ -796,11 +756,11 @@ def h3_get_faces(self, h): Python ``set`` of ``int`` """ h = self._in_scalar(h) - faces = _cy.get_faces(h) + faces = _cy.get_icosahedron_faces(h) return faces - def experimental_h3_to_local_ij(self, origin, h): + def cell_to_local_ij(self, origin, h): """ Return local (i,j) coordinates of cell ``h`` in relation to ``origin`` cell @@ -834,11 +794,11 @@ def experimental_h3_to_local_ij(self, origin, h): origin = self._in_scalar(origin) h = self._in_scalar(h) - i, j = _cy.experimental_h3_to_local_ij(origin, h) + i, j = _cy.cell_to_local_ij(origin, h) return i, j - def experimental_local_ij_to_h3(self, origin, i, j): + def local_ij_to_cell(self, origin, i, j): """ Return cell at local (i,j) position relative to the ``origin`` cell. @@ -869,7 +829,7 @@ def experimental_local_ij_to_h3(self, origin, i, j): """ origin = self._in_scalar(origin) - h = _cy.experimental_local_ij_to_h3(origin, i, j) + h = _cy.local_ij_to_cell(origin, i, j) h = self._out_scalar(h) return h @@ -895,13 +855,13 @@ def cell_area(self, h, unit='km^2'): This function breaks the cell into spherical triangles, and computes their spherical area. The function uses the spherical distance calculation given by - `point_dist`. + `great_circle_distance`. """ h = self._in_scalar(h) return _cy.cell_area(h, unit=unit) - def exact_edge_length(self, e, unit='km'): + def edge_length(self, e, unit='km'): """ Compute the spherical length of a specific H3 edge. @@ -920,14 +880,14 @@ def exact_edge_length(self, e, unit='km'): Notes ----- This function uses the spherical distance calculation given by - `point_dist`. + `great_circle_distance`. """ e = self._in_scalar(e) return _cy.edge_length(e, unit=unit) @staticmethod - def point_dist(point1, point2, unit='km'): + def great_circle_distance(point1, point2, unit='km'): """ Compute the spherical distance between two (lat, lng) points. @@ -935,6 +895,8 @@ def point_dist(point1, point2, unit='km'): about (lat1, lng1, lat2, lng2) as the input? How will this work for vectorized versions? + todo: overload to allow two cell inputs? + Parameters ---------- point1 : tuple @@ -952,7 +914,7 @@ def point_dist(point1, point2, unit='km'): lat1, lng1 = point1 lat2, lng2 = point2 - return _cy.point_dist( + return _cy.great_circle_distance( lat1, lng1, lat2, lng2, unit=unit diff --git a/src/h3/api/basic_int/_public_api.py b/src/h3/api/basic_int/_public_api.py index b25064e2..56c6a43f 100644 --- a/src/h3/api/basic_int/_public_api.py +++ b/src/h3/api/basic_int/_public_api.py @@ -6,58 +6,59 @@ This file exists to avoid dynamically modifying `globals` and support static tooling. """ -from ._binding import _binding - -cell_area = _binding.cell_area -compact = _binding.compact -edge_length = _binding.edge_length -exact_edge_length = _binding.exact_edge_length -experimental_h3_to_local_ij = _binding.experimental_h3_to_local_ij -experimental_local_ij_to_h3 = _binding.experimental_local_ij_to_h3 -geo_to_h3 = _binding.geo_to_h3 -get_destination_h3_index_from_unidirectional_edge = ( - _binding.get_destination_h3_index_from_unidirectional_edge -) -get_h3_indexes_from_unidirectional_edge = ( - _binding.get_h3_indexes_from_unidirectional_edge -) -get_h3_unidirectional_edge = _binding.get_h3_unidirectional_edge -get_h3_unidirectional_edge_boundary = _binding.get_h3_unidirectional_edge_boundary -get_h3_unidirectional_edges_from_hexagon = ( - _binding.get_h3_unidirectional_edges_from_hexagon -) -get_origin_h3_index_from_unidirectional_edge = ( - _binding.get_origin_h3_index_from_unidirectional_edge -) -get_pentagon_indexes = _binding.get_pentagon_indexes -get_res0_indexes = _binding.get_res0_indexes -h3_distance = _binding.h3_distance -h3_get_base_cell = _binding.h3_get_base_cell -h3_get_faces = _binding.h3_get_faces -h3_get_resolution = _binding.h3_get_resolution -h3_indexes_are_neighbors = _binding.h3_indexes_are_neighbors -h3_is_pentagon = _binding.h3_is_pentagon -h3_is_res_class_III = _binding.h3_is_res_class_III -is_valid_cell = _binding.is_valid_cell -h3_line = _binding.h3_line -h3_set_to_multi_polygon = _binding.h3_set_to_multi_polygon -h3_to_center_child = _binding.h3_to_center_child -h3_to_children = _binding.h3_to_children -h3_to_geo = _binding.h3_to_geo -h3_to_geo_boundary = _binding.h3_to_geo_boundary -h3_to_parent = _binding.h3_to_parent -h3_to_string = _binding.h3_to_string -h3_unidirectional_edge_is_valid = _binding.h3_unidirectional_edge_is_valid -hex_area = _binding.hex_area -hex_range_distances = _binding.hex_range_distances -hex_ranges = _binding.hex_ranges -hex_ring = _binding.hex_ring -k_ring = _binding.k_ring -num_hexagons = _binding.num_hexagons -point_dist = _binding.point_dist -polyfill = _binding.polyfill -polyfill_geojson = _binding.polyfill_geojson -polyfill_polygon = _binding.polyfill_polygon -string_to_h3 = _binding.string_to_h3 -uncompact = _binding.uncompact -versions = _binding.versions +from ._binding import _binding as _b + + +is_valid_cell = _b.is_valid_cell +is_pentagon = _b.is_pentagon +is_valid_directed_edge = _b.is_valid_directed_edge +is_res_class_III = _b.is_res_class_III + +int_to_string = _b.int_to_string +string_to_int = _b.string_to_int + +cell_area = _b.cell_area +edge_length = _b.edge_length +great_circle_distance = _b.great_circle_distance +average_hexagon_area = _b.average_hexagon_area +average_hexagon_edge_length = _b.average_hexagon_edge_length + +latlng_to_cell = _b.latlng_to_cell +cell_to_latlng = _b.cell_to_latlng +cell_to_boundary = _b.cell_to_boundary +cell_to_local_ij = _b.cell_to_local_ij +local_ij_to_cell = _b.local_ij_to_cell + +grid_ring = _b.grid_ring +grid_disk = _b.grid_disk +grid_distance = _b.grid_distance +grid_path_cells = _b.grid_path_cells + +get_num_cells = _b.get_num_cells +get_pentagons = _b.get_pentagons +get_res0_cells = _b.get_res0_cells +get_resolution = _b.get_resolution +get_base_cell_number = _b.get_base_cell_number +get_icosahedron_faces = _b.get_icosahedron_faces + +cell_to_parent = _b.cell_to_parent +cell_to_children = _b.cell_to_children +cell_to_center_child = _b.cell_to_center_child +compact_cells = _b.compact_cells +uncompact_cells = _b.uncompact_cells + +# todo: think through polyfill functions +polyfill = _b.polyfill +polyfill_geojson = _b.polyfill_geojson +polyfill_polygon = _b.polyfill_polygon +cells_to_multi_polygon = _b.cells_to_multi_polygon + +are_neighbor_cells = _b.are_neighbor_cells +cells_to_directed_edge = _b.cells_to_directed_edge +directed_edge_to_cells = _b.directed_edge_to_cells +origin_to_directed_edges = _b.origin_to_directed_edges +get_directed_edge_origin = _b.get_directed_edge_origin +get_directed_edge_destination = _b.get_directed_edge_destination +directed_edge_to_boundary = _b.directed_edge_to_boundary + +versions = _b.versions diff --git a/tests/cython_example.pyx b/tests/cython_example.pyx index e8d28594..a465bd6e 100644 --- a/tests/cython_example.pyx +++ b/tests/cython_example.pyx @@ -1,11 +1,11 @@ from cython cimport boundscheck, wraparound from h3._cy.h3lib cimport H3int -from h3._cy.geo cimport geo_to_h3 +from h3._cy.geo cimport latlng_to_cell @boundscheck(False) @wraparound(False) -cpdef void geo_to_h3_vect( +cpdef void latlng_to_cell_vect( const double[:] lat, const double[:] lng, int res, @@ -15,4 +15,4 @@ cpdef void geo_to_h3_vect( cdef Py_ssize_t i for i in range(len(lat)): - out[i] = geo_to_h3(lat[i], lng[i], res) + out[i] = latlng_to_cell(lat[i], lng[i], res) diff --git a/tests/test_basic_int.py b/tests/test_basic_int.py index d5c47c02..1b8b8b31 100644 --- a/tests/test_basic_int.py +++ b/tests/test_basic_int.py @@ -5,11 +5,11 @@ def test_int_output(): lat = 37.7752702151959 lng = -122.418307270836 - assert h3.geo_to_h3(lat, lng, 9) == 617700169958293503 - assert h3.geo_to_h3(lat, lng, 9) == 0x8928308280fffff + assert h3.latlng_to_cell(lat, lng, 9) == 617700169958293503 + assert h3.latlng_to_cell(lat, lng, 9) == 0x8928308280fffff -def test_k_ring(): +def test_grid_disk(): expected = { 617700169957507071, 617700169957769215, @@ -20,29 +20,29 @@ def test_k_ring(): 617700169965109247, } - out = h3.k_ring(617700169958293503, 1) + out = h3.grid_disk(617700169958293503, 1) assert out == expected -def test_compact(): +def test_compact_cells(): h = 617700169958293503 - hexes = h3.h3_to_children(h) + hexes = h3.cell_to_children(h) - assert h3.compact(hexes) == {h} + assert h3.compact_cells(hexes) == {h} -def test_get_faces(): +def test_get_icosahedron_faces(): h = 577832942814887935 expected = {2, 3, 7, 8, 12} - out = h3.h3_get_faces(h) + out = h3.get_icosahedron_faces(h) assert out == expected h = 579873636396040191 expected = {13} - out = h3.h3_get_faces(h) + out = h3.get_icosahedron_faces(h) assert out == expected h = 579768083279773695 expected = {16, 15} - out = h3.h3_get_faces(h) + out = h3.get_icosahedron_faces(h) assert out == expected diff --git a/tests/test_basic_str.py b/tests/test_basic_str.py index f7656784..eaae35bb 100644 --- a/tests/test_basic_str.py +++ b/tests/test_basic_str.py @@ -2,7 +2,8 @@ def test1(): - assert h3.geo_to_h3(37.7752702151959, -122.418307270836, 9) == '8928308280fffff' + lat, lng = 37.7752702151959, -122.418307270836 + assert h3.latlng_to_cell(lat, lng, 9) == '8928308280fffff' def test5(): @@ -16,5 +17,5 @@ def test5(): '89283082803ffff' } - out = h3.k_ring('8928308280fffff', 1) + out = h3.grid_disk('8928308280fffff', 1) assert out == expected diff --git a/tests/test_cells_and_edges.py b/tests/test_cells_and_edges.py index 194b05b4..cfe6f178 100644 --- a/tests/test_cells_and_edges.py +++ b/tests/test_cells_and_edges.py @@ -22,14 +22,15 @@ def approx2(a, b): def test1(): - assert h3.geo_to_h3(37.7752702151959, -122.418307270836, 9) == '8928308280fffff' + lat, lng = 37.7752702151959, -122.418307270836 + assert h3.latlng_to_cell(lat, lng, 9) == '8928308280fffff' def test2(): h = '8928308280fffff' expected = (37.77670234943567, -122.41845932318311) - assert h3.h3_to_geo(h) == pytest.approx(expected) + assert h3.cell_to_latlng(h) == pytest.approx(expected) def test3(): @@ -42,7 +43,7 @@ def test3(): (37.775019673792606, -122.4195306280734), ) - out = h3.h3_to_geo_boundary('8928308280fffff') + out = h3.cell_to_boundary('8928308280fffff') assert approx2(out, expected) @@ -57,18 +58,18 @@ def test4(): (-122.41719971841658, 37.775197782893386) ) - out = h3.h3_to_geo_boundary('8928308280fffff', geo_json=True) + out = h3.cell_to_boundary('8928308280fffff', geo_json=True) assert approx2(out, expected) -def test_k_ring_distance(): +def test_grid_disk_distance(): with pytest.raises(H3DomainError): - h3.k_ring('8928308280fffff', -10) + h3.grid_disk('8928308280fffff', -10) -def test_hex_ring_distance(): +def test_grid_ring_distance(): with pytest.raises(H3DomainError): - h3.hex_ring('8928308280fffff', -10) + h3.grid_ring('8928308280fffff', -10) def test5(): @@ -82,13 +83,13 @@ def test5(): '89283082803ffff' } - out = h3.k_ring('8928308280fffff', 1) + out = h3.grid_disk('8928308280fffff', 1) assert out == expected def test6(): expected = {'8928308280fffff'} - out = h3.hex_ring('8928308280fffff', 0) + out = h3.grid_ring('8928308280fffff', 0) assert out == expected @@ -102,7 +103,7 @@ def test7(): '89283082877ffff' } - out = h3.hex_ring('8928308280fffff', 1) + out = h3.grid_ring('8928308280fffff', 1) assert out == expected @@ -116,41 +117,41 @@ def test8(): # other methods should validate and raise exception if bad input with pytest.raises(H3CellInvalidError): - h3.h3_get_resolution(h_bad) + h3.get_resolution(h_bad) def test9(): - assert h3.h3_get_resolution('8928308280fffff') == 9 - assert h3.h3_get_resolution('8a28308280f7fff') == 10 + assert h3.get_resolution('8928308280fffff') == 9 + assert h3.get_resolution('8a28308280f7fff') == 10 def test_parent(): h = '8928308280fffff' - assert h3.h3_to_parent(h, 7) == '872830828ffffff' - assert h3.h3_to_parent(h, 8) == '8828308281fffff' - assert h3.h3_to_parent(h, 9) == h + assert h3.cell_to_parent(h, 7) == '872830828ffffff' + assert h3.cell_to_parent(h, 8) == '8828308281fffff' + assert h3.cell_to_parent(h, 9) == h with pytest.raises(H3ResMismatchError): - h3.h3_to_parent(h, 10) + h3.cell_to_parent(h, 10) def test_parent_err(): # Test 1 - h = '8075fffffffffff' # geo_to_h3(0,0,0) + h = '8075fffffffffff' # latlng_to_cell(0,0,0) with pytest.raises(H3ResDomainError): - h3.h3_to_parent(h) + h3.cell_to_parent(h) # Test 2 try: - h3.h3_to_parent(h) + h3.cell_to_parent(h) except Exception as e: msg = str(e) # todo: revist this weird formatting stuff expected = 'Invalid parent resolution -1 for cell {}.' - expected = expected.format(hex(h3.string_to_h3(h))) + expected = expected.format(hex(h3.string_to_int(h))) assert msg == expected @@ -159,10 +160,10 @@ def test_children(): h = '8928308280fffff' with pytest.raises(H3ResDomainError): - h3.h3_to_children(h, 8) + h3.cell_to_children(h, 8) # same resolution is set of just cell itself - out = h3.h3_to_children(h, 9) + out = h3.cell_to_children(h, 9) assert out == {h} # one below should give children @@ -175,13 +176,13 @@ def test_children(): '8a28308280effff', '8a28308280f7fff' } - out = h3.h3_to_children(h, 10) + out = h3.cell_to_children(h, 10) assert out == expected # finest resolution cell should return error for children h = '8f04ccb2c45e225' with pytest.raises(H3ResDomainError): - h3.h3_to_children(h) + h3.cell_to_children(h) def test_center_child(): @@ -189,30 +190,30 @@ def test_center_child(): # one above should raise an exception with pytest.raises(H3ResDomainError): - h3.h3_to_center_child(h, 8) + h3.cell_to_center_child(h, 8) # same resolution should be same cell - assert h3.h3_to_center_child(h, 9) == h + assert h3.cell_to_center_child(h, 9) == h # one below should give direct child expected = '8a28308280c7fff' - assert h3.h3_to_center_child(h, 10) == expected + assert h3.cell_to_center_child(h, 10) == expected # finest resolution hex should return error for child h = '8f04ccb2c45e225' with pytest.raises(H3ResDomainError): - h3.h3_to_center_child(h) + h3.cell_to_center_child(h) def test_distance(): h = '8a28308280c7fff' - assert h3.h3_distance(h, h) == 0 + assert h3.grid_distance(h, h) == 0 - n = h3.hex_ring(h, 1).pop() - assert h3.h3_distance(h, n) == 1 + n = h3.grid_ring(h, 1).pop() + assert h3.grid_distance(h, n) == 1 - n = h3.hex_ring(h, 2).pop() - assert h3.h3_distance(h, n) == 2 + n = h3.grid_ring(h, 2).pop() + assert h3.grid_distance(h, n) == 2 def test_distance_error(): @@ -224,10 +225,10 @@ def test_distance_error(): h2 = '835804fffffffff' with pytest.raises(H3FailedError): - h3.h3_distance(h1, h2) + h3.grid_distance(h1, h2) -def test_compact(): +def test_compact_cells(): # lat/lngs for State of Maine maine = [ @@ -256,7 +257,7 @@ def test_compact(): res = 5 h_uncomp = h3.polyfill_polygon(maine, res) - h_comp = h3.compact(h_uncomp) + h_comp = h3.compact_cells(h_uncomp) expected = {'852b114ffffffff', '852b189bfffffff', '852b1163fffffff', '842ba9bffffffff', '842bad3ffffffff', '852ba9cffffffff', '842badbffffffff', '852b1e8bfffffff', '852a346ffffffff', '842b1e3ffffffff', '852b116ffffffff', '842b185ffffffff', '852b1bdbfffffff', '852bad47fffffff', '852ba9c3fffffff', '852b106bfffffff', '852a30d3fffffff', '842b1edffffffff', '852b12a7fffffff', '852b1027fffffff', '842baddffffffff', '852a349bfffffff', '852b1227fffffff', '852a3473fffffff', '852b117bfffffff', '842ba99ffffffff', '852a341bfffffff', '852ba9d3fffffff', '852b1067fffffff', '852a3463fffffff', '852baca7fffffff', '852b116bfffffff', '852b1c6bfffffff', '852a3493fffffff', '852ba9dbfffffff', '852b180bfffffff', '842bad7ffffffff', '852b1063fffffff', '842ba93ffffffff', '852a3693fffffff', '852ba977fffffff', '852b1e9bfffffff', '852bad53fffffff', '852b100ffffffff', '852b102bfffffff', '852a3413fffffff', '852ba8b7fffffff', '852bad43fffffff', '852b1c6ffffffff', '852a340bfffffff', '852b103bfffffff', '852b1813fffffff', '852b12affffffff', '842a34dffffffff', '852b1873fffffff', '852b106ffffffff', '852b115bfffffff', '852baca3fffffff', '852b114bfffffff', '852b1143fffffff', '852a348bfffffff', '852a30d7fffffff', '852b181bfffffff', '842a345ffffffff', '852b1e8ffffffff', '852b1883fffffff', '852b1147fffffff', '852a3483fffffff', '852b12a3fffffff', '852a346bfffffff', '852ba9d7fffffff', '842b18dffffffff', '852b188bfffffff', '852a36a7fffffff', '852bacb3fffffff', '852b187bfffffff', '852bacb7fffffff', '842b1ebffffffff', '842b1e5ffffffff', '852ba8a7fffffff', '842bad9ffffffff', '852a36b7fffffff', '852a347bfffffff', '832b13fffffffff', '852ba9c7fffffff', '832b1afffffffff', '842ba91ffffffff', '852bad57fffffff', '852ba8affffffff', '852b1803fffffff', '842b1e7ffffffff', '852bad4ffffffff', '852b102ffffffff', '852b1077fffffff', '852b1237fffffff', '852b1153fffffff', '852a3697fffffff', '852a36b3fffffff', '842bad1ffffffff', '842b1e1ffffffff', '852b186bfffffff', '852b1023fffffff'} # noqa @@ -265,16 +266,16 @@ def test_compact(): return h_uncomp, h_comp, res -def test_uncompact(): +def test_uncompact_cells(): - h_uncomp, h_comp, res = test_compact() + h_uncomp, h_comp, res = test_compact_cells() - out = h3.uncompact(h_comp, res) + out = h3.uncompact_cells(h_comp, res) assert out == h_uncomp -def test_num_hexagons(): +def test_get_num_cells(): expected = { 0: 122, 1: 842, @@ -284,14 +285,14 @@ def test_num_hexagons(): } out = { - k: h3.num_hexagons(k) + k: h3.get_num_cells(k) for k in expected } assert expected == out -def test_hex_area(): +def test_average_hexagon_area(): expected_in_km2 = { 0: 4357449.416078381, 1: 609788.441794133, @@ -301,14 +302,14 @@ def test_hex_area(): } out = { - k: h3.hex_area(k, unit='km^2') + k: h3.average_hexagon_area(k, unit='km^2') for k in expected_in_km2 } assert out == pytest.approx(expected_in_km2) -def test_hex_edge_length(): +def test_average_hexagon_edge_length(): expected_in_km = { 0: 1107.712591000, 1: 418.676005500, @@ -318,7 +319,7 @@ def test_hex_edge_length(): } out = { - res: h3.edge_length(res, unit='km') + res: h3.average_hexagon_edge_length(res, unit='km') for res in expected_in_km } @@ -329,29 +330,29 @@ def test_edge(): h1 = '8928308280fffff' h2 = '89283082873ffff' - assert not h3.h3_indexes_are_neighbors(h1, h1) - assert h3.h3_indexes_are_neighbors(h1, h2) + assert not h3.are_neighbor_cells(h1, h1) + assert h3.are_neighbor_cells(h1, h2) - e = h3.get_h3_unidirectional_edge(h1, h2) + e = h3.cells_to_directed_edge(h1, h2) assert e == '12928308280fffff' - assert h3.h3_unidirectional_edge_is_valid(e) + assert h3.is_valid_directed_edge(e) assert not h3.is_valid_cell(e) - assert h3.get_origin_h3_index_from_unidirectional_edge(e) == h1 - assert h3.get_destination_h3_index_from_unidirectional_edge(e) == h2 + assert h3.get_directed_edge_origin(e) == h1 + assert h3.get_directed_edge_destination(e) == h2 - assert h3.get_h3_indexes_from_unidirectional_edge(e) == (h1, h2) + assert h3.directed_edge_to_cells(e) == (h1, h2) -def test_edges_from_cell(): +def test_origin_to_directed_edges(): h = '8928308280fffff' - edges = h3.get_h3_unidirectional_edges_from_hexagon(h) + edges = h3.origin_to_directed_edges(h) destinations = { - h3.get_destination_h3_index_from_unidirectional_edge(e) + h3.get_directed_edge_destination(e) for e in edges } - neighbors = h3.hex_ring(h, 1) + neighbors = h3.grid_ring(h, 1) assert neighbors == destinations @@ -359,14 +360,14 @@ def test_edges_from_cell(): def test_edge_boundary(): h1 = '8928308280fffff' h2 = '89283082873ffff' - e = h3.get_h3_unidirectional_edge(h1, h2) + e = h3.cells_to_directed_edge(h1, h2) expected = ( (37.77688044840226, -122.41612835779266), (37.778385004930925, -122.41738797617619) ) - out = h3.get_h3_unidirectional_edge_boundary(e) + out = h3.directed_edge_to_boundary(e) assert out[0] == pytest.approx(expected[0]) assert out[1] == pytest.approx(expected[1]) @@ -376,83 +377,83 @@ def test_validation(): h = '8a28308280fffff' # invalid cell with pytest.raises(H3CellInvalidError): - h3.h3_get_base_cell(h) + h3.get_base_cell_number(h) with pytest.raises(H3CellInvalidError): - h3.h3_get_resolution(h) + h3.get_resolution(h) with pytest.raises(H3CellInvalidError): - h3.h3_to_parent(h, 9) + h3.cell_to_parent(h, 9) with pytest.raises(H3CellInvalidError): - h3.h3_distance(h, h) + h3.grid_distance(h, h) with pytest.raises(H3CellInvalidError): - h3.k_ring(h, 1) + h3.grid_disk(h, 1) with pytest.raises(H3CellInvalidError): - h3.hex_ring(h, 1) + h3.grid_ring(h, 1) with pytest.raises(H3CellInvalidError): - h3.h3_to_children(h, 11) + h3.cell_to_children(h, 11) with pytest.raises(H3CellInvalidError): - h3.compact({h}) + h3.compact_cells({h}) with pytest.raises(H3CellInvalidError): - h3.uncompact({h}, 10) + h3.uncompact_cells({h}, 10) def test_validation2(): h = '8928308280fffff' with pytest.raises(H3ResDomainError): - h3.h3_to_children(h, 17) + h3.cell_to_children(h, 17) - assert not h3.h3_indexes_are_neighbors(h, h) + assert not h3.are_neighbor_cells(h, h) def test_validation_geo(): h = '8a28308280fffff' # invalid cell with pytest.raises(H3CellInvalidError): - h3.h3_to_geo(h) + h3.cell_to_latlng(h) with pytest.raises(H3ResDomainError): - h3.geo_to_h3(0, 0, 17) + h3.latlng_to_cell(0, 0, 17) with pytest.raises(H3CellInvalidError): - h3.h3_to_geo_boundary(h) + h3.cell_to_boundary(h) # note: this won't raise an exception on bad input, but it does # *correctly* say that two invalid indexes are not neighbors - assert not h3.h3_indexes_are_neighbors(h, h) + assert not h3.are_neighbor_cells(h, h) def test_edges(): h = '8928308280fffff' with pytest.raises(H3NotNeighborsError): - h3.get_h3_unidirectional_edge(h, h) + h3.cells_to_directed_edge(h, h) - h2 = h3.hex_ring(h, 2).pop() + h2 = h3.grid_ring(h, 2).pop() with pytest.raises(H3NotNeighborsError): - h3.get_h3_unidirectional_edge(h, h2) + h3.cells_to_directed_edge(h, h2) e_bad = '14928308280ffff1' - assert not h3.h3_unidirectional_edge_is_valid(e_bad) + assert not h3.is_valid_directed_edge(e_bad) # note: won't raise an error on bad input - h3.get_origin_h3_index_from_unidirectional_edge(e_bad) - h3.get_destination_h3_index_from_unidirectional_edge(e_bad) - h3.get_h3_indexes_from_unidirectional_edge(e_bad) + h3.get_directed_edge_origin(e_bad) + h3.get_directed_edge_destination(e_bad) + h3.directed_edge_to_cells(e_bad) def test_line(): h1 = '8928308280fffff' h2 = '8928308287bffff' - out = h3.h3_line(h1, h2) + out = h3.grid_path_cells(h1, h2) expected = [ '8928308280fffff', @@ -479,9 +480,9 @@ def test_versions(): def test_str_int_convert(): s = '8928308280fffff' - i = h3.string_to_h3(s) + i = h3.string_to_int(s) - assert h3.h3_to_string(i) == s + assert h3.int_to_string(i) == s def test_hex2int_fail(): @@ -492,11 +493,11 @@ def test_hex2int_fail(): def test_edge_is_valid_fail(): e_invalid = {} - assert not h3.h3_unidirectional_edge_is_valid(e_invalid) + assert not h3.is_valid_directed_edge(e_invalid) def test_get_pentagons(): - out = h3.get_pentagon_indexes(0) + out = h3.get_pentagons(0) expected = { '8009fffffffffff', @@ -515,7 +516,7 @@ def test_get_pentagons(): assert out == expected - out = h3.get_pentagon_indexes(5) + out = h3.get_pentagons(5) expected = { '85080003fffffff', @@ -535,26 +536,26 @@ def test_get_pentagons(): assert out == expected for i in range(16): - assert len(h3.get_pentagon_indexes(i)) == 12 + assert len(h3.get_pentagons(i)) == 12 def test_uncompact_cell_input(): - # `uncompact` takes in a collection of cells, not a single cell. + # `uncompact_cells` takes in a collection of cells, not a single cell. # Since a python string is seen as a Iterable collection, # inputting a single cell string can raise weird errors. # Ensure we get a reasonably helpful answer with pytest.raises(H3CellInvalidError): - h3.uncompact('8001fffffffffff', 1) + h3.uncompact_cells('8001fffffffffff', 1) -def test_get_res0_indexes(): - out = h3.get_res0_indexes() +def test_get_res0_cells(): + out = h3.get_res0_cells() assert len(out) == 122 # subset - pentagons = h3.get_pentagon_indexes(0) + pentagons = h3.get_pentagons(0) assert pentagons < out # all valid @@ -562,7 +563,7 @@ def test_get_res0_indexes(): # resolution assert all(map( - lambda h: h3.h3_get_resolution(h) == 0, + lambda h: h3.get_resolution(h) == 0, out )) @@ -575,55 +576,55 @@ def test_get_res0_indexes(): assert sub < out -def test_get_faces(): +def test_get_icosahedron_faces(): h = '804dfffffffffff' expected = {2, 3, 7, 8, 12} - out = h3.h3_get_faces(h) + out = h3.get_icosahedron_faces(h) assert out == expected h = '80c1fffffffffff' expected = {13} - out = h3.h3_get_faces(h) + out = h3.get_icosahedron_faces(h) assert out == expected h = '80bbfffffffffff' expected = {16, 15} - out = h3.h3_get_faces(h) + out = h3.get_icosahedron_faces(h) assert out == expected def test_to_local_ij_error(): - h = h3.geo_to_h3(0, 0, 0) + h = h3.latlng_to_cell(0, 0, 0) # error if we cross a face - nb = h3.hex_ring(h, k=2) + nb = h3.grid_ring(h, k=2) # todo: should this be the E_TOO_FAR guy? with pytest.raises(H3FailedError): - [h3.experimental_h3_to_local_ij(h, p) for p in nb] + [h3.cell_to_local_ij(h, p) for p in nb] # should be fine if we do not cross a face - nb = h3.hex_ring(h, k=1) - out = {h3.experimental_h3_to_local_ij(h, p) for p in nb} + nb = h3.grid_ring(h, k=1) + out = {h3.cell_to_local_ij(h, p) for p in nb} expected = {(-1, 0), (0, -1), (0, 1), (1, 0), (1, 1)} assert out == expected def test_from_local_ij_error(): - h = h3.geo_to_h3(0, 0, 0) + h = h3.latlng_to_cell(0, 0, 0) baddies = [(1, -1), (-1, 1), (-1, -1)] for i, j in baddies: with pytest.raises(H3FailedError): - h3.experimental_local_ij_to_h3(h, i, j) + h3.local_ij_to_cell(h, i, j) # inverting output should give good data - nb = h3.hex_ring(h, k=1) - goodies = {h3.experimental_h3_to_local_ij(h, p) for p in nb} + nb = h3.grid_ring(h, k=1) + goodies = {h3.cell_to_local_ij(h, p) for p in nb} out = { - h3.experimental_local_ij_to_h3(h, i, j) + h3.local_ij_to_cell(h, i, j) for i, j in goodies } @@ -631,7 +632,7 @@ def test_from_local_ij_error(): def test_to_local_ij_self(): - h = h3.geo_to_h3(0, 0, 9) - out = h3.experimental_h3_to_local_ij(h, h) + h = h3.latlng_to_cell(0, 0, 9) + out = h3.cell_to_local_ij(h, h) assert out == (-858, -2766) diff --git a/tests/test_collection_inputs.py b/tests/test_collection_inputs.py index aa09c4fd..92a8ba54 100644 --- a/tests/test_collection_inputs.py +++ b/tests/test_collection_inputs.py @@ -22,15 +22,15 @@ def test_set(): h = 614553222213795839 - assert basic_int.compact(ints) == {h} + assert basic_int.compact_cells(ints) == {h} with pytest.raises(TypeError): # numpy can't convert from a set - numpy_int.compact(ints) + numpy_int.compact_cells(ints) with pytest.raises(TypeError): # set isn't a memoryview - memview_int.compact(ints) + memview_int.compact_cells(ints) def test_list(): @@ -46,19 +46,19 @@ def test_list(): h = 614553222213795839 - assert basic_int.compact(ints) == {h} + assert basic_int.compact_cells(ints) == {h} # numpy can convert from a list OK # (numpy knows to convert it to uint64) - assert numpy_int.compact(ints) == np.array([h], dtype='uint64') + assert numpy_int.compact_cells(ints) == np.array([h], dtype='uint64') # little weird that numpy comparisons don't consider dtype - assert numpy_int.compact(ints) == np.array([h]) - assert not numpy_int.compact(ints).dtype == np.array([h]).dtype + assert numpy_int.compact_cells(ints) == np.array([h]) + assert not numpy_int.compact_cells(ints).dtype == np.array([h]).dtype with pytest.raises(TypeError): # list isn't a memoryview - memview_int.compact(ints) + memview_int.compact_cells(ints) def test_np_array(): @@ -74,12 +74,12 @@ def test_np_array(): h = 614553222213795839 - assert basic_int.compact(ints) == {h} + assert basic_int.compact_cells(ints) == {h} - assert numpy_int.compact(ints) == np.array([h], dtype='uint64') - assert numpy_int.compact(ints).dtype == np.dtype('uint64') + assert numpy_int.compact_cells(ints) == np.array([h], dtype='uint64') + assert numpy_int.compact_cells(ints).dtype == np.dtype('uint64') - out = memview_int.compact(ints) + out = memview_int.compact_cells(ints) assert len(out) == 1 assert out[0] == h @@ -99,15 +99,15 @@ def test_list_to_array(): h = 614553222213795839 - assert basic_int.compact(ints) == {h} - assert numpy_int.compact(ints) == np.array([h], dtype='uint64') + assert basic_int.compact_cells(ints) == {h} + assert numpy_int.compact_cells(ints) == np.array([h], dtype='uint64') with pytest.raises(ValueError): # Without the explicit dtype given above, the array # assumes it has *signed* integers # The `memview_int` interface requires a dtype match # with uint64. - memview_int.compact(ints) + memview_int.compact_cells(ints) def test_iterator(): @@ -128,14 +128,14 @@ def foo(): h = 614553222213795839 ints = foo() - assert basic_int.compact(ints) == {h} + assert basic_int.compact_cells(ints) == {h} ints = foo() with pytest.raises(TypeError): # numpy can't create an array from an iterator - numpy_int.compact(ints) + numpy_int.compact_cells(ints) ints = foo() with pytest.raises(TypeError): # requires a bytes-like input - memview_int.compact(ints) + memview_int.compact_cells(ints) diff --git a/tests/test_cython.py b/tests/test_cython.py index 30566b18..89aa0646 100644 --- a/tests/test_cython.py +++ b/tests/test_cython.py @@ -3,15 +3,15 @@ # Avoid checking for import-error here because cython_example may not have # been compiled yet. try: - from .cython_example import geo_to_h3_vect # pylint: disable=import-error + from .cython_example import latlng_to_cell_vect # pylint: disable=import-error except ImportError: - geo_to_h3_vect = None + latlng_to_cell_vect = None np.random.seed(0) def test_cython_api(): - if geo_to_h3_vect is None: + if latlng_to_cell_vect is None: print("Not running Cython test because cython example was not compiled") return @@ -23,6 +23,6 @@ def test_cython_api(): lats = np.array(lats, dtype=np.float64) lngs = np.array(lngs, dtype=np.float64) out = np.zeros(len(lats), dtype="uint64") - geo_to_h3_vect(lats, lngs, res, out) + latlng_to_cell_vect(lats, lngs, res, out) assert out[0] == 617284541015654399 diff --git a/tests/test_h3.py b/tests/test_h3.py index 33386064..3cf5d8f3 100644 --- a/tests/test_h3.py +++ b/tests/test_h3.py @@ -19,38 +19,38 @@ def test_is_valid_cell(): assert not h3.is_valid_cell('5004295803a88') for res in range(16): - assert h3.is_valid_cell(h3.geo_to_h3(37, -122, res)) + assert h3.is_valid_cell(h3.latlng_to_cell(37, -122, res)) -def test_geo_to_h3(): - assert h3.geo_to_h3(37.3615593, -122.0553238, 5) == '85283473fffffff' +def test_latlng_to_cell(): + assert h3.latlng_to_cell(37.3615593, -122.0553238, 5) == '85283473fffffff' -def test_h3_get_resolution(): +def test_get_resolution(): for res in range(16): - h = h3.geo_to_h3(37.3615593, -122.0553238, res) - assert h3.h3_get_resolution(h) == res + h = h3.latlng_to_cell(37.3615593, -122.0553238, res) + assert h3.get_resolution(h) == res -def test_silly_geo_to_h3(): +def test_silly_latlng_to_cell(): lat, lng = 37.3615593, -122.0553238 expected0 = '85283473fffffff' - out0 = h3.geo_to_h3(lat, lng, 5) + out0 = h3.latlng_to_cell(lat, lng, 5) assert out0 == expected0 - out1 = h3.geo_to_h3(lat + 180.0, lng + 360.0, 5) + out1 = h3.latlng_to_cell(lat + 180.0, lng + 360.0, 5) expected1 = '85ca2d53fffffff' assert out1 == expected1 -def test_h3_to_geo(): - latlng = h3.h3_to_geo('85283473fffffff') +def test_cell_to_latlng(): + latlng = h3.cell_to_latlng('85283473fffffff') assert latlng == approx((37.34579337536848, -121.97637597255124)) -def test_h3_to_geo_boundary(): - out = h3.h3_to_geo_boundary('85283473fffffff') +def test_cell_to_boundary(): + out = h3.cell_to_boundary('85283473fffffff') expected = [ [37.271355866731895, -121.91508032705622], @@ -67,8 +67,8 @@ def test_h3_to_geo_boundary(): assert o == approx(e) -def test_h3_to_geo_boundary_geo_json(): - out = h3.h3_to_geo_boundary('85283473fffffff', True) +def test_cell_to_boundary_geo_json(): + out = h3.cell_to_boundary('85283473fffffff', True) expected = [ [-121.91508032705622, 37.271355866731895], @@ -86,9 +86,9 @@ def test_h3_to_geo_boundary_geo_json(): assert o == approx(e) -def test_k_ring(): +def test_grid_disk(): h = '8928308280fffff' - out = h3.k_ring(h, 1) + out = h3.grid_disk(h, 1) assert len(out) == 1 + 6 @@ -105,9 +105,9 @@ def test_k_ring(): assert out == expected -def test_k_ring2(): +def test_grid_disk2(): h = '8928308280fffff' - out = h3.k_ring(h, 2) + out = h3.grid_disk(h, 2) assert len(out) == 1 + 6 + 12 @@ -136,9 +136,9 @@ def test_k_ring2(): assert out == expected -def test_k_ring_pentagon(): +def test_grid_disk_pentagon(): h = '821c07fffffffff' # a pentagon cell - out = h3.k_ring(h, 1) + out = h3.grid_disk(h, 1) assert len(out) == 1 + 5 @@ -349,18 +349,18 @@ def test_polyfill_null_island(): assert len(out) > 10 -def test_h3_set_to_multi_polygon_empty(): - out = h3.h3_set_to_multi_polygon([]) +def test_cells_to_multi_polygon_empty(): + out = h3.cells_to_multi_polygon([]) assert out == [] -def test_h3_set_to_multi_polygon_single(): +def test_cells_to_multi_polygon_single(): h = '89283082837ffff' hexes = {h} # multi_polygon - mp = h3.h3_set_to_multi_polygon(hexes) - vertices = h3.h3_to_geo_boundary(h) + mp = h3.cells_to_multi_polygon(hexes) + vertices = h3.cell_to_boundary(h) # We shift the expected circular list so that it starts from # multi_polygon[0][0][0], since output starting from any vertex @@ -382,10 +382,10 @@ def test_h3_set_to_multi_polygon_single(): assert mp == expected -def test_h3_set_to_multi_polygon_single_geo_json(): +def test_cells_to_multi_polygon_single_geo_json(): hexes = ['89283082837ffff'] - mp = h3.h3_set_to_multi_polygon(hexes, True) - vertices = h3.h3_to_geo_boundary(hexes[0], True) + mp = h3.cells_to_multi_polygon(hexes, True) + vertices = h3.cell_to_boundary(hexes[0], True) # We shift the expected circular list so that it starts from # multi_polygon[0][0][0], since output starting from any vertex @@ -426,14 +426,14 @@ def test_h3_set_to_multi_polygon_single_geo_json(): assert mp == expected -def test_h3_set_to_multi_polygon_contiguous(): +def test_cells_to_multi_polygon_contiguous(): # the second hexagon shares v0 and v1 with the first hexes = ['89283082837ffff', '89283082833ffff'] # multi_polygon - mp = h3.h3_set_to_multi_polygon(hexes) - vertices0 = h3.h3_to_geo_boundary(hexes[0]) - vertices1 = h3.h3_to_geo_boundary(hexes[1]) + mp = h3.cells_to_multi_polygon(hexes) + vertices0 = h3.cell_to_boundary(hexes[0]) + vertices1 = h3.cell_to_boundary(hexes[1]) # We shift the expected circular list so that it starts from # multi_polygon[0][0][0], since output starting from any vertex @@ -463,11 +463,11 @@ def test_h3_set_to_multi_polygon_contiguous(): assert mp == expected -def test_h3_set_to_multi_polygon_non_contiguous(): +def test_cells_to_multi_polygon_non_contiguous(): # the second hexagon does not touch the first hexes = {'89283082837ffff', '8928308280fffff'} # multi_polygon - mp = h3.h3_set_to_multi_polygon(hexes) + mp = h3.cells_to_multi_polygon(hexes) assert len(mp) == 2 # polygon count matches expected assert len(mp[0]) == 1 # loop count matches expected @@ -475,13 +475,13 @@ def test_h3_set_to_multi_polygon_non_contiguous(): assert len(mp[1][0]) == 6 # coord count 2 matches expected -def test_h3_set_to_multi_polygon_hole(): +def test_cells_to_multi_polygon_hole(): # Six hexagons in a ring around a hole hexes = [ '892830828c7ffff', '892830828d7ffff', '8928308289bffff', '89283082813ffff', '8928308288fffff', '89283082883ffff', ] - mp = h3.h3_set_to_multi_polygon(hexes) + mp = h3.cells_to_multi_polygon(hexes) assert len(mp) == 1 # polygon count matches expected assert len(mp[0]) == 2 # loop count matches expected @@ -489,11 +489,11 @@ def test_h3_set_to_multi_polygon_hole(): assert len(mp[0][1]) == 6 # inner coord count matches expected -def test_h3_set_to_multi_polygon_2k_ring(): +def test_cells_to_multi_polygon_2grid_disk(): h = '8930062838bffff' - hexes = h3.k_ring(h, 2) + hexes = h3.grid_disk(h, 2) # multi_polygon - mp = h3.h3_set_to_multi_polygon(hexes) + mp = h3.cells_to_multi_polygon(hexes) assert len(mp) == 1 # polygon count matches expected assert len(mp[0]) == 1 # loop count matches expected @@ -509,22 +509,22 @@ def test_h3_set_to_multi_polygon_2k_ring(): '893006283c7ffff' } - mp2 = h3.h3_set_to_multi_polygon(hexes2) + mp2 = h3.cells_to_multi_polygon(hexes2) assert len(mp2) == 1 # polygon count matches expected assert len(mp2[0]) == 1 # loop count matches expected assert len(mp2[0][0]) == 6 * (2 * 2 + 1) # coord count matches expected - hexes3 = list(h3.k_ring(h, 6)) + hexes3 = list(h3.grid_disk(h, 6)) hexes3.sort() - mp3 = h3.h3_set_to_multi_polygon(hexes3) + mp3 = h3.cells_to_multi_polygon(hexes3) assert len(mp3[0]) == 1 # loop count matches expected -def test_hex_ring(): +def test_grid_ring(): h = '8928308280fffff' - out = h3.hex_ring(h, 1) + out = h3.grid_ring(h, 1) expected = { '8928308280bffff', '89283082807ffff', @@ -535,12 +535,12 @@ def test_hex_ring(): } assert out == expected - assert out == h3.k_ring(h, 1) - h3.k_ring(h, 0) + assert out == h3.grid_disk(h, 1) - h3.grid_disk(h, 0) -def test_hex_ring2(): +def test_grid_ring2(): h = '8928308280fffff' - out = h3.hex_ring(h, 2) + out = h3.grid_ring(h, 2) expected = { '89283082813ffff', @@ -558,12 +558,12 @@ def test_hex_ring2(): } assert out == expected - assert out == h3.k_ring(h, 2) - h3.k_ring(h, 1) + assert out == h3.grid_disk(h, 2) - h3.grid_disk(h, 1) -def test_hex_ring_pentagon(): +def test_grid_ring_pentagon(): h = '821c07fffffffff' - out = h3.hex_ring(h, 1) + out = h3.grid_ring(h, 1) expected = { '821c17fffffffff', @@ -576,7 +576,7 @@ def test_hex_ring_pentagon(): assert out == expected -def test_compact_and_uncompact(): +def test_compact_and_uncompact_cells(): geo = { 'type': 'Polygon', 'coordinates': [ @@ -593,264 +593,157 @@ def test_compact_and_uncompact(): hexes = h3.polyfill(geo, 9) - compact_hexes = h3.compact(hexes) - assert len(compact_hexes) == 209 + compact_cells = h3.compact_cells(hexes) + assert len(compact_cells) == 209 - uncompact_hexes = h3.uncompact(compact_hexes, 9) - assert len(uncompact_hexes) == 1253 + uncompact_cells = h3.uncompact_cells(compact_cells, 9) + assert len(uncompact_cells) == 1253 -def test_compact_and_uncompact_nothing(): - assert h3.compact([]) == set() - assert h3.uncompact([], 9) == set() +def test_compact_cells_and_uncompact_cells_nothing(): + assert h3.compact_cells([]) == set() + assert h3.uncompact_cells([], 9) == set() -def test_uncompact_error(): - hexagons = [h3.geo_to_h3(37, -122, 10)] +def test_uncompact_cells_error(): + hexagons = [h3.latlng_to_cell(37, -122, 10)] with pytest.raises(Exception): - h3.uncompact(hexagons, 5) + h3.uncompact_cells(hexagons, 5) -def test_compact_malformed_input(): +def test_compact_cells_malformed_input(): hexes = ['89283082813ffff'] * 13 with pytest.raises(Exception): - h3.compact(hexes) + h3.compact_cells(hexes) -def test_h3_to_parent(): +def test_cell_to_parent(): h = '89283082813ffff' - assert h3.h3_to_parent(h, 8) == '8828308281fffff' + assert h3.cell_to_parent(h, 8) == '8828308281fffff' -def test_h3_to_children(): +def test_cell_to_children(): h = '8828308281fffff' - children = h3.h3_to_children(h, 9) + children = h3.cell_to_children(h, 9) assert len(children) == 7 -def test_hex_range_distances_pentagon(): - - h = '821c07fffffffff' - out = h3.hex_range_distances(h, 1) - - expected = [ - {h}, - { - '821c17fffffffff', - '821c1ffffffffff', - '821c27fffffffff', - '821c2ffffffffff', - '821c37fffffffff', - } - ] - - assert out == expected - - -def test_hex_range_distances(): - h = '8928308280fffff' - - # should consist of `h` and it's 5 neighbors - out = h3.hex_range_distances(h, 1) - - assert [len(x) for x in out] == [1, 6] - - expected = [ - {h}, - { - '8928308280bffff', - '89283082807ffff', - '89283082877ffff', - '89283082803ffff', - '89283082873ffff', - '8928308283bffff', - } - ] - - assert out == expected - - out = h3.hex_range_distances('870800003ffffff', 2) - - assert [len(x) for x in out] == [1, 6, 11] - - -def test_hex_ranges(): - h = '8928308280fffff' - out = h3.hex_ranges([h], 1) - - assert set(out.keys()) == {h} - - expected = [ - {h}, - { - '8928308280bffff', - '89283082807ffff', - '89283082877ffff', - '89283082803ffff', - '89283082873ffff', - '8928308283bffff', - } - ] - - assert out[h] == expected - - -def test_hex_ranges_pentagon(): - h = '821c07fffffffff' - out = h3.hex_ranges([h], 1) - - expected = { - h: [ - {h}, - { - '821c17fffffffff', - '821c1ffffffffff', - '821c27fffffffff', - '821c2ffffffffff', - '821c37fffffffff' - } - ] - } - - assert out == expected - - -def test_many_hex_ranges(): - hexes = h3.k_ring('8928308280fffff', 2) - out = h3.hex_ranges(hexes, 2) - - assert len(out) == 19 - - hexes = out['8928308280fffff'] - assert [len(x) for x in hexes] == [1, 6, 12] - - -def test_many_hex_ranges2(): - hexes = h3.k_ring('8928308280fffff', 5) - out = h3.hex_ranges(hexes, 5) - assert len(out) == 91 - - hexes = out['8928308280fffff'] - - assert [len(x) for x in hexes] == [1, 6, 12, 18, 24, 30] - - -def test_hex_area(): +def test_average_hexagon_area(): for i in range(0, 15): - assert isinstance(h3.hex_area(i), float) - assert isinstance(h3.hex_area(i, 'm^2'), float) + assert isinstance(h3.average_hexagon_area(i), float) + assert isinstance(h3.average_hexagon_area(i, 'm^2'), float) with pytest.raises(ValueError): - h3.hex_area(5, 'ft^2') + h3.average_hexagon_area(5, 'ft^2') -def test_edge_length(): +def test_average_hexagon_edge_length(): for i in range(0, 15): - assert isinstance(h3.edge_length(i), float) - assert isinstance(h3.edge_length(i, 'm'), float) + assert isinstance(h3.average_hexagon_edge_length(i), float) + assert isinstance(h3.average_hexagon_edge_length(i, 'm'), float) with pytest.raises(ValueError): - h3.edge_length(5, 'ft') + h3.average_hexagon_edge_length(5, 'ft') -def test_num_hexagons(): +def test_get_num_cells(): h0 = 122 - assert h3.num_hexagons(0) == h0 + assert h3.get_num_cells(0) == h0 for i in range(0, 15): - n = h3.num_hexagons(i) * 1.0 / h0 + n = h3.get_num_cells(i) * 1.0 / h0 assert 6**i <= n <= 7**i -def test_h3_get_base_cell(): - assert h3.h3_get_base_cell('8928308280fffff') == 20 +def test_get_base_cell_number(): + assert h3.get_base_cell_number('8928308280fffff') == 20 -def test_h3_is_res_class_III(): - assert h3.h3_is_res_class_III('8928308280fffff') - assert not h3.h3_is_res_class_III('8828308280fffff') +def test_is_res_class_III(): + assert h3.is_res_class_III('8928308280fffff') + assert not h3.is_res_class_III('8828308280fffff') -def test_h3_is_pentagon(): - assert h3.h3_is_pentagon('821c07fffffffff') - assert not h3.h3_is_pentagon('8928308280fffff') +def test_is_pentagon(): + assert h3.is_pentagon('821c07fffffffff') + assert not h3.is_pentagon('8928308280fffff') -def test_h3_indexes_are_neighbors(): - assert h3.h3_indexes_are_neighbors('8928308280fffff', '8928308280bffff') +def test_are_neighbor_cells(): + assert h3.are_neighbor_cells('8928308280fffff', '8928308280bffff') - assert not h3.h3_indexes_are_neighbors('821c07fffffffff', '8928308280fffff') + assert not h3.are_neighbor_cells('821c07fffffffff', '8928308280fffff') -def test_get_h3_unidirectional_edge(): - out = h3.get_h3_unidirectional_edge('8928308280fffff', '8928308280bffff') - assert h3.h3_unidirectional_edge_is_valid(out) +def test_cells_to_directed_edge(): + out = h3.cells_to_directed_edge('8928308280fffff', '8928308280bffff') + assert h3.is_valid_directed_edge(out) with pytest.raises(h3.H3NotNeighborsError): - h3.get_h3_unidirectional_edge('821c07fffffffff', '8928308280fffff') + h3.cells_to_directed_edge('821c07fffffffff', '8928308280fffff') -def test_h3_unidirectional_edge_is_valid(): - assert not h3.h3_unidirectional_edge_is_valid('8928308280fffff') - assert h3.h3_unidirectional_edge_is_valid('11928308280fffff') +def test_is_valid_directed_edge(): + assert not h3.is_valid_directed_edge('8928308280fffff') + assert h3.is_valid_directed_edge('11928308280fffff') -def test_get_origin_h3_index_from_unidirectional_edge(): - out = h3.get_origin_h3_index_from_unidirectional_edge('11928308280fffff') +def test_get_directed_edge_origin(): + out = h3.get_directed_edge_origin('11928308280fffff') assert out == '8928308280fffff' -def test_get_destination_h3_index_from_unidirectional_edge(): +def test_get_directed_edge_destination(): h = '11928308280fffff' - out = h3.get_destination_h3_index_from_unidirectional_edge(h) + out = h3.get_directed_edge_destination(h) assert out == '8928308283bffff' -def test_get_h3_indexes_from_unidirectional_edge(): - e = h3.get_h3_indexes_from_unidirectional_edge('11928308280fffff') +def test_directed_edge_to_cells(): + e = h3.directed_edge_to_cells('11928308280fffff') assert e == ('8928308280fffff', '8928308283bffff') -def test_get_h3_unidirectional_edges_from_hexagon(): - h3_uni_edges = h3.get_h3_unidirectional_edges_from_hexagon( +def test_origin_to_directed_edges(): + h3_uni_edges = h3.origin_to_directed_edges( '8928308280fffff' ) assert len(h3_uni_edges) == 6 - h3_uni_edge_pentagon = h3.get_h3_unidirectional_edges_from_hexagon( + h3_uni_edge_pentagon = h3.origin_to_directed_edges( '821c07fffffffff' ) assert len(h3_uni_edge_pentagon) == 5 -def test_get_h3_unidirectional_edge_boundary(): +def test_directed_edge_to_boundary(): e = '11928308280fffff' - boundary = h3.get_h3_unidirectional_edge_boundary(e) + boundary = h3.directed_edge_to_boundary(e) assert len(boundary) == 2 - boundary_geo_json = h3.get_h3_unidirectional_edge_boundary(e, True) + boundary_geo_json = h3.directed_edge_to_boundary(e, True) assert len(boundary_geo_json) == 3 -def test_h3_distance(): +def test_grid_distance(): h = '89283082993ffff' - assert 0 == h3.h3_distance(h, h) - assert 1 == h3.h3_distance(h, '8928308299bffff') - assert 5 == h3.h3_distance(h, '89283082827ffff') + assert 0 == h3.grid_distance(h, h) + assert 1 == h3.grid_distance(h, '8928308299bffff') + assert 5 == h3.grid_distance(h, '89283082827ffff') -def test_h3_line(): +def test_grid_path_cells(): h1 = '8a2a84730587fff' h2 = '8a2a8471414ffff' - out = h3.h3_line(h1, h2) + out = h3.grid_path_cells(h1, h2) expected = [ h1, @@ -889,4 +782,4 @@ def test_h3_line(): assert out == expected with pytest.raises(h3.H3ResMismatchError): - h3.h3_line(h1, '8001fffffffffff') + h3.grid_path_cells(h1, '8001fffffffffff') diff --git a/tests/test_length_area.py b/tests/test_length_area.py index 8c15f136..8851a4b4 100644 --- a/tests/test_length_area.py +++ b/tests/test_length_area.py @@ -13,10 +13,10 @@ def approx2(a, b): def cell_perimiter1(h, unit='km'): - edges = h3.get_h3_unidirectional_edges_from_hexagon(h) + edges = h3.origin_to_directed_edges(h) dists = [ - h3.exact_edge_length(e, unit=unit) + h3.edge_length(e, unit=unit) for e in edges ] @@ -26,12 +26,12 @@ def cell_perimiter1(h, unit='km'): def cell_perimiter2(h, unit='km'): - verts = h3.h3_to_geo_boundary(h) + verts = h3.cell_to_boundary(h) N = len(verts) verts += (verts[0],) dists = [ - h3.point_dist(verts[i], verts[i + 1], unit=unit) + h3.great_circle_distance(verts[i], verts[i + 1], unit=unit) for i in range(N) ] @@ -61,7 +61,7 @@ def test_areas_at_00(): ] out = [ - h3.cell_area(h3.geo_to_h3(0, 0, r), unit='km^2') + h3.cell_area(h3.latlng_to_cell(0, 0, r), unit='km^2') for r in range(16) ] @@ -87,7 +87,7 @@ def test_areas_at_00(): ] out = [ - h3.cell_area(h3.geo_to_h3(0, 0, r), unit='rads^2') + h3.cell_area(h3.latlng_to_cell(0, 0, r), unit='rads^2') for r in range(16) ] @@ -99,40 +99,41 @@ def test_bad_units(): e = '139754e64993ffff' assert h3.is_valid_cell(h) - assert h3.h3_unidirectional_edge_is_valid(e) + assert h3.is_valid_directed_edge(e) with pytest.raises(ValueError): h3.cell_area(h, unit='foot-pounds') with pytest.raises(ValueError): - h3.exact_edge_length(e, unit='foot-pounds') + h3.edge_length(e, unit='foot-pounds') with pytest.raises(ValueError): - h3.point_dist((0, 0), (0, 0), unit='foot-pounds') + h3.great_circle_distance((0, 0), (0, 0), unit='foot-pounds') -def test_point_dist(): +def test_great_circle_distance(): lyon = (45.7597, 4.8422) # (lat, lon) paris = (48.8567, 2.3508) - d = h3.point_dist(lyon, paris, unit='rads') + d = h3.great_circle_distance(lyon, paris, unit='rads') assert d == pytest.approx(0.0615628186794217) - d = h3.point_dist(lyon, paris, unit='m') + d = h3.great_circle_distance(lyon, paris, unit='m') assert d == pytest.approx(392217.1598841777) - d = h3.point_dist(lyon, paris, unit='km') + d = h3.great_circle_distance(lyon, paris, unit='km') assert d == pytest.approx(392.21715988417765) # test that 'km' is the default unit - assert h3.point_dist(lyon, paris, unit='km') == h3.point_dist(lyon, paris) + dist = h3.great_circle_distance + assert dist(lyon, paris, unit='km') == dist(lyon, paris) def test_cell_perimiter_calculations(): resolutions = [0, 1] for r in resolutions: - cells = h3.uncompact(h3.get_res0_indexes(), r) + cells = h3.uncompact_cells(h3.get_res0_cells(), r) for h in cells: for unit in ['rads', 'm', 'km']: v1 = cell_perimiter1(h, unit) diff --git a/tests/test_memview_int.py b/tests/test_memview_int.py index 9923b750..3cd2c450 100644 --- a/tests/test_memview_int.py +++ b/tests/test_memview_int.py @@ -2,15 +2,16 @@ def test1(): - assert h3.geo_to_h3(37.7752702151959, -122.418307270836, 9) == 617700169958293503 + lat, lng = 37.7752702151959, -122.418307270836 + assert h3.latlng_to_cell(lat, lng, 9) == 617700169958293503 def test_line(): h1 = '8928308280fffff' h2 = '8928308287bffff' - h1, h2 = h3.string_to_h3(h1), h3.string_to_h3(h2) + h1, h2 = h3.string_to_int(h1), h3.string_to_int(h2) - out = h3.h3_line(h1, h2) + out = h3.grid_path_cells(h1, h2) # todo: are we outputting `memoryviewslice`? should we just output a memoryview? assert 'memoryview' in str(type(out)) @@ -24,18 +25,18 @@ def test_line(): assert list(out) == expected -def test_get_faces(): +def test_get_icosahedron_faces(): h = 577832942814887935 expected = {2, 3, 7, 8, 12} - out = h3.h3_get_faces(h) + out = h3.get_icosahedron_faces(h) assert out == expected h = 579873636396040191 expected = {13} - out = h3.h3_get_faces(h) + out = h3.get_icosahedron_faces(h) assert out == expected h = 579768083279773695 expected = {16, 15} - out = h3.h3_get_faces(h) + out = h3.get_icosahedron_faces(h) assert out == expected diff --git a/tests/test_numpy_int.py b/tests/test_numpy_int.py index 8169772c..5ebcd44a 100644 --- a/tests/test_numpy_int.py +++ b/tests/test_numpy_int.py @@ -3,7 +3,8 @@ def test1(): - assert h3.geo_to_h3(37.7752702151959, -122.418307270836, 9) == 617700169958293503 + lat, lng = 37.7752702151959, -122.418307270836, + assert h3.latlng_to_cell(lat, lng, 9) == 617700169958293503 def test5(): @@ -17,31 +18,31 @@ def test5(): 617700169965109247, } - out = h3.k_ring(617700169958293503, 1) + out = h3.grid_disk(617700169958293503, 1) assert isinstance(out, np.ndarray) assert set(out) == expected -def test_compact(): +def test_compact_cells(): h = 617700169958293503 - hexes = h3.h3_to_children(h) + hexes = h3.cell_to_children(h) assert isinstance(hexes, np.ndarray) - assert set(h3.compact(hexes)) == {h} + assert set(h3.compact_cells(hexes)) == {h} -def test_get_faces(): +def test_get_icosahedron_faces(): h = 577832942814887935 expected = {2, 3, 7, 8, 12} - out = h3.h3_get_faces(h) + out = h3.get_icosahedron_faces(h) assert out == expected h = 579873636396040191 expected = {13} - out = h3.h3_get_faces(h) + out = h3.get_icosahedron_faces(h) assert out == expected h = 579768083279773695 expected = {16, 15} - out = h3.h3_get_faces(h) + out = h3.get_icosahedron_faces(h) assert out == expected diff --git a/tests/test_to_multipoly.py b/tests/test_to_multipoly.py index 0b899b93..3de1360d 100644 --- a/tests/test_to_multipoly.py +++ b/tests/test_to_multipoly.py @@ -1,11 +1,11 @@ import h3 -def test_h3_set_to_multi_polygon(): +def test_cells_to_multi_polygon(): h = '8928308280fffff' - hexes = h3.k_ring(h, 1) + hexes = h3.grid_disk(h, 1) - mpoly = h3.h3_set_to_multi_polygon(hexes) + mpoly = h3.cells_to_multi_polygon(hexes) out = h3.polyfill_polygon(mpoly[0][0], 9, holes=None, lnglat_order=False) @@ -14,14 +14,14 @@ def test_h3_set_to_multi_polygon(): def test_2_polys(): h = '8928308280fffff' - hexes = h3.hex_ring(h, 2) + hexes = h3.grid_ring(h, 2) hexes = hexes | {h} # hexes should be a center hex, and the 2-ring around it # (with the 1-ring being absent) out = [ h3.polyfill_polygon(poly[0], 9, holes=poly[1:], lnglat_order=False) - for poly in h3.h3_set_to_multi_polygon(hexes, geo_json=False) + for poly in h3.cells_to_multi_polygon(hexes, geo_json=False) ] assert set.union(*out) == hexes @@ -29,13 +29,13 @@ def test_2_polys(): def test_2_polys_json(): h = '8928308280fffff' - hexes = h3.hex_ring(h, 2) + hexes = h3.grid_ring(h, 2) hexes = hexes | {h} # hexes should be a center hex, and the 2-ring around it # (with the 1-ring being absent) # not deterministic which poly is first.. - poly1, poly2 = h3.h3_set_to_multi_polygon(hexes, geo_json=True) + poly1, poly2 = h3.cells_to_multi_polygon(hexes, geo_json=True) assert {len(poly1), len(poly2)} == {1, 2} @@ -46,13 +46,13 @@ def test_2_polys_json(): def test_2_polys_not_json(): h = '8928308280fffff' - hexes = h3.hex_ring(h, 2) + hexes = h3.grid_ring(h, 2) hexes = hexes | {h} # hexes should be a center hex, and the 2-ring around it # (with the 1-ring being absent) # not deterministic which poly is first.. - poly1, poly2 = h3.h3_set_to_multi_polygon(hexes, geo_json=False) + poly1, poly2 = h3.cells_to_multi_polygon(hexes, geo_json=False) assert {len(poly1), len(poly2)} == {1, 2}