cheginit / geomesher

Meshing a GeoDataFrame using Gmsh.

Home Page:https://geomesher.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

image

GeoMesher: Meshing a GeoDataFrame using Gmsh

CI

PyPi

Conda Version

CodeCov

Python Versions

Downloads

CodeFactor

black

pre-commit

Features

GeoMesher is a fork of pandamesh. The original package included two mesh generators: Triangle and Gmsh. This fork only includes the Gmsh mesh generator since Triangle seems to be not maintained anymore. Also, GeoMesher adds the following new functionalities:

  • A new method for returning the generated mesh as a GeoDataFrame.
  • A new function called gdf_mesher that can generate a mesh from a GeoDataFrame with a single function call and with sane defaults for the mesh generator.
  • Remap a scalar field from the source GeoDataFrame to the generated mesh, using an area weighted interpolation method (based on Tobler).
  • Handle MultiPolygon geometries in the source GeoDataFrame.

Note that the remapping functionality of GeoMesher is a simple areal interpolation method. For more advanced interpolation methods, please use Tobler.

Installation

You can install GeoMesher using pip:

$ pip install geomesher

or using conda (mamba):

$ conda install -c conda-forge geomesher

Quick start

The following example shows how to generate a mesh from a GeoDataFrame using both the gdf_mesher function and the Mesher class.

We start by getting a GeoDataFrame of South America from the Natural Earth website. Then, we reproject it to a projected coordinate system (UTM zone 20S). Finally, we add a new column called cellsize that will be used to set the maximum size of the mesh elements.

We use the gdf_mesher function to generate the mesh with default parameters and use Mesher to generate the mesh with MESH_ADAPT algorithm. We also use the area_interpolate function to remap the POP_EST column from the source GeoDataFrame to the generated mesh.

import geopandas as gpd
import geomesher as gm

world = gpd.read_file(
    "https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip"
)

south_america = world[world["CONTINENT"] == "South America"]
south_america = south_america.explode(ignore_index=True).to_crs(32620)
south_america["cellsize"] = 500_000.0

mesh_auto = gm.gdf_mesher(south_america, intensive_variables=["POP_EST"])

mesher = gm.Mesher(south_america)
mesher.mesh_algorithm = "MESH_ADAPT"
mesh_adapt = mesher.generate()
mesh_adapt = gm.area_interpolate(south_america, mesh_adapt, intensive_variables=["POP_EST"])

image

Contributing

Contributions are very welcomed. Please read CONTRIBUTING.rst file for instructions.

Credits

GeoMesher is a fork of pandamesh (MIT License) and uses one of the modules in Tobler (BSD-3-Clause License).

About

Meshing a GeoDataFrame using Gmsh.

https://geomesher.readthedocs.io/

License:Other


Languages

Language:Python 100.0%