Skip to content

Commit

Permalink
bug fix 0.3.1 with Z7_STRING COARSE_CELLS and the grid_cell_centroids…
Browse files Browse the repository at this point in the history
…_from_cellids/grid_cell_polygons_from_cellids functions
  • Loading branch information
allixender committed Nov 19, 2024
1 parent bbdd391 commit d8e399d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 29 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

GNU AFFERO GENERAL PUBLIC LICENSE

[DGGRID](https://www.discreteglobalgrids.org/software/) is a free software program for creating and manipulating Discrete Global Grids created and maintained by Kevin Sahr. DGGRID version 8.1b was released 12. January 2024
[DGGRID](https://www.discreteglobalgrids.org/software/) is a free software program for creating and manipulating Discrete Global Grids created and maintained by Kevin Sahr. DGGRID version 8.34 was released 13. November 2024

- [DGGRID Version 8.1b on GitHub](https://github.com/sahrk/DGGRID)
- [DGGRID Version 8.3 on GitHub](https://github.com/sahrk/DGGRID)
- [DGGRID User Manual](https://github.com/sahrk/DGGRID/blob/d08e10d761f7bedd72a253ab1057458f339de51e/dggridManualV81b.pdf)

You need the ddgrid tool compiled available on the system.
Expand All @@ -19,6 +19,7 @@ Besides some lowlevel access influence the dggrid operations' metafile creation,
- grid_cell_polygons_from_cellids(): geometry_from_cellid for dggs at resolution (from id list)
- grid_cellids_for_extent(): get_all_indexes/cell_ids for dggs at resolution (clip or world)
- cells_for_geo_points(): poly_outline for point/centre at resolution
- address_transform(): conversion betwenn cell_id address types, like SEQNUM, Z7, or Q2DI


```python
Expand Down Expand Up @@ -99,7 +100,7 @@ After some unsuccessful trials with ctypes, cython, CFFI, pybind11 or cppyy (rat
## Bundling for different operating systems

Having to compile DGGRID for Windows can be a bit challenging. We are
working on an updated conda package. Currently DGGRID v7.8 is available on conda-forge:
working on an updated conda package. Currently DGGRID v8.3 is available on conda-forge:

[![Latest version on conda-forge](https://anaconda.org/conda-forge/dggrid/badges/version.svg)](https://anaconda.org/conda-forge/dggrid)

Expand Down
16 changes: 8 additions & 8 deletions dggrid4py/dggrid_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,16 +1170,16 @@ def grid_cell_polygons_from_cellids(self, cell_id_list, dggs_type, resolution, m
if self.debug is True:
print(f"cannot switch address types on the fly here: {input_address_type} != {output_address_type}")

seq_df['cell_exists'] = True
# seq_df['cell_exists'] = True
if output_address_type in ['SEQNUM']:
seq_df[input_address_type] = seq_df[input_address_type].astype(np.int64)

seq_df.set_index(input_address_type, inplace=True)
# seq_df.set_index(input_address_type, inplace=True)
name_col = 'name' if 'name' in gdf.columns else 'Name'
if output_address_type in ['SEQNUM']:
gdf[name_col] = gdf[name_col].astype(np.int64)
gdf = gdf.join( seq_df, how='inner', on=name_col)
gdf = gdf.loc[gdf['cell_exists']].drop(columns=['cell_exists'])
# gdf = gdf.join( seq_df, how='inner', left_on=name_col, right_on=input_address_type)
# gdf = gdf.loc[gdf['cell_exists']].drop(columns=['cell_exists'])

if self.debug is False:
try:
Expand Down Expand Up @@ -1276,16 +1276,16 @@ def grid_cell_centroids_from_cellids(self, cell_id_list, dggs_type, resolution,
if self.debug is True:
print(f"cannot switch address types on the fly here: {input_address_type} != {output_address_type}")

seq_df['cell_exists'] = True
# seq_df['cell_exists'] = True
if output_address_type in ['SEQNUM']:
seq_df[input_address_type] = seq_df[input_address_type].astype(np.int64)

seq_df.set_index(input_address_type, inplace=True)
# seq_df.set_index(input_address_type, inplace=True)
name_col = 'name' if 'name' in gdf.columns else 'Name'
if output_address_type in ['SEQNUM']:
gdf[name_col] = gdf[name_col].astype(np.int64)
gdf = gdf.join( seq_df, how='inner', on=name_col)
gdf = gdf.loc[gdf['cell_exists']].drop(columns=['cell_exists'])
# gdf = gdf.join( seq_df, how='inner', on=name_col)
# gdf = gdf.loc[gdf['cell_exists']].drop(columns=['cell_exists'])

if self.debug is False:
try:
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ pandas
fiona
shapely
geopandas
dggrid4py==0.3.0
dggrid4py==0.3.1

4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
copyright = '2024, Alexander Kmoch'
author = "Alexander Kmoch"

release = '0.3.0'
version = '0.3.0'
release = '0.3.1'
version = '0.3.1'

# -- General configuration

Expand Down
6 changes: 3 additions & 3 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ GNU AFFERO GENERAL PUBLIC LICENSE

`DGGRID <https://www.discreteglobalgrids.org/software/>`__ is a free
software program for creating and manipulating Discrete Global Grids
created and maintained by Kevin Sahr. DGGRID version 8.1b was released 12. January 2024
created and maintained by Kevin Sahr. DGGRID version 8.34 was released 13. November 2024

- `DGGRID Version 8.1b on GitHub <https://github.com/sahrk/DGGRID>`__
- `DGGRID Version 8.3 on GitHub <https://github.com/sahrk/DGGRID>`__
- `DGGRID User
Manual <https://github.com/sahrk/DGGRID/blob/d08e10d761f7bedd72a253ab1057458f339de51e/dggridManualV81b.pdf>`__

Expand Down Expand Up @@ -50,7 +50,7 @@ Bundling for different operating systems
----------------------------------------

Having to compile DGGRID for Windows can be a bit challenging. We are
working on an updated conda package. Currently DGGRID v7.8 is available on conda-forge:
working on an updated conda package. Currently DGGRID v8.3 is available on conda-forge:

.. image:: https://anaconda.org/conda-forge/dggrid/badges/version.svg
:target: https://anaconda.org/conda-forge/dggrid
Expand Down
33 changes: 22 additions & 11 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,28 @@ comfortable geopython libraries, like shapely and geopandas
gdf7 = dggrid_instance.grid_cell_polygons_for_extent('ISEA7H', 3, split_dateline=True)
gdf7.to_file('global_isea7h_3_interrupted.shp')
gdf_z1 = dggrid_instance.grid_cell_polygons_for_extent('IGEO7', 5, clip_geom=est_bound, output_address_type='Z7_STRING')
print(gdf_z1.head(3))
df_z1 = dggrid_instance.guess_zstr_resolution(gdf_z1['name'].values, 'IGEO7', input_address_type='Z7_STRING')
print(df_z1.head(3))
df_q2di = dggrid_instance.address_transform(gdf_z1['name'].values, 'IGEO7', 5, input_address_type='Z7_STRING', output_address_type='Q2DI')
print(df_q2di.head(3))
df_tri = dggrid_instance.address_transform(gdf_z1['name'].values, 'IGEO7', 5, input_address_type='Z7_STRING', output_address_type='PROJTRI')
print(df_tri.head(3))
gdf_z1 = dggrid_instance.grid_cell_polygons_for_extent('IGEO7', 5, clip_geom=est_bound, output_address_type='Z7_STRING')
print(gdf_z1.head(3))
df_z1 = dggrid_instance.guess_zstr_resolution(gdf_z1['name'].values, 'IGEO7', input_address_type='Z7_STRING')
print(df_z1.head(3))
df_q2di = dggrid_instance.address_transform(gdf_z1['name'].values, 'IGEO7', 5, input_address_type='Z7_STRING', output_address_type='Q2DI')
print(df_q2di.head(3))
df_tri = dggrid_instance.address_transform(gdf_z1['name'].values, 'IGEO7', 5, input_address_type='Z7_STRING', output_address_type='PROJTRI')
print(df_tri.head(3))
children = dggrid_instance.grid_cell_polygons_from_cellids(
cell_id_list=['00012502340'], # the input/parent cell id
dggs_type='IGEO7', # dggs type
resolution=11, # target resolution of children
clip_subset_type='COARSE_CELLS', # new parameter
clip_cell_res=9, # resolution of parent cell
input_address_type='Z7_STRING', # address_type
output_address_type='Z7_STRING' # address_type
)
print(children.head(3))
TODO
----
Expand Down
12 changes: 12 additions & 0 deletions examples/demo_highlevel_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ def highlevel_grid_gen_and_transform(dggrid_instance):
df_tri = dggrid_instance.address_transform(gdf_z1['name'].values, 'IGEO7', 5, input_address_type='Z7_STRING', output_address_type='PROJTRI')
print(df_tri.head(3))

children = dggrid_instance.grid_cell_polygons_from_cellids(
cell_id_list=['00012502340'], # the input/parent cell id
dggs_type='IGEO7', # dggs type
resolution=11, # target resolution of children
clip_subset_type='COARSE_CELLS', # new parameter
clip_cell_res=9, # resolution of parent cell
input_address_type='Z7_STRING', # address_type
output_address_type='Z7_STRING' # address_type
)
print(children.head(3))



def highlevel_grid_stats(dggrid_instance):

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dggrid4py"
version = "0.3.0"
version = "0.3.1"
description = "a Python library to run highlevel functions of DGGRIDv7 and v8"
authors = ["Alexander Kmoch <[email protected]>",
"Wai Tik Chan <[email protected]>",
Expand Down

0 comments on commit d8e399d

Please sign in to comment.