dggrid4py

A Python 3.8+ wrapper for the DGGS tool DGGRID from Kevin Sahr

https://github.com/allixender/dggrid4py

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.9%) to scientific vocabulary

Keywords

dggrid dggs geospatial
Last synced: 6 months ago · JSON representation ·

Repository

A Python 3.8+ wrapper for the DGGS tool DGGRID from Kevin Sahr

Basic Info
Statistics
  • Stars: 28
  • Watchers: 5
  • Forks: 8
  • Open Issues: 9
  • Releases: 10
Topics
dggrid dggs geospatial
Created over 5 years ago · Last pushed 6 months ago
Metadata Files
Readme License Citation

README.md

dggrid4py - a Python library to run highlevel functions of DGGRID

PyPI version DOI Documentation Status GitHub

Population Gridded

GNU AFFERO GENERAL PUBLIC LICENSE

DGGRID 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

You need the ddgrid tool compiled available on the system.

Besides some lowlevel access influence the dggrid operations' metafile creation, a few highlevel functions are integrated to work with the more comfortable geopython libraries, like shapely and geopandas

  • gridcellpolygonsforextent(): fill extent/subset with cells at resolution (clip or world)
  • gridcellpolygonsfromcellids(): geometryfromcellid for dggs at resolution (from id list)
  • gridcellidsforextent(): getallindexes/cellids for dggs at resolution (clip or world)
  • cellsforgeopoints(): polyoutline for point/centre at resolution
  • addresstransform(): conversion betwenn cellid address types, like SEQNUM, Z7, or Q2DI

```python import geopandas import shapely

from dggrid4py import DGGRIDv7

create an inital instance that knows where the dggrid tool lives, configure temp workspace and log/stdout output

if you have

dggridinstance = DGGRIDv7(executable='<pathto>/dggrid', workingdir='.', capturelogs=False, silent=False, tmpgeoout_legacy=False, debug=False)

global ISEA4T grid at resolution 5 into GeoDataFrame to Shapefile

gdf1 = dggridinstance.gridcellpolygonsforextent('ISEA4T', 5) print(gdf1.head()) gdf1.tofile('isea4t_5.shp')

gdfcentroids = dggridinstance.gridcellcentroidsforextent(dggstype='ISEA7H', resolution=4, mixedaperturelevel=None, clipgeom=None)

clip extent

clip_bound = shapely.geometry.box(20.2,57.00, 28.4,60.0 )

ISEA7H grid at resolution 9, for extent of provided WGS84 rectangle into GeoDataFrame to Shapefile

gdf3 = dggridinstance.gridcellpolygonsforextent('ISEA7H', 9, clipgeom=estbound) print(gdf3.head()) gdf3.tofile('grids/estshapeisea7h_9.shp')

generate cell and areal statistics for a ISEA7H grids from resolution 0 to 8 (return a pandas DataFrame)

df1 = dggridinstance.gridstatstable('ISEA7H', 8) print(df1.head(8)) df1.tocsv('isea7h8stats.csv', index=False)

generate the DGGS grid cells that would cover a GeoDataFrame of points, return Polygons with cell IDs as GeoDataFrame

gdf4 = dggridinstance.cellsforgeopoints(geodfpointswgs84, False, 'ISEA7H', 5) print(gdf4.head()) gdf4.tofile('polycellsfrompointsisea7h_5.shp')

generate the DGGS grid cells that would cover a GeoDataFrame of points, return cell IDs added as column to the points GDF

gdf5 = dggridinstance.cellsforgeopoints(geodfpointswgs84=geodfpointswgs84, cellidsonly=True, dggstype='ISEA4H', resolution=8) print(gdf5.head()) gdf5.tofile('geopointcellidsfrompointsisea4h_8.shp')

generate DGGS grid cell polygons based on 'cellidlist' (a list or np.array of provided cell_ids)

gdf6 = dggridinstance.gridcellpolygonsfromcellids(cellidlist=[1, 4, 8], 'ISEA7H', 5) print(gdf6.head()) gdf6.tofile('fromseqnumsisea7h_5.shp')

v0.2.6 API update split at dateline for cartesian GIS tools

gdf7 = dggridinstance.gridcellpolygonsforextent('ISEA7H', 3, splitdateline=True) gdf7.tofile('globalisea7h3interrupted.shp')

gdfz1 = dggridinstance.gridcellpolygonsforextent('IGEO7', 5, clipgeom=estbound, outputaddresstype='Z7STRING') print(gdfz1.head(3))

dfz1 = dggridinstance.guesszstrresolution(gdfz1['name'].values, 'IGEO7', inputaddresstype='Z7STRING') print(df_z1.head(3))

dfq2di = dggridinstance.addresstransform(gdfz1['name'].values, 'IGEO7', 5, inputaddresstype='Z7STRING', outputaddresstype='Q2DI') print(dfq2di.head(3))

dftri = dggridinstance.addresstransform(gdfz1['name'].values, 'IGEO7', 5, inputaddresstype='Z7STRING', outputaddresstype='PROJTRI') print(dftri.head(3))

```

