Name | geomask JSON |
Version |
0.1.1
JSON |
| download |
home_page | None |
Summary | A very simple lib for creating geometric masks from spatial data using regular grids |
upload_time | 2025-09-13 03:14:12 |
maintainer | None |
docs_url | None |
author | campiohe |
requires_python | >=3.11 |
license | MIT |
keywords |
gis
spatial
grid
geometry
mask
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# GeoMask
A very simple lib for creating geometric masks from spatial data using regular grids.
## Features
- Create regular grids of points inside spacial geometries (polygons or multipolygons)
- Control grid spacing with a resolution parameter
- Optional point limits to avoid huge grids
- Export to pandas DataFrames
## Installation
```bash
pip install geomask
```
## Quick Start
```python
from geomask import GeoMask
from shapely import Polygon
# Create a polygon
polygon = Polygon([(0, 0), (10, 0), (10, 10), (0, 10)])
# Generate a grid mask
mask = GeoMask(geom=polygon, resolution=1.0)
print(f"Generated {len(mask)} points")
print(f"Area: {mask.area}")
print(f"Bounds: {mask.bounds}")
```
## Core Functionality
### Creating Masks
```python
from geomask import GeoMask
from shapely import Polygon, MultiPolygon
# Basic usage
polygon = Polygon([(0, 0), (10, 0), (10, 10), (0, 10)])
mask = GeoMask(geom=polygon, resolution=2.0)
# With point limit
mask = GeoMask(geom=polygon, resolution=0.5, limit=100)
# With grid offset
mask = GeoMask(geom=polygon, resolution=1.0, offset=(0.5, 0.5))
# Works with MultiPolygons too
poly1 = Polygon([(0, 0), (5, 0), (5, 5), (0, 5)])
poly2 = Polygon([(10, 10), (15, 10), (15, 15), (10, 15)])
multipoly = MultiPolygon([poly1, poly2])
mask = GeoMask(geom=multipoly, resolution=1.0)
```
### Extracting Coordinates
```python
# As numpy array
coords = mask.to_coordinates()
print(f"Shape: {coords.shape}") # (n_points, 2)
# As pandas DataFrame (requires pandas)
df = mask.to_dataframe()
print(df.head())
# Custom column names
df = mask.to_dataframe(x_col='longitude', y_col='latitude')
df = mask.to_dataframe(x_col='easting', y_col='northing')
```
### Filtering and Analysis
```python
# Filter by another geometry
filter_polygon = Polygon([(2, 2), (8, 2), (8, 8), (2, 8)])
filtered_mask = mask.filter_by_geometry(filter_polygon)
# Properties and methods
print(f"Point count: {len(mask)}")
print(f"Has points: {bool(mask)}")
print(f"Area: {mask.area}")
print(f"Bounds: {mask.bounds}")
```
### Integration with Pandas
```python
import pandas as pd
import numpy as np
# Convert to DataFrame for analysis
df = mask.to_dataframe(x_col='x', y_col='y')
# Add computed columns
df['distance_from_origin'] = np.sqrt(df.x**2 + df.y**2)
df['quadrant'] = df.apply(
lambda row: ('N' if row.y >= 0 else 'S') + ('E' if row.x >= 0 else 'W'),
axis=1
)
# Analysis
print(df.describe())
print(df.quadrant.value_counts())
# Filter points
close_points = df[df.distance_from_origin < 5.0]
```
## Advanced Usage
### Working with Complex Geometries
```python
# Polygon with hole
outer = [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]
inner = [(3, 3), (7, 3), (7, 7), (3, 7), (3, 3)]
polygon_with_hole = Polygon(outer, [inner])
mask = GeoMask(geom=polygon_with_hole, resolution=1.0)
```
### Performance Optimization
```python
# Use limits for large areas
large_polygon = Polygon([(0, 0), (1000, 0), (1000, 1000), (0, 1000)])
# This will automatically adjust resolution to meet the limit
mask = GeoMask(geom=large_polygon, resolution=1.0, limit=10000)
print(f"Actual resolution used: {mask.resolution}")
```
## Requirements
- Python 3.11+
- shapely >= 2.1.1
- numpy
- pandas (optional, for DataFrame functionality)
## Development
### Testing
Run the comprehensive test suite:
```bash
# Basic tests
pytest test_geomask.py
# With coverage
pytest test_geomask.py --cov=geomask --cov-report=term-missing
# Verbose output
pytest test_geomask.py -v
```
Raw data
{
"_id": null,
"home_page": null,
"name": "geomask",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "gis, spatial, grid, geometry, mask",
"author": "campiohe",
"author_email": "campiottihenrique@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b9/07/74eba479961cef95800a41af9b313418ea40cffbb1a430b77b51f5f581b0/geomask-0.1.1.tar.gz",
"platform": null,
"description": "# GeoMask\n\nA very simple lib for creating geometric masks from spatial data using regular grids.\n\n## Features\n\n- Create regular grids of points inside spacial geometries (polygons or multipolygons)\n- Control grid spacing with a resolution parameter\n- Optional point limits to avoid huge grids\n- Export to pandas DataFrames\n\n## Installation\n\n```bash\npip install geomask\n```\n\n## Quick Start\n\n```python\nfrom geomask import GeoMask\nfrom shapely import Polygon\n\n# Create a polygon\npolygon = Polygon([(0, 0), (10, 0), (10, 10), (0, 10)])\n\n# Generate a grid mask\nmask = GeoMask(geom=polygon, resolution=1.0)\n\nprint(f\"Generated {len(mask)} points\")\nprint(f\"Area: {mask.area}\")\nprint(f\"Bounds: {mask.bounds}\")\n```\n\n## Core Functionality\n\n### Creating Masks\n\n```python\nfrom geomask import GeoMask\nfrom shapely import Polygon, MultiPolygon\n\n# Basic usage\npolygon = Polygon([(0, 0), (10, 0), (10, 10), (0, 10)])\nmask = GeoMask(geom=polygon, resolution=2.0)\n\n# With point limit\nmask = GeoMask(geom=polygon, resolution=0.5, limit=100)\n\n# With grid offset\nmask = GeoMask(geom=polygon, resolution=1.0, offset=(0.5, 0.5))\n\n# Works with MultiPolygons too\npoly1 = Polygon([(0, 0), (5, 0), (5, 5), (0, 5)])\npoly2 = Polygon([(10, 10), (15, 10), (15, 15), (10, 15)])\nmultipoly = MultiPolygon([poly1, poly2])\nmask = GeoMask(geom=multipoly, resolution=1.0)\n```\n\n### Extracting Coordinates\n\n```python\n# As numpy array\ncoords = mask.to_coordinates()\nprint(f\"Shape: {coords.shape}\") # (n_points, 2)\n\n# As pandas DataFrame (requires pandas)\ndf = mask.to_dataframe()\nprint(df.head())\n\n# Custom column names\ndf = mask.to_dataframe(x_col='longitude', y_col='latitude')\ndf = mask.to_dataframe(x_col='easting', y_col='northing')\n```\n\n### Filtering and Analysis\n\n```python\n# Filter by another geometry\nfilter_polygon = Polygon([(2, 2), (8, 2), (8, 8), (2, 8)])\nfiltered_mask = mask.filter_by_geometry(filter_polygon)\n\n# Properties and methods\nprint(f\"Point count: {len(mask)}\")\nprint(f\"Has points: {bool(mask)}\")\nprint(f\"Area: {mask.area}\")\nprint(f\"Bounds: {mask.bounds}\")\n```\n\n### Integration with Pandas\n\n```python\nimport pandas as pd\nimport numpy as np\n\n# Convert to DataFrame for analysis\ndf = mask.to_dataframe(x_col='x', y_col='y')\n\n# Add computed columns\ndf['distance_from_origin'] = np.sqrt(df.x**2 + df.y**2)\ndf['quadrant'] = df.apply(\n lambda row: ('N' if row.y >= 0 else 'S') + ('E' if row.x >= 0 else 'W'), \n axis=1\n)\n\n# Analysis\nprint(df.describe())\nprint(df.quadrant.value_counts())\n\n# Filter points\nclose_points = df[df.distance_from_origin < 5.0]\n```\n\n## Advanced Usage\n\n### Working with Complex Geometries\n\n```python\n# Polygon with hole\nouter = [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]\ninner = [(3, 3), (7, 3), (7, 7), (3, 7), (3, 3)]\npolygon_with_hole = Polygon(outer, [inner])\n\nmask = GeoMask(geom=polygon_with_hole, resolution=1.0)\n```\n\n### Performance Optimization\n\n```python\n# Use limits for large areas\nlarge_polygon = Polygon([(0, 0), (1000, 0), (1000, 1000), (0, 1000)])\n\n# This will automatically adjust resolution to meet the limit\nmask = GeoMask(geom=large_polygon, resolution=1.0, limit=10000)\nprint(f\"Actual resolution used: {mask.resolution}\")\n```\n\n## Requirements\n\n- Python 3.11+\n- shapely >= 2.1.1\n- numpy\n- pandas (optional, for DataFrame functionality)\n\n## Development\n\n### Testing\n\nRun the comprehensive test suite:\n\n```bash\n# Basic tests\npytest test_geomask.py\n\n# With coverage\npytest test_geomask.py --cov=geomask --cov-report=term-missing\n\n# Verbose output\npytest test_geomask.py -v\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A very simple lib for creating geometric masks from spatial data using regular grids",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/campiohe/geomask",
"Issues": "https://github.com/campiohe/geomask/issues",
"Repository": "https://github.com/campiohe/geomask"
},
"split_keywords": [
"gis",
" spatial",
" grid",
" geometry",
" mask"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "accd2e0c4bd6fc424aad153c378ba53263201a4e9de5993b436e07a467540eb5",
"md5": "8ffc9f8e49851d296f4ca863ca8b36d1",
"sha256": "4f4eba1c8ebe6bd35c5d6bdc5834d4434ac4ab8bf82544edc1c7a25152d1b18b"
},
"downloads": -1,
"filename": "geomask-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8ffc9f8e49851d296f4ca863ca8b36d1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 6546,
"upload_time": "2025-09-13T03:14:10",
"upload_time_iso_8601": "2025-09-13T03:14:10.902692Z",
"url": "https://files.pythonhosted.org/packages/ac/cd/2e0c4bd6fc424aad153c378ba53263201a4e9de5993b436e07a467540eb5/geomask-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "b90774eba479961cef95800a41af9b313418ea40cffbb1a430b77b51f5f581b0",
"md5": "31ac3f269b14e47886e765490fcb25da",
"sha256": "afe4c862e5cc2363c358345bb5c9d4d1050529ca95c0a4055108df9ee6b3e693"
},
"downloads": -1,
"filename": "geomask-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "31ac3f269b14e47886e765490fcb25da",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 6163,
"upload_time": "2025-09-13T03:14:12",
"upload_time_iso_8601": "2025-09-13T03:14:12.396910Z",
"url": "https://files.pythonhosted.org/packages/b9/07/74eba479961cef95800a41af9b313418ea40cffbb1a430b77b51f5f581b0/geomask-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-13 03:14:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "campiohe",
"github_project": "geomask",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "geomask"
}