Skip to main content

Creates shapely shapes around given points.

Project description

Bounding Shapes

This library creates Shapely shapes designed to fit closely around a set of given points, and provides functionality to create a grid of points inside those shapes. This simplifies the problem of trying to find a shape that fits around all points, whilst allowing for gaps/multiple shapes to accomodate for situations where points may be clustered around a few areas, or handling points far outside a cluster.

import geopandas as gpd
from shapely import MultiPoint

# Example dataset of rainfall stations covering England
fn = "AllRainfallStations"
imported_gdf = gpd.read_file(f"zip://{fn}.zip!{fn}/{fn}.shp")
imported_gdf.head()
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
sample_N geometry
0 1 POINT (-1.17133 52.18628)
1 1 POINT (-1.1637 52.98624)
2 1 POINT (-1.67298 51.69289)
3 1 POINT (-0.64929 52.49389)
4 1 POINT (-0.99517 52.73152)
# Convert improted data into Multipoint object
reprojected_gdf = imported_gdf.to_crs(crs="EPSG:32631")
points = MultiPoint(list(zip(reprojected_gdf.geometry.x, reprojected_gdf.geometry.y)))
points

svg

from bounding_shape.bounding_shape import create_bounding_area

bounding_area = create_bounding_area(points)
bounding_area

svg

Using the libary to create a set of points inside an area:

from bounding_shape.bounding_shape import create_spaced_points
spaced_points = create_spaced_points(points=points) 
spaced_points

svg

Targeting a number of grid points

If creating a grid and there is a target number of points for the shape to be split into, the get_grid_spacing_for_points method allows this to be specified with the magnitude parameter.

from bounding_shape.bounding_shape import create_spaced_points, get_grid_spacing_for_points
from shapely import MultiPoint

points = MultiPoint([[0.0, 0.0], [0.0, 100.0], [100.0, 100.0], [100.0, 0.0]])

distance = get_grid_spacing_for_points(points=points, magnitude=500)
spaced_points = create_spaced_points(points=points, grid_spacing=distance, buffer=0.0)
spaced_points

svg

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bounding_shape-0.1.0.tar.gz (245.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bounding_shape-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file bounding_shape-0.1.0.tar.gz.

File metadata

  • Download URL: bounding_shape-0.1.0.tar.gz
  • Upload date:
  • Size: 245.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.3

File hashes

Hashes for bounding_shape-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa23401b63cf3b3af73a2eaa1f7756f65c8ea554b1d2c0b2fd906b22ba9e7a81
MD5 201475ab0debc62d6ae375022b29d428
BLAKE2b-256 ca14a66069bdecf9372068a0eb669dddeef326479dc80ae380bd2b7b0a389cc4

See more details on using hashes here.

File details

Details for the file bounding_shape-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bounding_shape-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.3

File hashes

Hashes for bounding_shape-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb9dc03c305aa90edfe997079b279d342853bd691475e576c14557947bc75164
MD5 416a97d308932cf6d1993fd05741490f
BLAKE2b-256 979391e739fa5b9024b6cc221165794663cd8fa151bb4ff6556d52884882b422

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page