Portable DGGRID binary

if you don't have a special local distribution of the dggrid-tool or if you didn't install with conda-forge, you can use a provided portable:

```python

from dggrid4py import tool

dggridexec = tool.getportableexecutable(".") dggridinstanceportable = DGGRIDv7(executable=dggridexec, workingdir='.', capturelogs=False, silent=True, hasgdal=False, tmpgeooutlegacy=True, debug=False)

```

TODO:

  • get parentforcell_id at coarser resolution
  • get childrenforcell_id at finer resolution

Remark: This is now possible with the IGEO7/Z7 system.

Related work:

Originally insprired by dggridR, Richard Barnes’ R interface to DGGRID. However, dggridR is directly linked via Rcpp to DGGRID and calls native C/C++ functions.

After some unsuccessful trials with ctypes, cython, CFFI, pybind11 or cppyy (rather due to lack of experience) I found am2222/pydggrid (on PyPI) which made apparently some initial scaffolding for the transform operation with pybind11 including some sophisticated conda packaging for Windows. This might be worth following up. Interestingly, its todos include "Adding GDAL export Geometry Support" and "Support GridGeneration using DGGRID" which this dggrid4py module supports with integration of GeoPandas.

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 v8.3 is available on conda-forge:

Latest version on conda-forge

greater context DGGS in Earth Sciences and GIS

Some reading to be excited about: discourse.pangeo.io

Owner

  • Name: Alex Kmoch
  • Login: allixender
  • Kind: user
  • Location: Estonia
  • Company: University of Tartu

Geospatial Web Dev Ops Researcher Tinkerer

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Kmoch"
  given-names: "Alexander"
  orcid: https://orcid.org/0000-0003-4386-4450
title: "dggrid4py: A set of python modules for creating and manipulating Discrete Global Grids with DGGRID v7"
version: "0.2.3"
doi: 10.5281/zenodo.5873330
date-released: 2020-10-29
url: "https://github.com/allixender/dggrid4py"

GitHub Events

Total
  • Create event: 6
  • Issues event: 14
  • Release event: 7
  • Watch event: 3
  • Issue comment event: 17
  • Push event: 30
  • Pull request review event: 2
  • Pull request event: 6
Last Year
  • Create event: 6
  • Issues event: 14
  • Release event: 7
  • Watch event: 3
  • Issue comment event: 17
  • Push event: 30
  • Pull request review event: 2
  • Pull request event: 6

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 30
  • Total Committers: 2
  • Avg Commits per committer: 15.0
  • Development Distribution Score (DDS): 0.033
Top Committers
Name Email Commits
Alexander Kmoch a****h@u****e 29
Luís de Sousa l****a@p****h 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 12
  • Total pull requests: 5
  • Average time to close issues: over 1 year
  • Average time to close pull requests: 20 days
  • Total issue authors: 4
  • Total pull request authors: 2
  • Average comments per issue: 1.58
  • Average comments per pull request: 0.4
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 7
  • Pull requests: 4
  • Average time to close issues: 7 days
  • Average time to close pull requests: 24 days
  • Issue authors: 3
  • Pull request authors: 1
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.25
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • tik65536 (6)
  • allixender (5)
  • jlguilherme (1)
  • thangqd (1)
Pull Request Authors
  • tik65536 (4)
  • ldesousa (1)
  • allixender (1)
Top Labels
Issue Labels
enhancement (1) help wanted (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 971 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 2
  • Total versions: 11
  • Total maintainers: 1
pypi.org: dggrid4py

a Python library to run highlevel functions of DGGRIDv7 and v8

  • Versions: 11
  • Dependent Packages: 0
  • Dependent Repositories: 2
  • Downloads: 971 Last month
Rankings
Dependent packages count: 9.9%
Dependent repos count: 11.7%
Stargazers count: 13.6%
Forks count: 15.4%
Average: 15.7%
Downloads: 28.0%
Maintainers (1)
Last synced: 6 months ago

Dependencies

docs/requirements.txt pypi
  • myst-parser ==3
  • sphinx ==7.1.2
  • sphinx-rtd-theme ==1.3.0rc1
pyproject.toml pypi
  • myst-parser 2 docs
  • sphinx 7.1.2 docs
  • sphinx-rtd-theme 1.3.0rc1 docs
  • fiona ^1.8
  • geopandas ^0.9
  • numpy ^1.21
  • pandas ^1.3
  • python ^3.8
  • shapely ^1.7
  • pytest * test
.github/workflows/python-publish.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v3 composite
  • pypa/gh-action-pypi-publish 27b31702a0e7fc50959f5ad993c78deac1bdfc29 composite