Skip to main content

Sampling random points from non-convex polygons and land areas

Project description

Random Land Points

Unit Coverage Status

This is a little package that allows you to randomly sample points on land. This can be done either for all land masses, by continent, or by country.

Random Points

Installation

pip install random-land-points

Usage

This package can be used to get random points on land in a provided polygon or in a specific country.

To sampleyou can use the random_points function. This function returns a random point on land in the provided polygon.

from src import random_land_points as rlp

# Get a random point on land
point = rlp.random_points()

# Get 10 random points on land
points = rlp.random_points(count=10)

You can also sample points by continent or by country. To do this, you can pass the continent or country name as an argument to the random_points function.

from src import random_land_points as rlp

# Get a random point on land in Europe
point = rlp.random_points('Europe')

# Get a random point on land in Italy
point = rlp.random_points('Italy')

The package utilizes the Natural Earth dataset to get the land polygons for each country. The data set comes in 3 resolutions: 10m high, 50m medium, and 110m low. The default resolution is medium, but you can specify the resolution by passing the resolution argument to the random_points and get_countries functions. The number of polygons and the available countries vary by resolution.

An example of this is shown below:

from src import random_land_points as rlp

# Get all high resolution countries
countries = rlp.get_countries(resolution='high')

# Get a random point on land in a high resolution country
point = rlp.random_points('Italy', resolution='high')

If you need to get the list of all supported countries, you can use the get_countries function.

from src import random_land_points as rlp

countries = rlp.get_countries()

To sample from a specific polygon, you can use the random_point_in_polygon function. This function takes a Shapely polygon as an argument and returns a random point on land in that polygon.

from src import random_land_points as rlp
from shapely.geometry import Polygon

# Create a polygon
polygon = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])

# Get a random point on land in the polygon
point = rlp.random_point_in_polygon(polygon)

Examples

There are examples found in the examples directory. These examples show how to use the package to get random points on land and visualize the results.

To run the examples install the package with [examples] option:

pip install random-land-points[examples]

Then run the examples with the following command:

python ./examples/random_points.py
python ./examples/random_by_continent.py
python ./examples/random_by_country.py

Development

To install the package for development, you can use the following command:

pip install -e ".[dev]"

To run the tests, you can use the following command:

pytest

License

This package is licensed under the MIT license. See the LICENSE file for more details.

Acknowledgements

Made with Natural Earth. Free vector and raster map data @ naturalearthdata.com.

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

random_land_points-1.0.0.tar.gz (6.1 MB view details)

Uploaded Source

File details

Details for the file random_land_points-1.0.0.tar.gz.

File metadata

  • Download URL: random_land_points-1.0.0.tar.gz
  • Upload date:
  • Size: 6.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for random_land_points-1.0.0.tar.gz
Algorithm Hash digest
SHA256 eb2035d8c4dc0f1c89801411795ae88f6ac78800a5f9ff1d2444c93c2d2ce224
MD5 a4a1cec100eec108d8197f4769209b76
BLAKE2b-256 0bcf449ffb71075fc0d45656d824cc45d1b9edcd7053d19468fab41c4b1061d0

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