├── .github └── workflows │ ├── daily_tests.yml │ └── main.yml ├── .gitignore ├── .isort.cfg ├── .readthedocs.yml ├── .travis.yml ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.md ├── boolean.md ├── conftest.py ├── dev_requirements.txt ├── docs └── source │ ├── Makefile │ ├── boolean │ ├── boolean_disjoint.rst │ └── boolean_intersects.rst │ ├── conf.py │ ├── feature_conversion │ └── polygon_to_line.rst │ ├── index.rst │ ├── install.rst │ ├── make.bat │ ├── measurements │ ├── along.rst │ ├── area.rst │ ├── bbox.rst │ ├── bbox_polygon.rst │ ├── bearing.rst │ ├── center.rst │ ├── centroid.rst │ ├── destination.rst │ ├── distance.rst │ ├── envelop.rst │ ├── length.rst │ ├── midpoint.rst │ ├── nearest_point.rst │ ├── point_in_polygon.rst │ ├── point_on_feature.rst │ ├── point_to_line_distance.rst │ ├── points_within_polygon.rst │ ├── rhumb_bearing.rst │ ├── rhumb_destination.rst │ ├── rhumb_distance.rst │ └── square.rst │ ├── misc │ ├── line_arc.rst │ ├── line_intersect.rst │ ├── line_segment.rst │ └── sector.rst │ ├── random │ ├── random_points.rst │ └── random_position.rst │ ├── transformations │ ├── bbox_clip.rst │ ├── bezier_spline.rst │ ├── circle.rst │ ├── concave_hull.rst │ ├── convex_hull.rst │ ├── difference.rst │ ├── dissolve.rst │ ├── intersect.rst │ ├── line_offset.rst │ ├── tesselate.rst │ ├── transform_rotate.rst │ ├── transform_scale.rst │ ├── transform_translate.rst │ ├── union.rst │ └── voronoi.rst │ ├── turfpy.__version__.rst │ ├── turfpy._compact.rst │ ├── turfpy.boolean.rst │ ├── turfpy.dev_lib.earcut.rst │ ├── turfpy.dev_lib.rst │ ├── turfpy.dev_lib.spline.rst │ ├── turfpy.extra.rst │ ├── turfpy.feature_conversion.rst │ ├── turfpy.helper.rst │ ├── turfpy.measurement.rst │ ├── turfpy.meta.rst │ ├── turfpy.misc.rst │ ├── turfpy.random.rst │ ├── turfpy.rst │ └── turfpy.transformation.rst ├── environment.yml ├── examples ├── Misc.ipynb ├── Random.ipynb ├── boolean.ipynb ├── feature_conversion.ipynb ├── measurements.ipynb └── transformations.ipynb ├── feature_conversion.md ├── measurements.md ├── misc.md ├── postBuild ├── random.md ├── requirements.txt ├── scripts └── build_apiref.sh ├── setup.cfg ├── setup.py ├── tests ├── boolean_disjoint_test │ ├── false │ │ ├── LineString │ │ │ ├── LineString │ │ │ │ └── LineString-LineString.geojson │ │ │ ├── Point │ │ │ │ ├── LineString-Point-1.geojson │ │ │ │ └── LineString-Point-2.geojson │ │ │ └── Polygon │ │ │ │ ├── LineString-In-Polygon.geojson │ │ │ │ └── LineString-Polygon.geojson │ │ ├── MultiPoint │ │ │ ├── LineString │ │ │ │ └── MultiPoint-LineString.geojson │ │ │ ├── MultiPoint │ │ │ │ └── MultiPoint-MultiPoint.geojson │ │ │ └── Polygon │ │ │ │ └── MultiPoint-Polygon.geojson │ │ ├── MultiPolygon │ │ │ └── Polygon │ │ │ │ └── MultiPolygon-Polygon.geojson │ │ ├── Point │ │ │ ├── LineString │ │ │ │ ├── Point-LineString-1.geojson │ │ │ │ ├── Point-LineString-2.geojson │ │ │ │ ├── Point-LineString-3.geojson │ │ │ │ └── Point-LineString-4.geojson │ │ │ ├── MultiPoint │ │ │ │ └── Point-MultiPoint.geojson │ │ │ ├── Point │ │ │ │ └── Point-Point.geojson │ │ │ └── Polygon │ │ │ │ ├── Point-Polygon-1.geojson │ │ │ │ └── Point-Polygon-2.geojson │ │ └── Polygon │ │ │ ├── LineString │ │ │ ├── Polygon-Containing-Linestring.geojson │ │ │ └── Polygon-LineString.geojson │ │ │ ├── MultiPolygon │ │ │ └── Polygon-MultiPolygon.geojson │ │ │ ├── Point │ │ │ └── Polygon-Point.geojson │ │ │ └── Polygon │ │ │ ├── Large-Inside-Small.geojson │ │ │ ├── Polygon-Polygon.geojson │ │ │ ├── Small-Inside-Large.geojson │ │ │ └── issue-1216.geojson │ └── true │ │ ├── LineString │ │ ├── LineString │ │ │ └── LineString-LineString.geojson │ │ ├── Point │ │ │ └── LineString-Point.geojson │ │ └── Polygon │ │ │ └── LineString-Polygon.geojson │ │ ├── MultiPoint │ │ ├── LineString │ │ │ └── MultiPoint-LineString.geojson │ │ ├── MultiPoint │ │ │ └── MultiPoint-MultiPoint.geojson │ │ ├── Point │ │ │ └── MultiPoint-Point.geojson │ │ └── Polygon │ │ │ └── MultiPoint-Polygon.geojson │ │ ├── MultiPolygon │ │ └── Polygon │ │ │ └── MultiPolygon-Polygon.geojson │ │ ├── Point │ │ ├── LineString │ │ │ └── Point-LineString.geojson │ │ ├── MultiPoint │ │ │ └── Point-Multipoint.geojson │ │ ├── Point │ │ │ └── Point-Point.geojson │ │ └── Polygon │ │ │ └── Point-Polygon.geojson │ │ └── Polygon │ │ ├── LineString │ │ └── Polygon-LineString.geojson │ │ ├── MultiPolygon │ │ └── Polygon-MultiPolygon.geojson │ │ ├── Point │ │ └── Polygon-Point.geojson │ │ └── Polygon │ │ └── Polygon-Polygon.geojson ├── boolean_intersects_test │ ├── false │ │ ├── LineString │ │ │ ├── LineString │ │ │ │ └── LineString-LineString.geojson │ │ │ ├── Point │ │ │ │ └── LineString-Point.geojson │ │ │ └── Polygon │ │ │ │ └── LineString-Polygon.geojson │ │ ├── MultiPoint │ │ │ ├── LineString │ │ │ │ └── MultiPoint-LineString.geojson │ │ │ ├── MultiPoint │ │ │ │ └── MultiPoint-MultiPoint.geojson │ │ │ ├── Point │ │ │ │ └── MultiPoint-Point.geojson │ │ │ └── Polygon │ │ │ │ └── MultiPoint-Polygon.geojson │ │ ├── MultiPolygon │ │ │ └── Polygon │ │ │ │ └── MultiPolygon-Polygon.geojson │ │ ├── Point │ │ │ ├── LineString │ │ │ │ └── Point-LineString.geojson │ │ │ ├── MultiPoint │ │ │ │ └── Point-Multipoint.geojson │ │ │ ├── Point │ │ │ │ └── Point-Point.geojson │ │ │ └── Polygon │ │ │ │ └── Point-Polygon.geojson │ │ └── Polygon │ │ │ ├── LineString │ │ │ └── Polygon-LineString.geojson │ │ │ ├── MultiPolygon │ │ │ └── Polygon-MultiPolygon.geojson │ │ │ ├── Point │ │ │ └── Polygon-Point.geojson │ │ │ └── Polygon │ │ │ └── Polygon-Polygon.geojson │ └── true │ │ ├── LineString │ │ ├── LineString │ │ │ └── LineString-LineString.geojson │ │ ├── Point │ │ │ ├── LineString-Point-1.geojson │ │ │ └── LineString-Point-2.geojson │ │ └── Polygon │ │ │ ├── LineString-In-Polygon.geojson │ │ │ └── LineString-Polygon.geojson │ │ ├── MultiPoint │ │ ├── LineString │ │ │ └── MultiPoint-LineString.geojson │ │ ├── MultiPoint │ │ │ └── MultiPoint-MultiPoint.geojson │ │ └── Polygon │ │ │ └── MultiPoint-Polygon.geojson │ │ ├── MultiPolygon │ │ └── Polygon │ │ │ └── MultiPolygon-Polygon.geojson │ │ ├── Point │ │ ├── LineString │ │ │ ├── Point-LineString-1.geojson │ │ │ ├── Point-LineString-2.geojson │ │ │ ├── Point-LineString-3.geojson │ │ │ └── Point-LineString-4.geojson │ │ ├── MultiPoint │ │ │ └── Point-MultiPoint.geojson │ │ ├── Point │ │ │ └── Point-Point.geojson │ │ └── Polygon │ │ │ ├── Point-Polygon-1.geojson │ │ │ └── Point-Polygon-2.geojson │ │ └── Polygon │ │ ├── LineString │ │ ├── Polygon-Containing-Linestring.geojson │ │ └── Polygon-LineString.geojson │ │ ├── MultiPolygon │ │ └── Polygon-MultiPolygon.geojson │ │ ├── Point │ │ └── Polygon-Point.geojson │ │ └── Polygon │ │ ├── Large-Inside-Small.geojson │ │ ├── Polygon-Polygon.geojson │ │ ├── Small-Inside-Large.geojson │ │ └── issue-1216.geojson ├── feature_conversion_polygon_to_line_test │ ├── in │ │ ├── geometry-polygon.geojson │ │ ├── multi-polygon-outer-doughnut.geojson │ │ ├── multi-polygon-with-holes.geojson │ │ ├── multi-polygon.geojson │ │ ├── polygon-with-hole.geojson │ │ └── polygon.geojson │ └── out │ │ ├── geometry-polygon.geojson │ │ ├── multi-polygon-outer-doughnut.geojson │ │ ├── multi-polygon-with-holes.geojson │ │ ├── multi-polygon.geojson │ │ ├── polygon-with-hole.geojson │ │ └── polygon.geojson ├── test_boolean.py ├── test_feature_conversion.py ├── test_helper.py ├── test_measurement.py ├── test_misc.py ├── test_random.py └── test_transformation.py ├── transformation.md └── turfpy ├── __init__.py ├── __version__.py ├── _compact.py ├── boolean.py ├── dev_lib ├── __init__.py ├── earcut.py └── spline.py ├── extra.py ├── feature_conversion.py ├── helper.py ├── measurement.py ├── meta.py ├── misc.py ├── random.py └── transformation.py /.github/workflows/daily_tests.yml: -------------------------------------------------------------------------------- 1 | name: Daily Tests 2 | 3 | on: 4 | schedule: 5 | - cron: "0 0 * * *" 6 | 7 | jobs: 8 | run: 9 | runs-on: ${{ matrix.os }} 10 | 11 | strategy: 12 | fail-fast: false 13 | matrix: 14 | os: [ubuntu-latest] 15 | python-version: [3.7, 3.8, 3.9] 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | 20 | - name: Set up Python ${{ matrix.python-version }} 21 | uses: actions/setup-python@v2 22 | with: 23 | python-version: ${{ matrix.python-version }} 24 | 25 | - name: Pip install dependencies 26 | shell: bash -l {0} 27 | run: | 28 | python3 -m pip install --upgrade pip 29 | pip3 install -r requirements.txt 30 | pip3 install -r dev_requirements.txt 31 | 32 | - name: Install turfpy 33 | shell: bash -l {0} 34 | run: pip3 install . 35 | 36 | - name: Lint check 37 | shell: bash -l {0} 38 | run: | 39 | make clean 40 | make lint 41 | make typing 42 | 43 | - name: Test check 44 | shell: bash -l {0} 45 | run: pytest -v --durations=10 --cov-report=xml --cov=turfpy tests 46 | 47 | - name: Build docs (Only on Linux for saving time) 48 | if: matrix.os == 'ubuntu-latest' 49 | shell: bash -l {0} 50 | run: sh scripts/build_apiref.sh 51 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | run: 13 | runs-on: ${{ matrix.os }} 14 | 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | os: [ubuntu-latest] 19 | python-version: ['3.10', '3.11', '3.12', '3.13'] 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | 24 | - name: Set up Python ${{ matrix.python-version }} 25 | uses: actions/setup-python@v2 26 | with: 27 | python-version: ${{ matrix.python-version }} 28 | 29 | - name: Pip install dependencies 30 | shell: bash -l {0} 31 | run: | 32 | python3 -m pip install --upgrade pip 33 | pip3 install -r requirements.txt 34 | pip3 install -r dev_requirements.txt 35 | 36 | - name: Install turfpy 37 | shell: bash -l {0} 38 | run: pip3 install . 39 | 40 | - name: Lint check 41 | shell: bash -l {0} 42 | run: | 43 | make clean 44 | make lint 45 | make typing 46 | 47 | - name: Test check 48 | shell: bash -l {0} 49 | run: pytest -v --durations=10 --cov-report=xml --cov=turfpy tests 50 | 51 | - name: Build docs (Only on Linux for saving time) 52 | if: matrix.os == 'ubuntu-latest' 53 | shell: bash -l {0} 54 | run: sh scripts/build_apiref.sh -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | .idea 131 | .DS_Store 132 | _build/ 133 | -------------------------------------------------------------------------------- /.isort.cfg: -------------------------------------------------------------------------------- 1 | [settings] 2 | line_length=90 3 | multi_line_output=3 4 | include_trailing_comma=True 5 | force_grid_wrap=0 6 | use_parentheses=True 7 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Build documentation in the docs/ directory with Sphinx 9 | sphinx: 10 | builder: html 11 | configuration: docs/source/conf.py 12 | 13 | # Build documentation with MkDocs 14 | #mkdocs: 15 | # configuration: mkdocs.yml 16 | 17 | # Optionally build your docs in additional formats such as PDF 18 | formats: 19 | - pdf 20 | 21 | # Optionally set the version of Python and requirements required to build your docs 22 | python: 23 | version: 3.7 24 | install: 25 | - requirements: requirements.txt 26 | - requirements: dev_requirements.txt 27 | - method: pip 28 | path: . -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - '3.8' 4 | script: 5 | - make clean 6 | deploy: 7 | provider: pypi 8 | username: __token__ 9 | password: 10 | secure: nbVjj9nxpJ5yT/vY9TZqLl17yCTV+PDJ9aCcQS6ZsWukGbmgl0RW8AiXNzUPToz6sx2krPDj/8nChEExIvhBWGbeNBVudx4x0RUjxQZWDMWDJrP2wxJkzatsO1D/KK9eXx9pkloqtR1JZzRNSiV2CQ9g30IUftPzvncYCBn6QkUqHflLBt1uh/mlccXfjuoE7LGkS6e+3VLDHgGEgHCq+39IlWp5336Sur5nW6xf7h0qk/6pyEXprA46ydq38k+1KII6yKnh0qJ0oqPkQG84XTptZG8kNUQ+suKNCbwp8Uutm7lo8/zbgIH+sDEfZz1dX/o2UMKaV3LQ2cqMkXuO91V7xJX0XnUNFABLc8GujuTMsJi7bBf/dj0eNrGxZGVi/7OpQnvor7/Bw55x88DPMJ30YHybcOPydu0h6y9hX4jP0WlYkoZMQnBfdVwWYCKs3P/WCFKH7fi8VtV9c2DVaMRmainnmp5Nji8EUTiwHADeZhX3s4yRYRYNm+5DlpuCpjLd4RXj1Df+jJxByP4f3XI8e0gw48H65GhYOfYQIkb+uRtXx6mKAiU7RjOOZ7ebkSFvPbtqkh3pQYOnOglNgY5pW0XUukAAeD0JzCFVmP3Q7EpnDPoXVM/DnPxE56+N4MdenBiH0L2CpbTi/6yn1D1TgqE9dJOzeLWOhGBmGKk= 11 | on: 12 | tags: true 13 | branch: master 14 | python: 3.8 15 | condition: $TRAVIS_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Omkar Mestry 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include requirements.txt 2 | include LICENSE 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts 4 | 5 | clean-build: ## remove build artifacts 6 | rm -fr build/ 7 | rm -fr dist/ 8 | rm -fr .eggs/ 9 | find . -name '*.egg-info' -exec rm -fr {} + 10 | find . -name '*.egg' -exec rm -rf {} + 11 | 12 | clean-pyc: ## remove Python file artifacts 13 | find . -name '*.pyc' -exec rm -f {} + 14 | find . -name '*.pyo' -exec rm -f {} + 15 | find . -name '*~' -exec rm -f {} + 16 | find . -name '__pycache__' -exec rm -fr {} + 17 | 18 | clean-test: ## remove test and coverage artifacts 19 | rm -fr .tox/ 20 | rm -f .coverage 21 | rm -fr htmlcov/ 22 | rm -fr .mypy_cache 23 | rm -fr .pytest_cache 24 | 25 | 26 | black: 27 | black -l 90 turfpy tests 28 | isort --atomic . 29 | 30 | typing: 31 | pytest -v -s --mypy turfpy 32 | 33 | lint: 34 | isort --check --diff turfpy tests 35 | flake8 -v --statistics --count turfpy 36 | black -l 90 --diff --check turfpy tests 37 | 38 | test: 39 | pytest -v -s --cov=turfpy tests 40 | coverage html -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Turfpy 2 | [![Build Status](https://travis-ci.com/omanges/turfpy.svg?branch=master)](https://travis-ci.com/omanges/turfpy) 3 | [![PyPI](https://img.shields.io/pypi/v/turfpy)](https://pypi.org/project/turfpy/) 4 | [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/turfpy)](https://pypi.org/project/turfpy/) 5 | [![PyPI - Status](https://img.shields.io/pypi/status/turfpy)](https://pypi.org/project/turfpy/) 6 | [![PyPI - License](https://img.shields.io/pypi/l/turfpy)](https://pypi.org/project/turfpy/) 7 | [![Total alerts](https://img.shields.io/lgtm/alerts/g/omanges/turfpy.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/omanges/turfpy/alerts/) 8 | [![code quality: python](https://img.shields.io/lgtm/grade/python/g/omanges/turfpy.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/omanges/turfpy/context:python) 9 | [![Downloads](https://pepy.tech/badge/turfpy/month)](https://pepy.tech/project/turfpy) 10 | [![Conda (channel only)](https://img.shields.io/conda/vn/conda-forge/turfpy)](https://anaconda.org/conda-forge/turfpy) 11 | [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/turfpy)](https://anaconda.org/conda-forge/turfpy) 12 | [![Join the Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/turfpy/turfpy-user-group?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 13 | [![Documentation Status](https://readthedocs.org/projects/turfpy/badge/?version=latest)](https://turfpy.readthedocs.io/en/latest/?badge=latest) 14 | [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) 15 | [![commits since](https://img.shields.io/github/commits-since/omanges/turfpy/latest.svg)](https://github.com/omanges/turfpy/commits/master) 16 | [![GitHub contributors](https://img.shields.io/github/contributors/omanges/turfpy)](https://github.com/omanges/turfpy/graphs/contributors) 17 | 18 | Demo: 19 | 20 | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/omanges/turfpy/master?urlpath=lab/tree/examples) 21 | 22 | 23 | A Python library for performing geospatial data analysis which reimplements turf.js. 24 | 25 | ## Installation 26 | 27 | You can install the Turfpy from [PyPI](https://pypi.org/project/turfpy/): 28 | 29 | pip install turfpy 30 | 31 | If you prefer to use [conda](https://anaconda.org/conda-forge/turfpy): 32 | 33 | conda install -c conda-forge turfpy 34 | 35 | ## Test Suite 36 | 37 | You can run the test suite locally: 38 | 39 | ```bash 40 | pip install -r dev_requirements.txt 41 | pytest -s -v --cov=turfpy tests 42 | ``` 43 | 44 | ## Features 45 | It supports below features: 46 | 47 | - [Measurements](https://github.com/omanges/turfpy/blob/master/measurements.md) 48 | 49 | - [Transformations](https://github.com/omanges/turfpy/blob/master/transformation.md) 50 | 51 | - [Misc](https://github.com/omanges/turfpy/blob/master/misc.md) 52 | 53 | - [Random](https://github.com/omanges/turfpy/blob/master/random.md) 54 | 55 | - [Feature Conversion](https://github.com/omanges/turfpy/blob/master/feature_conversion.md) 56 | 57 | - [Boolean](https://github.com/omanges/turfpy/blob/master/boolean.md) 58 | 59 | ## Documentation 60 | 61 | Documentation can be found at: [docs](https://turfpy.readthedocs.io/en/latest/) 62 | 63 | 64 | -------------------------------------------------------------------------------- /boolean.md: -------------------------------------------------------------------------------- 1 | ## Boolean Examples : 2 | * boolean_disjoint : Takes two features and returns (TRUE) if the two geometries do not touch or overlap. 3 | 4 | | Argument| Type | Description| 5 | | ------- |------ | ----------- | 6 | | `feature_1` |Feature | Feature 1 | 7 | | `feature_2` |Feature | Feature 2 | 8 | 9 | 10 | | Return | Type | Description | 11 | | ------- | ------ | ----------- | 12 | | `bool` | bool | Return true or false | 13 | 14 | ```python 15 | from geojson import Feature, Point 16 | from turfpy.boolean import boolean_disjoint 17 | 18 | feature_1 = Feature(geometry=Point((19.0760, 72.8777))) 19 | feature_2 = Feature(geometry=Point((29.0760, 72.8777))) 20 | boolean_disjoint(feature_1, feature_2) 21 | ``` 22 | 23 | * boolean_intersects : Takes two features and returns (TRUE) if the intersection of the two geometries is NOT an empty set. 24 | 25 | | Argument| Type | Description| 26 | | ------- |------ | ----------- | 27 | | `feature_1` |Feature | Feature 1 | 28 | | `feature_2` |Feature | Feature 2 | 29 | 30 | | Return | Type | Description | 31 | | ------- | ------ | ----------- | 32 | | `bool` | bool | Return true or false | 33 | 34 | ```python 35 | from geojson import Feature, Point 36 | from turfpy.boolean import boolean_intersects 37 | 38 | feature_1 = Feature(geometry=Point((19.0760, 72.8777))) 39 | feature_2 = Feature(geometry=Point((29.0760, 72.8777))) 40 | boolean_intersects(feature_1, feature_2) 41 | ``` -------------------------------------------------------------------------------- /conftest.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omanges/turfpy/db510553a6166f6e4b4c5d6ec44bc53d02086657/conftest.py -------------------------------------------------------------------------------- /dev_requirements.txt: -------------------------------------------------------------------------------- 1 | #test 2 | pytest==8.3.3 3 | mypy==1.13.0 4 | coverage==7.6.4 5 | black==24.10.0 6 | pytest-cov==6.0.0 7 | pytest-mypy==0.10.3 8 | pytest-flake8==1.2.2 9 | isort==5.13.2 10 | Sphinx==8.1.3 11 | sphinx-rtd-theme==3.0.1 12 | jupyter-sphinx==0.5.3 13 | ipyleaflet==0.19.2 -------------------------------------------------------------------------------- /docs/source/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/source/boolean/boolean_disjoint.rst: -------------------------------------------------------------------------------- 1 | Boolean Disjoint 2 | ================= 3 | Takes two features and returns (TRUE) if the two geometries do not touch or overlap. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from geojson import Feature, Point 11 | from turfpy.boolean import boolean_disjoint 12 | 13 | feature_1 = Feature(geometry=Point((19.0760, 72.8777))) 14 | feature_2 = Feature(geometry=Point((29.0760, 72.8777))) 15 | boolean_disjoint(feature_1, feature_2) 16 | 17 | -------------------------------------------------------------------------------- /docs/source/boolean/boolean_intersects.rst: -------------------------------------------------------------------------------- 1 | Boolean Intersects 2 | ================== 3 | Takes two features and returns (TRUE) if the intersection of the two geometries is NOT an empty set. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from geojson import Feature, Point 11 | from turfpy.boolean import boolean_intersects 12 | 13 | feature_1 = Feature(geometry=Point((19.0760, 72.8777))) 14 | feature_2 = Feature(geometry=Point((29.0760, 72.8777))) 15 | boolean_intersects(feature_1, feature_2) 16 | 17 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | import os 14 | import sys 15 | 16 | import sphinx_rtd_theme 17 | 18 | # sys.path.insert(0, os.path.abspath('.')) 19 | current_dir = os.path.dirname(__file__) 20 | target_dir = os.path.abspath(os.path.join(current_dir, "../..")) 21 | sys.path.insert(0, target_dir) 22 | 23 | 24 | # -- Project information ----------------------------------------------------- 25 | 26 | project = 'turfpy' 27 | copyright = '2020, Omkar Mestry, Sachin Kharude' 28 | author = 'Omkar Mestry, Sachin Kharude' 29 | 30 | 31 | # -- General configuration --------------------------------------------------- 32 | 33 | # Add any Sphinx extension module names here, as strings. They can be 34 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 35 | # ones. 36 | extensions = [ 37 | 'sphinx.ext.coverage', 38 | 'sphinx.ext.autodoc', 39 | 'sphinx.ext.viewcode', 40 | 'sphinx.ext.doctest', 41 | 'jupyter_sphinx', 42 | ] 43 | 44 | # Add any paths that contain templates here, relative to this directory. 45 | templates_path = ['_templates'] 46 | 47 | 48 | def setup(app): 49 | app.add_css_file("main_stylesheet.css") 50 | 51 | 52 | # List of patterns, relative to source directory, that match files and 53 | # directories to ignore when looking for source files. 54 | # This pattern also affects html_static_path and html_extra_path. 55 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 56 | 57 | 58 | # -- Options for HTML output ------------------------------------------------- 59 | 60 | # The theme to use for HTML and HTML Help pages. See the documentation for 61 | # a list of builtin themes. 62 | # 63 | # html_theme = 'alabaster' 64 | 65 | # Add any paths that contain custom static files (such as style sheets) here, 66 | # relative to this directory. They are copied after the builtin static files, 67 | # so a file named "default.css" will overwrite the builtin "default.css". 68 | html_static_path = ['_static'] 69 | highlight_language = 'python' 70 | pygments_style = 'sphinx' 71 | 72 | # Output file base name for HTML help builder. 73 | html_theme = "sphinx_rtd_theme" 74 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] 75 | htmlhelp_basename = 'turfpydoc' 76 | 77 | 78 | # -- Extension configuration ------------------------------------------------- 79 | # If true, `todo` and `todoList` produce output, else they produce nothing. 80 | todo_include_todos = True 81 | autodoc_typehints = "description" 82 | 83 | # -- autodoc options configuration ------------------------------------------------- 84 | 85 | autodoc_default_options = { 86 | 'members': True, 87 | 'undoc-members': True, 88 | 'special-members': True, 89 | 'show-inheritance': True, 90 | 'member-order': 'bysource', 91 | 'exclude-members': '__dict__,__weakref__,__module__' 92 | } 93 | -------------------------------------------------------------------------------- /docs/source/feature_conversion/polygon_to_line.rst: -------------------------------------------------------------------------------- 1 | Polygon to Line 2 | ================ 3 | Takes a Polygon or MultiPolygon and convert it to a line. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from geojson import Feature, Polygon 11 | from turfpy.feature_conversion import polygon_to_line 12 | 13 | feature_1 = Feature(geometry=Polygon([[(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15), (2.38, 57.322)]])) 14 | polygon_to_line(feature_1) 15 | 16 | Interactive Example 17 | ------------------- 18 | 19 | .. jupyter-execute:: 20 | 21 | from turfpy.feature_conversion import polygon_to_line 22 | from geojson import Polygon 23 | from geojson import Feature 24 | from ipyleaflet import Map, WidgetControl 25 | from ipywidgets import HTML 26 | 27 | feature_1 = Feature(geometry=Polygon([[(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15), (2.38, 57.322)]])) 28 | 29 | geo_json = polygon_to_line(feature_1) 30 | 31 | m = Map(center=[20.04303061200023, -11.832275390625002], zoom=2) 32 | 33 | m.add_layer(geo_json) 34 | 35 | html = HTML() 36 | html.layout.margin = "0px 20px 10px 20px" 37 | html.value = """ 38 |

Polygon to Line for given geojson

39 |

{}

40 | """.format( 41 | geo_json 42 | ) 43 | control = WidgetControl(widget=html, position="topright") 44 | m.add_control(control) 45 | 46 | m 47 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. turfpy documentation master file, created by 2 | sphinx-quickstart on Sun Oct 4 20:41:55 2020. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Documentation of Turfpy 7 | ======================= 8 | A Python library for performing geospatial data analysis which reimplements `turf.js`_. 9 | 10 | .. _turf.js: https://turfjs.org/docs/ 11 | 12 | 13 | .. toctree:: 14 | :maxdepth: 1 15 | :caption: Getting Started 16 | 17 | Installation 18 | 19 | .. toctree:: 20 | :maxdepth: 1 21 | :caption: Measurements 22 | 23 | Bearing 24 | Distance 25 | Area 26 | Bbox 27 | Bbox Polygon 28 | Center 29 | Envelop 30 | Length 31 | Destination 32 | Centroid 33 | Along 34 | Midpoint 35 | Nearest Point 36 | Point On Feature 37 | Point In Polygon 38 | Point To Line Distance 39 | Rhumb Bearing 40 | Rhumb Destination 41 | Rhumb Distance 42 | Square 43 | Points within Polygon 44 | 45 | 46 | .. toctree:: 47 | :maxdepth: 1 48 | :caption: Transformations 49 | 50 | Circle 51 | Bbox Clip 52 | Bezier spline 53 | Concave Hull 54 | Convex Hull 55 | Intersect 56 | Union 57 | Dissolve 58 | Difference 59 | Transform Rotate 60 | Transform Translate 61 | Transform Scale 62 | Tesselate 63 | Line Offset 64 | Voronoi 65 | 66 | .. toctree:: 67 | :maxdepth: 1 68 | :caption: Boolean 69 | 70 | Boolean Disjoint 71 | Boolean Intersects 72 | 73 | .. toctree:: 74 | :maxdepth: 1 75 | :caption: Feature Conversion 76 | 77 | Polygon To Line 78 | 79 | .. toctree:: 80 | :maxdepth: 1 81 | :caption: Misc 82 | 83 | Line Intersect 84 | Line Segment 85 | Line Arc 86 | Sector 87 | 88 | .. toctree:: 89 | :maxdepth: 1 90 | :caption: Random 91 | 92 | Random Position 93 | Random Points 94 | 95 | 96 | .. toctree:: 97 | :maxdepth: 1 98 | :caption: Reference Guide 99 | 100 | API Reference 101 | 102 | 103 | 104 | Indices and tables 105 | ================== 106 | 107 | * :ref:`genindex` 108 | * :ref:`modindex` 109 | * :ref:`search` 110 | -------------------------------------------------------------------------------- /docs/source/install.rst: -------------------------------------------------------------------------------- 1 | Installation 2 | ============ 3 | 4 | Using pip 5 | --------- 6 | 7 | .. code:: bash 8 | 9 | pip install turfpy 10 | 11 | Using conda 12 | ----------- 13 | 14 | .. code:: bash 15 | 16 | conda install -c conda-forge turfpy -------------------------------------------------------------------------------- /docs/source/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/source/measurements/along.rst: -------------------------------------------------------------------------------- 1 | Along 2 | ===== 3 | This function is used identify a Point at a specified distance along a LineString. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | import json 11 | from turfpy.measurement import along 12 | from geojson import LineString 13 | ls = LineString([(-83, 30), (-84, 36), (-78, 41)]) 14 | print(json.dumps(along(ls,200,'mi'), indent=2, sort_keys=True)) 15 | 16 | 17 | 18 | Interactive Example 19 | ------------------- 20 | 21 | .. jupyter-execute:: 22 | 23 | from turfpy.measurement import along, length 24 | from geojson import LineString, Feature 25 | from ipyleaflet import Map, GeoJSON, WidgetControl, Marker 26 | from ipywidgets import FloatSlider 27 | 28 | ls = LineString([(-83, 30), (-84, 36), (-78, 41)]) 29 | 30 | 31 | m = Map(center=[35.47241402319959, -80.11693954467775], zoom=5) 32 | marker = Marker(location=[30, -83]) 33 | m.add_layer(marker) 34 | 35 | 36 | def on_value_change(change): 37 | global marker 38 | new_point = along(ls, change["new"], "mi") 39 | marker.location = new_point["geometry"]["coordinates"][::-1] 40 | 41 | 42 | style = {"description_width": "initial"} 43 | slider = FloatSlider( 44 | description="Marker position:", 45 | min=0, 46 | max=length(ls, units="mi"), 47 | value=0, 48 | style=style, 49 | ) 50 | slider.observe(on_value_change, names="value") 51 | 52 | widget_control1 = WidgetControl(widget=slider, position="topright") 53 | m.add_control(widget_control1) 54 | 55 | 56 | geo_json = GeoJSON(name="Geojson", data=Feature(geometry=ls)) 57 | 58 | m.add_layer(geo_json) 59 | 60 | m 61 | 62 | -------------------------------------------------------------------------------- /docs/source/measurements/area.rst: -------------------------------------------------------------------------------- 1 | Area 2 | ===== 3 | Calculates the area of the input GeoJSON object. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from turfpy.measurement import area 11 | from geojson import Feature, FeatureCollection 12 | 13 | geometry_1 = { 14 | "coordinates": [[[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]], 15 | "type": "Polygon", 16 | } 17 | geometry_2 = { 18 | "coordinates": [ 19 | [[2.38, 57.322], [23.194, -20.28], [-120.43, 19.15], [2.38, 57.322]] 20 | ], 21 | "type": "Polygon", 22 | } 23 | feature_1 = Feature(geometry=geometry_1) 24 | feature_2 = Feature(geometry=geometry_2) 25 | feature_collection = FeatureCollection([feature_1, feature_2]) 26 | 27 | area(feature_collection) 28 | 29 | 30 | Interactive Example 31 | ------------------- 32 | 33 | .. jupyter-execute:: 34 | 35 | from turfpy.measurement import area 36 | from geojson import Feature, FeatureCollection 37 | from ipyleaflet import Map, GeoJSON, basemaps, basemap_to_tiles, WidgetControl 38 | from ipywidgets import HTML 39 | 40 | geometry_1 = { 41 | "coordinates": [[[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]], 42 | "type": "Polygon", 43 | } 44 | geometry_2 = { 45 | "coordinates": [ 46 | [[2.38, 57.322], [23.194, -20.28], [-120.43, 19.15], [2.38, 57.322]] 47 | ], 48 | "type": "Polygon", 49 | } 50 | feature_1 = Feature(geometry=geometry_1) 51 | feature_2 = Feature(geometry=geometry_2) 52 | feature_collection = FeatureCollection([feature_1, feature_2]) 53 | geo_json = GeoJSON(data=feature_collection) 54 | mapnik = basemap_to_tiles(basemaps.OpenStreetMap.Mapnik) 55 | 56 | m = Map(layers=(mapnik,), center=[20.04303061200023, -11.832275390625002], zoom=2) 57 | 58 | m.add_layer(geo_json) 59 | 60 | html = HTML() 61 | html.layout.margin = "0px 20px 10px 20px" 62 | html.value = """ 63 |

Area in meter sqaure: {}

64 |

measurement.area(feature_collection)

65 | """.format( 66 | area(feature_collection) 67 | ) 68 | control = WidgetControl(widget=html, position="topright") 69 | m.add_control(control) 70 | m 71 | -------------------------------------------------------------------------------- /docs/source/measurements/bbox.rst: -------------------------------------------------------------------------------- 1 | Bbox 2 | ===== 3 | Generate bounding box coordinates for given geojson. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from turfpy.measurement import bbox 11 | from geojson import Polygon 12 | 13 | p = Polygon([[(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15), (2.38, 57.322)]]) 14 | bbox(p) 15 | 16 | 17 | Interactive Example 18 | ------------------- 19 | 20 | .. jupyter-execute:: 21 | 22 | from turfpy.measurement import bbox 23 | from geojson import Polygon 24 | from geojson import Feature 25 | from ipyleaflet import Map, GeoJSON, WidgetControl 26 | from ipywidgets import HTML 27 | 28 | p = Polygon([[(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15), (2.38, 57.322)]]) 29 | 30 | 31 | geo_json = GeoJSON(data=Feature(geometry=p)) 32 | 33 | m = Map(center=[20.04303061200023, -11.832275390625002], zoom=2) 34 | 35 | m.add_layer(geo_json) 36 | 37 | html = HTML() 38 | html.layout.margin = "0px 20px 10px 20px" 39 | html.value = """ 40 |

Bounding Box for given geojson

41 |

{}

42 | """.format( 43 | bbox(p) 44 | ) 45 | control = WidgetControl(widget=html, position="topright") 46 | m.add_control(control) 47 | 48 | m -------------------------------------------------------------------------------- /docs/source/measurements/bbox_polygon.rst: -------------------------------------------------------------------------------- 1 | Bbox Polygon 2 | ============ 3 | Generate a Polygon Feature for the bounding box generated using bbox. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | 13 | from turfpy.measurement import bbox_polygon, bbox 14 | from geojson import Polygon 15 | 16 | p = Polygon([[(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15), (2.38, 57.322)]]) 17 | bb = bbox(p) 18 | print(json.dumps(bbox_polygon(bb), indent=2, sort_keys=True)) 19 | 20 | 21 | Interactive Example 22 | ------------------- 23 | 24 | .. jupyter-execute:: 25 | 26 | from turfpy.measurement import bbox_polygon, bbox 27 | from geojson import Polygon, Feature 28 | from ipyleaflet import Map, GeoJSON, WidgetControl, LayersControl 29 | 30 | p = Polygon([[(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15), (2.38, 57.322)]]) 31 | bb = bbox(p) 32 | geo_json = GeoJSON(name="Geojson", data=Feature(geometry=p)) 33 | bbox_polygon_geojson = GeoJSON( 34 | name="Bounding Box Polygon", data=bbox_polygon(bb), style={"color": "red"} 35 | ) 36 | 37 | m = Map(center=[20.04303061200023, -11.832275390625002], zoom=2) 38 | 39 | control = LayersControl(position="topright") 40 | m.add_control(control) 41 | 42 | m.add_layer(geo_json) 43 | m.add_layer(bbox_polygon_geojson) 44 | m 45 | 46 | -------------------------------------------------------------------------------- /docs/source/measurements/bearing.rst: -------------------------------------------------------------------------------- 1 | Bearing 2 | ======= 3 | Takes two Points and finds the geographic bearing between them. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from turfpy import measurement 11 | from geojson import Point, Feature 12 | 13 | start = Feature(geometry=Point((-75.343, 39.984))) 14 | end = Feature(geometry=Point((-75.534, 39.123))) 15 | measurement.bearing(start, end) -------------------------------------------------------------------------------- /docs/source/measurements/center.rst: -------------------------------------------------------------------------------- 1 | Center 2 | ====== 3 | Takes a Feature or FeatureCollection and returns the absolute center point of all features. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | import json 11 | from turfpy.measurement import center 12 | from geojson import Feature, FeatureCollection, Point 13 | 14 | f1 = Feature(geometry=Point((-97.522259, 35.4691))) 15 | f2 = Feature(geometry=Point((-97.502754, 35.463455))) 16 | f3 = Feature(geometry=Point((-97.508269, 35.463245))) 17 | feature_collection = FeatureCollection([f1, f2, f3]) 18 | print(json.dumps(center(feature_collection), indent=2, sort_keys=True)) 19 | 20 | 21 | 22 | 23 | Interactive Example 24 | ------------------- 25 | 26 | .. jupyter-execute:: 27 | 28 | from turfpy.measurement import center 29 | from geojson import Feature, FeatureCollection, Point 30 | from ipyleaflet import Map, GeoJSON, WidgetControl, LayersControl, CircleMarker 31 | 32 | f1 = Feature(geometry=Point((-97.522259, 35.4691))) 33 | f2 = Feature(geometry=Point((-97.502754, 35.463455))) 34 | f3 = Feature(geometry=Point((-97.508269, 35.463245))) 35 | feature_collection = FeatureCollection([f1, f2, f3]) 36 | 37 | m = Map(center=[35.467146770097315, -97.50865470618012], zoom=15) 38 | 39 | geo_json = GeoJSON(name="Geojson", data=feature_collection) 40 | 41 | centre_coord = center(feature_collection)["geometry"]["coordinates"] 42 | circle_marker = CircleMarker(name="Center") 43 | circle_marker.location = (centre_coord[1], centre_coord[0]) 44 | circle_marker.radius = 30 45 | circle_marker.color = "red" 46 | 47 | control = LayersControl(position="topright") 48 | m.add_control(control) 49 | 50 | m.add_layer(geo_json) 51 | m.add_layer(circle_marker) 52 | m 53 | 54 | -------------------------------------------------------------------------------- /docs/source/measurements/centroid.rst: -------------------------------------------------------------------------------- 1 | Centroid 2 | ======== 3 | Takes one or more features and calculates the centroid using the mean of all vertices. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.measurement import centroid 13 | from geojson import Polygon 14 | polygon = Polygon([[(-81, 41), (-88, 36), (-84, 31), (-80, 33), (-77, 39), (-81, 41)]]) 15 | print(json.dumps(centroid(polygon), indent=2, sort_keys=True)) 16 | 17 | 18 | Interactive Example 19 | ------------------- 20 | 21 | .. jupyter-execute:: 22 | 23 | from turfpy.measurement import centroid 24 | from geojson import Polygon, Feature 25 | from ipyleaflet import Map, GeoJSON, WidgetControl, LayersControl 26 | 27 | polygon = Polygon([[(-81, 41), (-88, 36), (-84, 31), (-80, 33), (-77, 39), (-81, 41)]]) 28 | 29 | m = Map(center=[36.198988385375806, -79.6392059326172], zoom=5) 30 | 31 | geo_json = GeoJSON(name="Geojson", data=Feature(geometry=polygon)) 32 | centroid_geojson = GeoJSON(name="Centroid", data=centroid(polygon)) 33 | 34 | control = LayersControl(position="topright") 35 | m.add_control(control) 36 | 37 | m.add_layer(geo_json) 38 | m.add_layer(centroid_geojson) 39 | m 40 | 41 | -------------------------------------------------------------------------------- /docs/source/measurements/destination.rst: -------------------------------------------------------------------------------- 1 | Destination 2 | =========== 3 | Takes a Point and calculates the location of a destination point given a distance in degrees, radians, miles, or kilometers and bearing in degrees. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.measurement import destination 13 | from geojson import Point, Feature 14 | 15 | origin = Feature(geometry=Point([-75.343, 39.984])) 16 | distance = 50 17 | bearing = 90 18 | options = {'units': 'mi'} 19 | print(json.dumps(destination(origin,distance,bearing,options), indent=2, sort_keys=True)) 20 | 21 | 22 | Interactive Example 23 | ------------------- 24 | 25 | .. jupyter-execute:: 26 | 27 | from turfpy.measurement import destination 28 | from geojson import Point, Feature 29 | from ipyleaflet import Map, GeoJSON, WidgetControl, LayersControl, CircleMarker 30 | from ipywidgets import HTML 31 | 32 | origin = Feature(geometry=Point([-75.343, 39.984])) 33 | distance = 50 34 | bearing = 90 35 | options = {"units": "mi"} 36 | 37 | m = Map(center=[39.98304755619415, -74.67888951301576], zoom=9) 38 | 39 | 40 | geo_json = GeoJSON(name="Start Point", data=origin) 41 | 42 | centre_coord = destination(origin, distance, bearing, options)["geometry"][ 43 | "coordinates" 44 | ] 45 | circle_marker = CircleMarker(name="End Point") 46 | circle_marker.location = (centre_coord[1], centre_coord[0]) 47 | circle_marker.radius = 10 48 | circle_marker.color = "red" 49 | 50 | 51 | m.add_layer(geo_json) 52 | m.add_layer(circle_marker) 53 | 54 | html = HTML() 55 | html.layout.margin = "0px 20px 10px 20px" 56 | html.value = """ 57 |

Point which is at 90 degrees bearing and 50 miles in that direction

58 | """ 59 | 60 | control = WidgetControl(widget=html, position="topright") 61 | m.add_control(control) 62 | 63 | control = LayersControl(position="topright") 64 | m.add_control(control) 65 | 66 | m 67 | 68 | -------------------------------------------------------------------------------- /docs/source/measurements/distance.rst: -------------------------------------------------------------------------------- 1 | Distance 2 | ======== 3 | Calculates distance between two Points. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from turfpy import measurement 11 | from geojson import Point, Feature 12 | start = Feature(geometry=Point((-75.343, 39.984))) 13 | end = Feature(geometry=Point((-75.534, 39.123))) 14 | measurement.distance(start,end) 15 | -------------------------------------------------------------------------------- /docs/source/measurements/envelop.rst: -------------------------------------------------------------------------------- 1 | Envelop 2 | ======= 3 | Takes any number of features and returns a rectangular Polygon that encompasses all vertices. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.measurement import envelope 13 | from geojson import Feature, FeatureCollection, Point 14 | 15 | f1 = Feature(geometry=Point((-97.522259, 35.4691))) 16 | f2 = Feature(geometry=Point((-97.502754, 35.463455))) 17 | f3 = Feature(geometry=Point((-97.508269, 35.463245))) 18 | feature_collection = FeatureCollection([f1, f2, f3]) 19 | print(json.dumps(envelope(feature_collection), indent=2, sort_keys=True)) 20 | 21 | 22 | Interactive Example 23 | ------------------- 24 | 25 | .. jupyter-execute:: 26 | 27 | from turfpy.measurement import envelope 28 | from geojson import Feature, FeatureCollection, Point 29 | from ipyleaflet import Map, GeoJSON, WidgetControl, LayersControl 30 | 31 | f1 = Feature(geometry=Point((-97.522259, 35.4691))) 32 | f2 = Feature(geometry=Point((-97.502754, 35.463455))) 33 | f3 = Feature(geometry=Point((-97.508269, 35.463245))) 34 | feature_collection = FeatureCollection([f1, f2, f3]) 35 | 36 | 37 | m = Map(center=[35.467146770097315, -97.50865470618012], zoom=15) 38 | 39 | geo_json = GeoJSON(name="Geojson", data=feature_collection) 40 | envelope_geojson = GeoJSON( 41 | name="Envelope", data=envelope(feature_collection), style={"color": "red"} 42 | ) 43 | 44 | control = LayersControl(position="topright") 45 | m.add_control(control) 46 | 47 | m.add_layer(geo_json) 48 | m.add_layer(envelope_geojson) 49 | m 50 | 51 | -------------------------------------------------------------------------------- /docs/source/measurements/length.rst: -------------------------------------------------------------------------------- 1 | Area 2 | ===== 3 | Takes a geojson and measures its length in the specified units. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from turfpy.measurement import length 11 | from geojson import LineString 12 | ls = LineString([(115, -32), (131, -22), (143, -25), (150, -34)]) 13 | length(ls) 14 | 15 | 16 | 17 | 18 | Interactive Example 19 | ------------------- 20 | 21 | .. jupyter-execute:: 22 | 23 | from turfpy.measurement import length 24 | from geojson import LineString, Feature 25 | from ipyleaflet import Map, GeoJSON, WidgetControl 26 | from ipywidgets import HTML 27 | 28 | ls = LineString([(115, -32), (131, -22), (143, -25), (150, -34)]) 29 | 30 | m = Map(center=[-25.52664223616833, 143.44917297363284], zoom=4) 31 | 32 | geo_json = GeoJSON(name="Geojson", data=Feature(geometry=ls)) 33 | 34 | m.add_layer(geo_json) 35 | 36 | html = HTML() 37 | html.layout.margin = "0px 20px 10px 20px" 38 | html.value = """ 39 |

Length of the given geojson in meters

40 |

{}

41 | """.format( 42 | length(ls, units="m") 43 | ) 44 | 45 | control = WidgetControl(widget=html, position="topright") 46 | m.add_control(control) 47 | 48 | m 49 | 50 | -------------------------------------------------------------------------------- /docs/source/measurements/midpoint.rst: -------------------------------------------------------------------------------- 1 | Midpoint 2 | ======== 3 | Get midpoint between any the two points. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.measurement import midpoint 13 | from geojson import Point, Feature 14 | point1 = Feature(geometry=Point([144.834823, -37.771257])) 15 | point2 = Feature(geometry=Point([145.14244, -37.830937])) 16 | print(json.dumps(midpoint(point1, point2), indent=2, sort_keys=True)) 17 | 18 | 19 | 20 | Interactive Example 21 | ------------------- 22 | 23 | .. jupyter-execute:: 24 | 25 | from turfpy.measurement import midpoint 26 | from geojson import Point, Feature 27 | from ipyleaflet import Map, GeoJSON, LayersControl, CircleMarker 28 | 29 | 30 | point1 = Feature(geometry=Point([144.834823, -37.771257])) 31 | point2 = Feature(geometry=Point([145.14244, -37.830937])) 32 | 33 | m = Map(center=[-37.80415546165204, 145.0286749005318], zoom=11) 34 | 35 | start_geo_json = GeoJSON(name="Start Point", data=point1) 36 | end_geo_json = GeoJSON(name="End Point", data=point2) 37 | m.add_layer(start_geo_json) 38 | m.add_layer(end_geo_json) 39 | 40 | midpoint_coord = midpoint(point1, point2)["geometry"]["coordinates"] 41 | circle_marker = CircleMarker(name="Midpoint") 42 | circle_marker.location = (midpoint_coord[1], midpoint_coord[0]) 43 | circle_marker.radius = 10 44 | circle_marker.color = "red" 45 | m.add_layer(circle_marker) 46 | 47 | control = LayersControl(position="topright") 48 | m.add_control(control) 49 | 50 | m 51 | 52 | -------------------------------------------------------------------------------- /docs/source/measurements/nearest_point.rst: -------------------------------------------------------------------------------- 1 | Nearest Point 2 | ============= 3 | Takes a reference Point Feature and FeatureCollection of point features and returns the point from the FeatureCollection closest to the reference Point Feature. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.measurement import nearest_point 13 | from geojson import Point, Feature, FeatureCollection 14 | f1 = Feature(geometry=Point([28.96991729736328,41.01190001748873])) 15 | f2 = Feature(geometry=Point([28.948459, 41.024204])) 16 | f3 = Feature(geometry=Point([28.938674, 41.013324])) 17 | fc = FeatureCollection([f1, f2 ,f3]) 18 | t = Feature(geometry=Point([28.973865, 41.011122])) 19 | print(json.dumps(nearest_point(t ,fc), indent=2, sort_keys=True)) 20 | 21 | 22 | 23 | Interactive Example 24 | ------------------- 25 | 26 | .. jupyter-execute:: 27 | 28 | from turfpy.measurement import nearest_point 29 | from geojson import Point, Feature, FeatureCollection 30 | from ipyleaflet import Map, GeoJSON, LayersControl 31 | 32 | f1 = Feature(geometry=Point([28.96991729736328, 41.01190001748873])) 33 | f2 = Feature(geometry=Point([28.948459, 41.024204])) 34 | f3 = Feature(geometry=Point([28.938674, 41.013324])) 35 | fc = FeatureCollection([f1, f2, f3]) 36 | t = Feature(geometry=Point([28.973865, 41.011122])) 37 | 38 | 39 | m = Map(center=[41.01656246584522, 28.959988430142406], zoom=14) 40 | 41 | geo_json = GeoJSON(name="Feature Collection", data=FeatureCollection([f2, f3])) 42 | 43 | ref_geo_json = GeoJSON(name="Reference Point", data=t) 44 | 45 | m.add_layer(geo_json) 46 | 47 | m.add_layer(ref_geo_json) 48 | 49 | near_geojson = GeoJSON(name="Nearest Point", data=nearest_point(t, fc)) 50 | m.add_layer(near_geojson) 51 | 52 | control = LayersControl(position="topright") 53 | m.add_control(control) 54 | 55 | m 56 | 57 | -------------------------------------------------------------------------------- /docs/source/measurements/point_in_polygon.rst: -------------------------------------------------------------------------------- 1 | Point In Polygon 2 | ================ 3 | Takes a Point or a Point Feature and Polygon or Polygon Feature as input and returns True if Point is in given Feature. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | from turfpy.measurement import boolean_point_in_polygon 12 | from geojson import Point, MultiPolygon, Feature 13 | point = Feature(geometry=Point([-77, 44])) 14 | polygon = Feature(geometry=MultiPolygon([([(-81, 41), (-81, 47), (-72, 47), (-72, 41), (-81, 41)],), 15 | ([(3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28)],)])) 16 | boolean_point_in_polygon(point, polygon) 17 | 18 | 19 | 20 | 21 | Interactive Example 22 | ------------------- 23 | 24 | .. jupyter-execute:: 25 | 26 | from turfpy.measurement import boolean_point_in_polygon 27 | from geojson import Point, MultiPolygon, Feature 28 | from ipyleaflet import Map, GeoJSON, LayersControl 29 | 30 | point = Feature(geometry=Point([-77, 44])) 31 | polygon = Feature( 32 | geometry=MultiPolygon( 33 | [ 34 | ([(-81, 41), (-81, 47), (-72, 47), (-72, 41), (-81, 41)],), 35 | ([(3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28)],), 36 | ] 37 | ) 38 | ) 39 | boolean_point_in_polygon(point, polygon) 40 | 41 | m = Map(center=[46.57868671298067, -40.91583251953126], zoom=2) 42 | 43 | geo_json = GeoJSON(name="MultiPolygon Feature", data=polygon) 44 | 45 | m.add_layer(geo_json) 46 | 47 | point_geojson = GeoJSON(name="Point in Polygon", data=point) 48 | 49 | m.add_layer(point_geojson) 50 | 51 | control = LayersControl(position="topright") 52 | m.add_control(control) 53 | 54 | m 55 | 56 | 57 | -------------------------------------------------------------------------------- /docs/source/measurements/point_on_feature.rst: -------------------------------------------------------------------------------- 1 | Point On Feature 2 | ================ 3 | Takes a Feature or FeatureCollection and returns a Point guaranteed to be on the surface of the feature. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.measurement import point_on_feature 13 | from geojson import Polygon, Feature 14 | point = Polygon([[(116, -36), (131, -32), (146, -43), (155, -25), (133, -9), (111, -22), (116, -36)]]) 15 | feature = Feature(geometry=point) 16 | print(json.dumps(point_on_feature(feature), indent=2, sort_keys=True)) 17 | 18 | 19 | 20 | 21 | Interactive Example 22 | ------------------- 23 | 24 | .. jupyter-execute:: 25 | 26 | from turfpy.measurement import point_on_feature 27 | from geojson import Polygon, Feature 28 | from ipyleaflet import Map, GeoJSON, LayersControl 29 | 30 | point = Polygon([[(116, -36), (131, -32), (146, -43), (155, -25), (133, -9), (111, -22), (116, -36)]]) 31 | feature = Feature(geometry=point) 32 | 33 | 34 | m = Map(center=[-25.743003105825967, 135.92525482177737], zoom=4) 35 | 36 | geo_json = GeoJSON(name='Feature', data=feature) 37 | 38 | m.add_layer(geo_json) 39 | 40 | point_geojson = GeoJSON(name='Point on Feature', data=point_on_feature(feature)) 41 | 42 | m.add_layer(point_geojson) 43 | 44 | control = LayersControl(position='topright') 45 | m.add_control(control) 46 | 47 | m 48 | 49 | -------------------------------------------------------------------------------- /docs/source/measurements/point_to_line_distance.rst: -------------------------------------------------------------------------------- 1 | Point To Line Distance 2 | ====================== 3 | Returns the minimum distance between a Point and any segment of the LineString. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | from turfpy.measurement import point_to_line_distance 12 | from geojson import LineString, Point, Feature 13 | point = Feature(geometry=Point([0, 0])) 14 | linestring = Feature(geometry=LineString([(1, 1),(-1, 1)])) 15 | point_to_line_distance(point, linestring) 16 | 17 | 18 | 19 | Interactive Example 20 | ------------------- 21 | 22 | .. jupyter-execute:: 23 | 24 | from turfpy.measurement import point_to_line_distance 25 | from geojson import LineString, Point, Feature 26 | from ipyleaflet import Map, GeoJSON, LayersControl, WidgetControl 27 | from ipywidgets import HTML 28 | 29 | point = Feature(geometry=Point([0, 0])) 30 | linestring = Feature(geometry=LineString([(1, 1),(-1, 1)])) 31 | 32 | m = Map(center=[0.5427636983179688, 0.3891992568969727], zoom=8) 33 | 34 | geo_json = GeoJSON(name='Point', data=point) 35 | 36 | m.add_layer(geo_json) 37 | 38 | point_geojson = GeoJSON(name='Linestring', data=linestring) 39 | 40 | m.add_layer(point_geojson) 41 | 42 | html = HTML() 43 | html.layout.margin = '0px 20px 10px 20px' 44 | html.value = ''' 45 |

Minimum distance between the Point and the LineString in meters

46 |

{}

47 | '''.format(point_to_line_distance(point, linestring, units='m')) 48 | 49 | control = WidgetControl(widget=html, position='topright') 50 | m.add_control(control) 51 | 52 | m 53 | 54 | -------------------------------------------------------------------------------- /docs/source/measurements/points_within_polygon.rst: -------------------------------------------------------------------------------- 1 | Points within Polygon 2 | ===================== 3 | Takes two inputs Point/Points and Polygon(s)/MultiPolygon(s) and returns all the Points with in Polygon(s)/MultiPolygon(s). 4 | 5 | 6 | Interactive Example 7 | ------------------- 8 | 9 | .. jupyter-execute:: 10 | 11 | from geojson import Feature, FeatureCollection, Point, Polygon 12 | from turfpy.measurement import points_within_polygon 13 | from ipyleaflet import Map, GeoJSON 14 | 15 | p1 = Feature(geometry=Point((-46.6318, -23.5523))) 16 | p2 = Feature(geometry=Point((-46.6246, -23.5325))) 17 | p3 = Feature(geometry=Point((-46.6062, -23.5513))) 18 | p4 = Feature(geometry=Point((-46.663, -23.554))) 19 | p5 = Feature(geometry=Point((-46.643, -23.557))) 20 | 21 | points = FeatureCollection([p1, p2, p3, p4, p5]) 22 | 23 | poly = Polygon( 24 | [ 25 | [ 26 | (-46.653, -23.543), 27 | (-46.634, -23.5346), 28 | (-46.613, -23.543), 29 | (-46.614, -23.559), 30 | (-46.631, -23.567), 31 | (-46.653, -23.560), 32 | (-46.653, -23.543), 33 | ] 34 | ] 35 | ) 36 | 37 | m = Map(center=(-23.5523, -46.6318), zoom=13) 38 | fc = FeatureCollection([p1, p2, p3, p4, p5, poly]) 39 | 40 | geo_json = GeoJSON( 41 | data=fc, 42 | style={"opacity": 1, "dashArray": "9", "fillOpacity": 0.3, "weight": 1}, 43 | hover_style={"color": "green", "dashArray": "0", "fillOpacity": 0.5}, 44 | ) 45 | m.add_layer(geo_json) 46 | 47 | result = points_within_polygon(points, poly) 48 | 49 | data = result.copy() 50 | data["features"].append(Feature(geometry=poly)) 51 | 52 | m = Map(center=(-23.5523, -46.6318), zoom=13) 53 | 54 | geo_json2 = GeoJSON( 55 | data=data, 56 | style={"opacity": 1, "dashArray": "9", "fillOpacity": 0.3, "weight": 1}, 57 | hover_style={"color": "green", "dashArray": "0", "fillOpacity": 0.5}, 58 | ) 59 | m.add_layer(geo_json2) 60 | m -------------------------------------------------------------------------------- /docs/source/measurements/rhumb_bearing.rst: -------------------------------------------------------------------------------- 1 | Rhumb Bearing 2 | ============= 3 | Takes two points and finds the bearing angle between them along a Rhumb line i.e. the angle measured in degrees start the north line (0 degrees). 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | from turfpy.measurement import rhumb_bearing 12 | from geojson import Feature, Point 13 | start = Feature(geometry=Point([-75.343, 39.984])) 14 | end = Feature(geometry=Point([-75.534, 39.123])) 15 | rhumb_bearing(start, end, True) 16 | 17 | -------------------------------------------------------------------------------- /docs/source/measurements/rhumb_destination.rst: -------------------------------------------------------------------------------- 1 | Rhumb Destination 2 | ================= 3 | Returns the destination Point having travelled the given distance along a Rhumb line from the origin Point with the (varant) given bearing. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.measurement import rhumb_destination 13 | from geojson import Point, Feature 14 | start = Feature(geometry=Point([-75.343, 39.984]), properties={"marker-color": "F00"}) 15 | distance = 50 16 | bearing = 90 17 | rd = rhumb_destination(start, distance, bearing, {'units':'mi', 'properties': {"marker-color": "F00"}}) 18 | print(json.dumps(rd, indent=2, sort_keys=True)) 19 | -------------------------------------------------------------------------------- /docs/source/measurements/rhumb_distance.rst: -------------------------------------------------------------------------------- 1 | Rhumb Distance 2 | ============== 3 | Calculates the distance along a rhumb line between two points in degrees, radians, miles, or kilometers. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from turfpy.measurement import rhumb_distance 11 | from geojson import Point, Feature 12 | start = Feature(geometry=Point([-75.343, 39.984])) 13 | end = Feature(geometry=Point([-75.534, 39.123])) 14 | rhumb_distance(start, end,'mi') -------------------------------------------------------------------------------- /docs/source/measurements/square.rst: -------------------------------------------------------------------------------- 1 | Square 2 | ====== 3 | Takes a bounding box and calculates the minimum square bounding box that would contain the input. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | from turfpy.measurement import square 12 | bbox = [-20, -20, -15, 0] 13 | square(bbox) 14 | 15 | 16 | 17 | Interactive Example 18 | ------------------- 19 | 20 | .. jupyter-execute:: 21 | 22 | from turfpy.measurement import square, bbox_polygon 23 | from geojson import Point, Feature 24 | from ipyleaflet import Map, GeoJSON, LayersControl 25 | 26 | bbox = [-20, -20, -15, 0] 27 | 28 | sqaure_geo_json = GeoJSON( 29 | name="Sqaure for the given Bounding Box", 30 | data=bbox_polygon(square(bbox)), 31 | style={"color": "red"}, 32 | ) 33 | bbox_polygon_geojson = GeoJSON(name="Bounding Box", data=bbox_polygon(bbox)) 34 | 35 | m = Map(center=[-8.484257262005082, -11.58611297607422], zoom=4) 36 | 37 | control = LayersControl(position="topright") 38 | m.add_control(control) 39 | 40 | m.add_layer(sqaure_geo_json) 41 | m.add_layer(bbox_polygon_geojson) 42 | m -------------------------------------------------------------------------------- /docs/source/misc/line_arc.rst: -------------------------------------------------------------------------------- 1 | Line Arc 2 | ================ 3 | Creates a circular arc, of a circle of the given radius and center point, between bearing1 and bearing2; 0 bearing is North of center point, positive clockwise. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from turfpy.misc import line_arc 11 | from geojson import Feature, Point 12 | 13 | center = Feature(geometry=Point((-75, 40))) 14 | radius = 5 15 | bearing1 = 25 16 | bearing2 = 47 17 | 18 | line_arc(center=center, radius=radius, bearing1=bearing1, bearing2=bearing2) 19 | 20 | 21 | 22 | Interactive Example 23 | ------------------- 24 | 25 | .. jupyter-execute:: 26 | 27 | from ipyleaflet import Map, GeoJSON, LayersControl 28 | from turfpy.misc import line_arc 29 | from geojson import Feature, Point, LineString, FeatureCollection 30 | 31 | center = Feature(geometry=Point((-75, 40))) 32 | radius = 5; 33 | bearing1 = 25; 34 | bearing2 = 47; 35 | 36 | m = Map(center=[40.011313056309056, -74.97720068362348], zoom=12) 37 | 38 | feature = line_arc(center=center, radius=radius, bearing1=bearing1, bearing2=bearing2) 39 | 40 | fc = FeatureCollection([feature, center]) 41 | 42 | layer = GeoJSON(name="Line_Arc", data=fc, style={'color':'red'}) 43 | 44 | m.add_layer(layer) 45 | m 46 | 47 | -------------------------------------------------------------------------------- /docs/source/misc/line_intersect.rst: -------------------------------------------------------------------------------- 1 | Line Intersect 2 | ================ 3 | Takes any LineString or Polygon GeoJSON and returns the intersecting point(s). If one of the Features is polygon pass the polygon feature as the first parameter to improve performance. To use this functionality Rtree or pygeos is needed to be installed. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from geojson import LineString, Feature 11 | from turfpy.misc import line_intersect 12 | l1 = Feature(geometry=LineString([[126, -11], [129, -21]])) 13 | l2 = Feature(geometry=LineString([[123, -18], [131, -14]])) 14 | line_intersect(l1, l2) 15 | 16 | 17 | 18 | Interactive Example 19 | ------------------- 20 | 21 | .. jupyter-execute:: 22 | 23 | from ipyleaflet import Map, GeoJSON 24 | from geojson import LineString, Feature 25 | from turfpy.misc import line_intersect 26 | 27 | m = Map(center=[-15.150511712009196, 127.52157211303712], zoom=5) 28 | 29 | l1 = Feature(geometry=LineString([[126, -11], [129, -21]])) 30 | 31 | l2 = Feature(geometry=LineString([[123, -18], [131, -14]])) 32 | 33 | Line1 = GeoJSON(name="Line1", data=l1) 34 | Line2 = GeoJSON(name="Line2", data=l2) 35 | 36 | 37 | m.add_layer(Line1) 38 | m.add_layer(Line2) 39 | 40 | intersection = GeoJSON(name="intersection", data=line_intersect(l1, l2)) 41 | m.add_layer(intersection) 42 | 43 | m 44 | 45 | -------------------------------------------------------------------------------- /docs/source/misc/line_segment.rst: -------------------------------------------------------------------------------- 1 | Line Segment 2 | ================ 3 | Creates a FeatureCollection of 2-vertex LineString segments from a (Multi)LineString or (Multi)Polygon. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from turfpy.misc import line_segment 11 | 12 | poly = { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "Polygon", 17 | "coordinates": [ 18 | [ 19 | [ 20 | 51.17431640625, 21 | 47.025206001585396 22 | ], 23 | [ 24 | 45.17578125, 25 | 43.13306116240612 26 | ], 27 | [ 28 | 54.5361328125, 29 | 41.85319643776675 30 | ], 31 | [ 32 | 51.17431640625, 33 | 47.025206001585396 34 | ] 35 | ] 36 | ] 37 | } 38 | } 39 | 40 | line_segment(poly) 41 | 42 | 43 | Interactive Example 44 | ------------------- 45 | 46 | .. jupyter-execute:: 47 | 48 | from ipyleaflet import Map, GeoJSON, LayersControl 49 | from turfpy.misc import line_segment 50 | 51 | m = Map(center=[44.52337579109473, 50.61581611633301], zoom=6) 52 | 53 | poly = { 54 | "type": "Feature", 55 | "properties": {}, 56 | "geometry": { 57 | "type": "Polygon", 58 | "coordinates": [ 59 | [ 60 | [ 61 | 51.17431640625, 62 | 47.025206001585396 63 | ], 64 | [ 65 | 45.17578125, 66 | 43.13306116240612 67 | ], 68 | [ 69 | 54.5361328125, 70 | 41.85319643776675 71 | ], 72 | [ 73 | 51.17431640625, 74 | 47.025206001585396 75 | ] 76 | ] 77 | ] 78 | } 79 | } 80 | 81 | polygon = GeoJSON(name="Polygon", data=poly, style={'color':'red'}) 82 | 83 | m.add_layer(polygon) 84 | 85 | segments = GeoJSON(name="segments", data=line_segment(poly)) 86 | m.add_layer(segments) 87 | 88 | control = LayersControl(position='topright') 89 | m.add_control(control) 90 | 91 | m 92 | 93 | -------------------------------------------------------------------------------- /docs/source/misc/sector.rst: -------------------------------------------------------------------------------- 1 | Sector 2 | ================ 3 | Creates a circular sector of a circle of given radius and center Point, between (clockwise) bearing1 and bearing2; 0 bearing is North of center point, positive clockwise. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | from turfpy.misc import sector 11 | from geojson import Feature, Point 12 | 13 | center = Feature(geometry=Point((-75, 40))) 14 | radius = 5 15 | bearing1 = 25 16 | bearing2 = 45 17 | 18 | feature = sector(center, radius, bearing1, bearing2, options={"properties":{"length":3}}) 19 | 20 | 21 | 22 | Interactive Example 23 | ------------------- 24 | 25 | .. jupyter-execute:: 26 | 27 | from ipyleaflet import Map, GeoJSON, LayersControl 28 | from turfpy.misc import sector 29 | from geojson import Feature, Point, LineString, FeatureCollection 30 | 31 | center = Feature(geometry=Point((-75, 40))) 32 | radius = 5; 33 | bearing1 = 25; 34 | bearing2 = 45; 35 | 36 | m = Map(center=[40.011313056309056, -74.97720068362348], zoom=12) 37 | 38 | feature = sector(center, radius, bearing1, bearing2, options={"properties":{"length":3}}) 39 | 40 | 41 | fc = FeatureCollection([feature, center]) 42 | 43 | layer = GeoJSON(name="Line_Arc", data=fc, style={'color':'red'}) 44 | 45 | m.add_layer(layer) 46 | m 47 | 48 | -------------------------------------------------------------------------------- /docs/source/random/random_points.rst: -------------------------------------------------------------------------------- 1 | Random Points 2 | ============== 3 | 4 | Generates geojson random points, if bbox provided then the generated points will be in the bbox. 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | from turfpy.random import random_points 12 | 13 | random_points(count=3, bbox=[11.953125, 18.979025953255267, 52.03125, 46.558860303117164]) 14 | 15 | 16 | Interactive Example 17 | ------------------- 18 | 19 | .. jupyter-execute:: 20 | 21 | from geojson import Feature 22 | from ipyleaflet import Map, GeoJSON 23 | from turfpy.random import random_points 24 | from turfpy.measurement import bbox_polygon 25 | 26 | bb = [11.953125, 18.979025953255267, 52.03125, 46.558860303117164] 27 | 28 | fc = random_points(count=3, bbox=[11.953125, 18.979025953255267, 52.03125, 46.558860303117164]) 29 | 30 | geo_json = GeoJSON(name="Points", data=fc) 31 | 32 | 33 | 34 | bbox_polygon_geojson = GeoJSON( 35 | name="Bounding Box Polygon", data=bbox_polygon(bb), style={"color": "red"} 36 | ) 37 | 38 | 39 | m = Map(center=[4.889835742990713, 5.82601547241211], zoom=1) 40 | 41 | m.add_layer(geo_json) 42 | m.add_layer(bbox_polygon_geojson) 43 | 44 | m -------------------------------------------------------------------------------- /docs/source/random/random_position.rst: -------------------------------------------------------------------------------- 1 | Random Position 2 | ================ 3 | 4 | Generates a random position, if bbox provided then the generated position will be in the bbox. 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | from turfpy.random import random_position 12 | 13 | random_position(bbox=[11.953125, 18.979025953255267, 52.03125, 46.558860303117164]) 14 | 15 | 16 | Interactive Example 17 | ------------------- 18 | 19 | .. jupyter-execute:: 20 | 21 | from geojson import Feature 22 | from ipyleaflet import Map, GeoJSON 23 | from turfpy.random import random_position 24 | from turfpy.measurement import bbox_polygon 25 | 26 | bb = [11.953125, 18.979025953255267, 52.03125, 46.558860303117164] 27 | 28 | random_pos = random_position(bbox=bb) 29 | 30 | f = Feature( 31 | geometry={ 32 | "coordinates": random_pos, 33 | "type": "Point", 34 | } 35 | ) 36 | 37 | geo_json = GeoJSON(name="Position", data=f) 38 | 39 | 40 | 41 | bbox_polygon_geojson = GeoJSON( 42 | name="Bounding Box Polygon", data=bbox_polygon(bb), style={"color": "red"} 43 | ) 44 | 45 | 46 | m = Map(center=[4.889835742990713, 5.82601547241211], zoom=1) 47 | 48 | m.add_layer(geo_json) 49 | m.add_layer(bbox_polygon_geojson) 50 | 51 | m -------------------------------------------------------------------------------- /docs/source/transformations/bbox_clip.rst: -------------------------------------------------------------------------------- 1 | Bbox clip 2 | ========= 3 | 4 | Takes a Feature or geometry and a bbox and clips the feature to the bbox. 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.transformation import bbox_clip 13 | from geojson import Feature 14 | f = Feature(geometry={"coordinates": [[[2, 2], [8, 4], 15 | [12, 8], [3, 7], [2, 2]]], "type": "Polygon"}) 16 | bbox = [0, 0, 10, 10] 17 | bc = bbox_clip(f, bbox) 18 | print(json.dumps(bc, indent=2, sort_keys=True)) 19 | 20 | 21 | 22 | Interactive Example 23 | ------------------- 24 | 25 | .. jupyter-execute:: 26 | 27 | from geojson import Feature 28 | from ipyleaflet import Map, GeoJSON, LayersControl 29 | from turfpy.transformation import bbox_clip, bbox_polygon 30 | 31 | 32 | f = Feature( 33 | geometry={ 34 | "coordinates": [[[2, 2], [8, 4], [12, 8], [3, 7], [2, 2]]], 35 | "type": "Polygon", 36 | } 37 | ) 38 | 39 | bbox = [0, 0, 10, 10] 40 | 41 | geo_json = GeoJSON(name="Polygon", data=f) 42 | 43 | bbox_polygon_geojson = GeoJSON( 44 | name="Bounding Box Polygon", data=bbox_polygon(bbox), style={"color": "green"} 45 | ) 46 | 47 | cliped_geojson = GeoJSON( 48 | name="Clipped Polygon", data=bbox_clip(f, bbox), style={"color": "red"} 49 | ) 50 | 51 | 52 | m = Map(center=[4.889835742990713, 5.82601547241211], zoom=5) 53 | 54 | m.add_layer(geo_json) 55 | m.add_layer(bbox_polygon_geojson) 56 | m.add_layer(cliped_geojson) 57 | 58 | control = LayersControl(position="topright") 59 | m.add_control(control) 60 | 61 | m 62 | 63 | -------------------------------------------------------------------------------- /docs/source/transformations/bezier_spline.rst: -------------------------------------------------------------------------------- 1 | Bezier spline 2 | ============= 3 | 4 | Takes a line and returns a curved version by applying a Bezier spline algorithm. 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from geojson import LineString, Feature 13 | from turfpy.transformation import bezier_spline 14 | ls = LineString([(-76.091308, 18.427501), 15 | (-76.695556, 18.729501), 16 | (-76.552734, 19.40443), 17 | (-74.61914, 19.134789), 18 | (-73.652343, 20.07657), 19 | (-73.157958, 20.210656)]) 20 | f = Feature(geometry=ls) 21 | bs = bezier_spline(f) 22 | print(json.dumps(bs, indent=2, sort_keys=True)) 23 | 24 | 25 | 26 | Interactive Example 27 | ------------------- 28 | 29 | .. jupyter-execute:: 30 | 31 | from geojson import LineString, Feature 32 | from ipyleaflet import Map, GeoJSON 33 | from turfpy.transformation import bezier_spline 34 | 35 | ls = LineString([(-76.091308, 18.427501), 36 | (-76.695556, 18.729501), 37 | (-76.552734, 19.40443), 38 | (-74.61914, 19.134789), 39 | (-73.652343, 20.07657), 40 | (-73.157958, 20.210656)]) 41 | f = Feature(geometry=ls) 42 | 43 | 44 | geo_json = GeoJSON(data=f) 45 | 46 | spline_geo_json = GeoJSON(data=bezier_spline(f), style={'color': 'red'}) 47 | 48 | m = Map(center=[19.318170089962457, -74.85710620880128], zoom=8) 49 | 50 | m.add_layer(geo_json) 51 | m.add_layer(spline_geo_json) 52 | 53 | m -------------------------------------------------------------------------------- /docs/source/transformations/circle.rst: -------------------------------------------------------------------------------- 1 | Circle 2 | ====== 3 | Takes a Point and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers; and steps for precision. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | import json 11 | from geojson import Feature, Point 12 | from turfpy.transformation import circle 13 | 14 | center = Feature(geometry=Point((19.0760, 72.8777))) 15 | cc = circle(center, radius=5, steps=10) 16 | print(json.dumps(cc, indent=2, sort_keys=True)) 17 | 18 | 19 | 20 | Interactive Example 21 | ------------------- 22 | 23 | .. jupyter-execute:: 24 | 25 | from geojson import Point, Feature 26 | from ipyleaflet import Map, GeoJSON 27 | from turfpy.transformation import circle 28 | 29 | center = Feature(geometry=Point((-75.343, 39.984))) 30 | 31 | geo_json = GeoJSON(data=circle(center, radius=5, steps=10, units='km')) 32 | 33 | m = Map(center=[39.978756161038504, -75.32421022653581], zoom=11) 34 | 35 | m.add_layer(geo_json) 36 | 37 | m -------------------------------------------------------------------------------- /docs/source/transformations/concave_hull.rst: -------------------------------------------------------------------------------- 1 | Concave Hull 2 | ============ 3 | 4 | Generate concave hull for the given feature or Feature Collection. 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.transformation import concave 13 | from geojson import FeatureCollection, Feature, Point 14 | f1 = Feature(geometry=Point((-63.601226, 44.642643))) 15 | f2 = Feature(geometry=Point((-63.591442, 44.651436))) 16 | f3 = Feature(geometry=Point((-63.580799, 44.648749))) 17 | f4 = Feature(geometry=Point((-63.573589, 44.641788))) 18 | f5 = Feature(geometry=Point((-63.587665, 44.64533))) 19 | f6 = Feature(geometry=Point((-63.595218, 44.64765))) 20 | fc = [f1, f2, f3, f4, f5, f6] 21 | ch = concave(FeatureCollection(fc), alpha=100) 22 | print(json.dumps(ch, indent=2, sort_keys=True)) 23 | 24 | 25 | 26 | Interactive Example 27 | ------------------- 28 | 29 | .. jupyter-execute:: 30 | 31 | from geojson import FeatureCollection, Feature, Point 32 | from ipyleaflet import Map, GeoJSON 33 | from turfpy.transformation import concave 34 | 35 | f1 = Feature(geometry=Point((-63.601226, 44.642643))) 36 | f2 = Feature(geometry=Point((-63.591442, 44.651436))) 37 | f3 = Feature(geometry=Point((-63.580799, 44.648749))) 38 | f4 = Feature(geometry=Point((-63.573589, 44.641788))) 39 | f5 = Feature(geometry=Point((-63.587665, 44.64533))) 40 | f6 = Feature(geometry=Point((-63.595218, 44.64765))) 41 | fc = [f1, f2, f3, f4, f5, f6] 42 | fc = FeatureCollection(fc) 43 | 44 | geo_json = GeoJSON(data=fc) 45 | 46 | spline_geo_json = GeoJSON(data=concave(FeatureCollection(fc), alpha=100), style={'color': 'red'}) 47 | 48 | m = Map(center=[44.64740465397292, -63.58361206948757], zoom=14) 49 | 50 | m.add_layer(geo_json) 51 | m.add_layer(spline_geo_json) 52 | 53 | m -------------------------------------------------------------------------------- /docs/source/transformations/convex_hull.rst: -------------------------------------------------------------------------------- 1 | Convex Hull 2 | =========== 3 | 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.transformation import convex 13 | from geojson import FeatureCollection, Feature, Point 14 | f1 = Feature(geometry=Point((-63.601226, 44.642643))) 15 | f2 = Feature(geometry=Point((-63.591442, 44.651436))) 16 | f3 = Feature(geometry=Point((-63.580799, 44.648749))) 17 | f4 = Feature(geometry=Point((-63.573589, 44.641788))) 18 | f5 = Feature(geometry=Point((-63.587665, 44.64533))) 19 | f6 = Feature(geometry=Point((-63.595218, 44.64765))) 20 | fc = [f1, f2, f3, f4, f5, f6] 21 | ch = convex(FeatureCollection(fc)) 22 | print(json.dumps(ch, indent=2, sort_keys=True)) 23 | 24 | 25 | Interactive Example 26 | ------------------- 27 | 28 | .. jupyter-execute:: 29 | 30 | from geojson import FeatureCollection, Feature, Point 31 | from ipyleaflet import Map, GeoJSON 32 | from turfpy.transformation import convex 33 | 34 | f1 = Feature(geometry=Point((-63.601226, 44.642643))) 35 | f2 = Feature(geometry=Point((-63.591442, 44.651436))) 36 | f3 = Feature(geometry=Point((-63.580799, 44.648749))) 37 | f4 = Feature(geometry=Point((-63.573589, 44.641788))) 38 | f5 = Feature(geometry=Point((-63.587665, 44.64533))) 39 | f6 = Feature(geometry=Point((-63.595218, 44.64765))) 40 | fc = [f1, f2, f3, f4, f5, f6] 41 | fc = FeatureCollection(fc) 42 | 43 | geo_json = GeoJSON(data=fc) 44 | 45 | spline_geo_json = GeoJSON(data=convex(FeatureCollection(fc)), style={'color': 'red'}) 46 | 47 | m = Map(center=[44.64740465397292, -63.58361206948757], zoom=14) 48 | 49 | m.add_layer(geo_json) 50 | m.add_layer(spline_geo_json) 51 | 52 | m 53 | 54 | -------------------------------------------------------------------------------- /docs/source/transformations/difference.rst: -------------------------------------------------------------------------------- 1 | Difference 2 | ========== 3 | Find the difference between given two features. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | import json 11 | from geojson import Polygon, Feature 12 | from turfpy.transformation import difference 13 | f1 = Feature(geometry=Polygon([[ 14 | [128, -26], 15 | [141, -26], 16 | [141, -21], 17 | [128, -21], 18 | [128, -26]]]), properties={"combine": "yes", "fill": "#00f"}) 19 | f2 = Feature(geometry=Polygon([[ 20 | [126, -28], 21 | [140, -28], 22 | [140, -20], 23 | [126, -20], 24 | [126, -28]]]), properties={"combine": "yes"}) 25 | diff = difference(f1, f2) 26 | print(json.dumps(diff, indent=2, sort_keys=True)) 27 | 28 | 29 | 30 | 31 | Interactive Example 32 | ------------------- 33 | 34 | .. jupyter-execute:: 35 | 36 | from geojson import Feature, Polygon, FeatureCollection 37 | from ipyleaflet import Map, GeoJSON, LayersControl 38 | from turfpy.transformation import difference 39 | 40 | f1 = Feature(geometry=Polygon([[ 41 | [128, -26], 42 | [141, -26], 43 | [141, -21], 44 | [128, -21], 45 | [128, -26]]]), properties={"combine": "yes", "fill": "#00f"}) 46 | f2 = Feature(geometry=Polygon([[ 47 | [126, -28], 48 | [140, -28], 49 | [140, -20], 50 | [126, -20], 51 | [126, -28]]]), properties={"combine": "yes"}) 52 | 53 | geo_json_1 = GeoJSON(name="First Polygon", data=f1) 54 | 55 | geo_json_2 = GeoJSON(name='Second Polygon', data=f2, style={'color': 'green'}) 56 | 57 | geojson = GeoJSON(name='Difference', data=difference(f1, f2), style={'color': 'red'}) 58 | 59 | 60 | m = Map(center=[-22.71491497943416, 135.750846862793], zoom=5) 61 | 62 | 63 | m.add_layer(geo_json_1) 64 | m.add_layer(geo_json_2) 65 | m.add_layer(geojson) 66 | 67 | control = LayersControl(position='topright') 68 | m.add_control(control) 69 | 70 | m -------------------------------------------------------------------------------- /docs/source/transformations/dissolve.rst: -------------------------------------------------------------------------------- 1 | Dissolve 2 | ========= 3 | Take FeatureCollection or list of features to dissolve based on property_name provided. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | import json 11 | from geojson import Polygon, Feature, FeatureCollection 12 | from turfpy.transformation import dissolve 13 | f1 = Feature(geometry=Polygon([[ 14 | [0, 0], 15 | [0, 1], 16 | [1, 1], 17 | [1, 0], 18 | [0, 0]]]), properties={"combine": "yes", "fill": "#00f"}) 19 | f2 = Feature(geometry=Polygon([[ 20 | [0, -1], 21 | [0, 0], 22 | [1, 0], 23 | [1, -1], 24 | [0,-1]]]), properties={"combine": "yes"}) 25 | f3 = Feature(geometry=Polygon([[ 26 | [1,-1], 27 | [1, 0], 28 | [2, 0], 29 | [2, -1], 30 | [1, -1]]]), properties={"combine": "no"}) 31 | ds = dissolve(FeatureCollection([f1, f2, f3]), property_name='combine') 32 | print(json.dumps(ds, indent=2, sort_keys=True)) 33 | 34 | 35 | 36 | 37 | Interactive Example 38 | ------------------- 39 | 40 | .. jupyter-execute:: 41 | 42 | from geojson import Feature, Polygon, FeatureCollection 43 | from ipyleaflet import Map, GeoJSON, LayersControl 44 | from turfpy.transformation import dissolve 45 | 46 | f1 = Feature( 47 | geometry=Polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]), 48 | properties={"combine": "yes", "fill": "#00f"}, 49 | ) 50 | f2 = Feature( 51 | geometry=Polygon([[[0, -1], [0, 0], [1, 0], [1, -1], [0, -1]]]), 52 | properties={"combine": "yes"}, 53 | ) 54 | f3 = Feature( 55 | geometry=Polygon([[[1, -1], [1, 0], [2, 0], [2, -1], [1, -1]]]), 56 | properties={"combine": "no"}, 57 | ) 58 | 59 | geo_json_1 = GeoJSON(name="First Polygon", data=f1) 60 | 61 | geo_json_2 = GeoJSON(name="Second Polygon", data=f2, style={"color": "green"}) 62 | 63 | geo_json_3 = GeoJSON(name="Third Polygon", data=f3, style={"color": "black"}) 64 | 65 | geojson = GeoJSON( 66 | name="Dissolve", 67 | data=dissolve(FeatureCollection([f1, f2, f3]), property_name="combine"), 68 | style={"color": "red"}, 69 | ) 70 | 71 | 72 | m = Map(center=[0.257748688144287, 1.9686126708984377], zoom=7) 73 | 74 | 75 | m.add_layer(geo_json_1) 76 | m.add_layer(geo_json_2) 77 | m.add_layer(geo_json_3) 78 | m.add_layer(geojson) 79 | 80 | control = LayersControl(position="topright") 81 | m.add_control(control) 82 | 83 | m -------------------------------------------------------------------------------- /docs/source/transformations/intersect.rst: -------------------------------------------------------------------------------- 1 | Intersect 2 | ========= 3 | Takes polygons and finds their intersection. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.transformation import intersect 13 | from geojson import Feature 14 | f = Feature(geometry={"coordinates": [ 15 | [[-122.801742, 45.48565], [-122.801742, 45.60491], 16 | [-122.584762, 45.60491], [-122.584762, 45.48565], 17 | [-122.801742, 45.48565]]], "type": "Polygon"}) 18 | b = Feature(geometry={"coordinates": [ 19 | [[-122.520217, 45.535693], [-122.64038, 45.553967], 20 | [-122.720031, 45.526554], [-122.669906, 45.507309], 21 | [-122.723464, 45.446643], [-122.532577, 45.408574], 22 | [-122.487258, 45.477466], [-122.520217, 45.535693] 23 | ]], "type": "Polygon"}) 24 | it = intersect([f, b]) 25 | print(json.dumps(it, indent=2, sort_keys=True)) 26 | 27 | 28 | 29 | 30 | Interactive Example 31 | ------------------- 32 | 33 | .. jupyter-execute:: 34 | 35 | from geojson import Feature 36 | from ipyleaflet import Map, GeoJSON, LayersControl 37 | from turfpy.transformation import intersect 38 | 39 | f = Feature(geometry={"coordinates": [ 40 | [[-122.801742, 45.48565], [-122.801742, 45.60491], 41 | [-122.584762, 45.60491], [-122.584762, 45.48565], 42 | [-122.801742, 45.48565]]], "type": "Polygon"}) 43 | b = Feature(geometry={"coordinates": [ 44 | [[-122.520217, 45.535693], [-122.64038, 45.553967], 45 | [-122.720031, 45.526554], [-122.669906, 45.507309], 46 | [-122.723464, 45.446643], [-122.532577, 45.408574], 47 | [-122.487258, 45.477466], [-122.520217, 45.535693] 48 | ]], "type": "Polygon"}) 49 | 50 | geo_json_1 = GeoJSON(name="First Polygon", data=f) 51 | 52 | geo_json_2 = GeoJSON(name='Second Polygon', data=b, style={'color': 'green'}) 53 | 54 | geojson = GeoJSON(name='Intersection', data=intersect([f, b]), style={'color': 'red'}) 55 | 56 | 57 | m = Map(center=[45.510343157077976, -122.63075172901155], zoom=10) 58 | 59 | m.add_layer(geo_json_1) 60 | m.add_layer(geo_json_2) 61 | m.add_layer(geojson) 62 | 63 | control = LayersControl(position='topright') 64 | m.add_control(control) 65 | 66 | m 67 | -------------------------------------------------------------------------------- /docs/source/transformations/line_offset.rst: -------------------------------------------------------------------------------- 1 | Line Offset 2 | =========== 3 | Takes a linestring or multilinestring and returns a line at offset by the specified distance. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from geojson import MultiLineString, Feature 13 | from turfpy.transformation import line_offset 14 | ls = Feature(geometry=MultiLineString([ 15 | [(3.75, 9.25), (-130.95, 1.52)], 16 | [(23.15, -34.25), (-1.35, -4.65), (3.45, 77.95)] 17 | ])) 18 | lo = line_offset(ls, 2, unit='mi') 19 | print(json.dumps(lo, indent=2, sort_keys=True)) 20 | 21 | 22 | 23 | Interactive Example 24 | ------------------- 25 | 26 | .. jupyter-execute:: 27 | 28 | from ipyleaflet import Map, GeoJSON, LayersControl 29 | 30 | original = GeoJSON(name='Original', data=ls) 31 | 32 | rotated = GeoJSON(name='Offset Line', data=line_offset(ls, 2, unit='mi'), style={'color': 'red'}) 33 | 34 | m = Map(center=[33.54139466898275, 7.536621093750001], zoom=1) 35 | 36 | m.add_layer(original) 37 | m.add_layer(rotated) 38 | 39 | control = LayersControl(position='topright') 40 | m.add_control(control) 41 | m 42 | -------------------------------------------------------------------------------- /docs/source/transformations/tesselate.rst: -------------------------------------------------------------------------------- 1 | Tesselate 2 | ================ 3 | Tesselates a Feature into a FeatureCollection of triangles using earcut. 4 | 5 | 6 | Interactive Example 7 | ------------------- 8 | 9 | .. jupyter-execute:: 10 | 11 | from geojson import Feature 12 | from turfpy.transformation import tesselate 13 | 14 | f = Feature( 15 | geometry={ 16 | "coordinates": [ 17 | [[11, 0], [22, 4], [31, 0], [31, 11], [21, 15], [11, 11], [11, 0]] 18 | ], 19 | "type": "Polygon", 20 | } 21 | ) 22 | 23 | from ipyleaflet import Map, GeoJSON, LayersControl 24 | 25 | m = Map(center=(4.595931675360621, 29.52129364013672), zoom=4) 26 | geo_json = GeoJSON( 27 | name="original", 28 | data=dict(f), 29 | style={"opacity": 1, "fillOpacity": 0.3, "weight": 1}, 30 | hover_style={"color": "green", "dashArray": "0", "fillOpacity": 0.5}, 31 | ) 32 | 33 | result = tesselate(f) 34 | m = Map(center=(4.595931675360621, 29.52129364013672), zoom=4) 35 | geo_json2 = GeoJSON( 36 | name="tesselate", 37 | data=result, 38 | style={"opacity": 1, "fillOpacity": 0.3, "weight": 1}, 39 | hover_style={"color": "green", "dashArray": "0", "fillOpacity": 0.5}, 40 | ) 41 | m.add_layer(geo_json2) 42 | control = LayersControl(position="topright") 43 | m.add_control(control) 44 | m.add_layer(geo_json) 45 | m -------------------------------------------------------------------------------- /docs/source/transformations/transform_rotate.rst: -------------------------------------------------------------------------------- 1 | Transform Rotate 2 | ================ 3 | Rotates any geojson Feature or Geometry of a specified angle, around its centroid or a given pivot point; all rotations follow the right-hand rule. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.transformation import transform_rotate 13 | from geojson import Polygon, Feature 14 | f = Feature(geometry=Polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]])) 15 | pivot = [0, 25] 16 | tr = transform_rotate(f, 10, pivot) 17 | print(json.dumps(tr, indent=2, sort_keys=True)) 18 | 19 | 20 | Interactive Example 21 | ------------------- 22 | 23 | .. jupyter-execute:: 24 | 25 | from ipyleaflet import Map, GeoJSON, LayersControl 26 | 27 | original = GeoJSON(name='Original', data=f) 28 | 29 | rotated = GeoJSON(name='Rotated', data=transform_rotate(f, 10, pivot), style={'color': 'red'}) 30 | 31 | m = Map(center=[30.18519925274955, 2.939529418945313], zoom=5) 32 | 33 | m.add_layer(original) 34 | m.add_layer(rotated) 35 | 36 | control = LayersControl(position='topright') 37 | m.add_control(control) 38 | m -------------------------------------------------------------------------------- /docs/source/transformations/transform_scale.rst: -------------------------------------------------------------------------------- 1 | Transform Scale 2 | =============== 3 | Scale a GeoJSON from a given point by a factor of scaling (ex: factor=2 would make the GeoJSON 200% larger). If a FeatureCollection is provided, the origin point will be calculated based on each individual Feature. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | import json 11 | from turfpy.transformation import transform_scale 12 | from geojson import Polygon, Feature 13 | f = Feature(geometry=Polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]])) 14 | ts = transform_scale(f, 3, origin=[0, 29]) 15 | print(json.dumps(ts, indent=2, sort_keys=True)) 16 | 17 | 18 | 19 | 20 | Interactive Example 21 | ------------------- 22 | 23 | .. jupyter-execute:: 24 | 25 | from ipyleaflet import Map, GeoJSON, LayersControl 26 | 27 | original = GeoJSON(name='Original', data=f) 28 | 29 | rotated = GeoJSON(name='Scaled', data=transform_scale(f, 3, origin=[0, 29]), style={'color': 'red'}) 30 | 31 | m = Map(center=[33.52608402076209, 7.55413055419922], zoom=5) 32 | 33 | m.add_layer(original) 34 | m.add_layer(rotated) 35 | 36 | control = LayersControl(position='topright') 37 | m.add_control(control) 38 | m -------------------------------------------------------------------------------- /docs/source/transformations/transform_translate.rst: -------------------------------------------------------------------------------- 1 | Transform Translate 2 | =================== 3 | Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line on the provided direction angle. 4 | 5 | 6 | Example 7 | ------- 8 | 9 | .. jupyter-execute:: 10 | 11 | import json 12 | from turfpy.transformation import transform_translate 13 | from geojson import Polygon, Feature 14 | f = Feature(geometry=Polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]])) 15 | tt = transform_translate(f, 100, direction=35, mutate=True) 16 | print(json.dumps(tt, indent=2, sort_keys=True)) 17 | 18 | 19 | 20 | Interactive Example 21 | ------------------- 22 | 23 | .. jupyter-execute:: 24 | 25 | from ipyleaflet import Map, GeoJSON, LayersControl 26 | 27 | original = GeoJSON(name='Original', data=f) 28 | 29 | rotated = GeoJSON(name='Translated', data=transform_translate(f, 100, 35, mutate=True), style={'color': 'red'}) 30 | 31 | m = Map(center=[30.18519925274955, 2.939529418945313], zoom=5) 32 | 33 | m.add_layer(original) 34 | m.add_layer(rotated) 35 | 36 | control = LayersControl(position='topright') 37 | m.add_control(control) 38 | m 39 | -------------------------------------------------------------------------------- /docs/source/transformations/union.rst: -------------------------------------------------------------------------------- 1 | Union 2 | ===== 3 | Given list of features or FeatureCollection return union of those. 4 | 5 | Example 6 | ------- 7 | 8 | .. jupyter-execute:: 9 | 10 | import json 11 | from turfpy.transformation import union 12 | from geojson import Feature, Polygon, FeatureCollection 13 | f1 = Feature(geometry=Polygon([[ 14 | [-82.574787, 35.594087], 15 | [-82.574787, 35.615581], 16 | [-82.545261, 35.615581], 17 | [-82.545261, 35.594087], 18 | [-82.574787, 35.594087] 19 | ]]), properties={"fill": "#00f"}) 20 | f2 = Feature(geometry=Polygon([[ 21 | [-82.560024, 35.585153], 22 | [-82.560024, 35.602602], 23 | [-82.52964, 35.602602], 24 | [-82.52964, 35.585153], 25 | [-82.560024, 35.585153]]]), properties={"fill": "#00f"}) 26 | un = union(FeatureCollection([f1, f2], properties={"combine": "yes"})) 27 | print(json.dumps(un, indent=2, sort_keys=True)) 28 | 29 | 30 | 31 | 32 | Interactive Example 33 | ------------------- 34 | 35 | .. jupyter-execute:: 36 | 37 | from geojson import Feature, Polygon, FeatureCollection 38 | from ipyleaflet import Map, GeoJSON, LayersControl 39 | from turfpy.transformation import union 40 | 41 | f1 = Feature( 42 | geometry=Polygon( 43 | [ 44 | [ 45 | [-82.574787, 35.594087], 46 | [-82.574787, 35.615581], 47 | [-82.545261, 35.615581], 48 | [-82.545261, 35.594087], 49 | [-82.574787, 35.594087], 50 | ] 51 | ] 52 | ), 53 | properties={"fill": "#00f"}, 54 | ) 55 | f2 = Feature( 56 | geometry=Polygon( 57 | [ 58 | [ 59 | [-82.560024, 35.585153], 60 | [-82.560024, 35.602602], 61 | [-82.52964, 35.602602], 62 | [-82.52964, 35.585153], 63 | [-82.560024, 35.585153], 64 | ] 65 | ] 66 | ), 67 | properties={"fill": "#00f"}, 68 | ) 69 | 70 | geo_json_1 = GeoJSON(name="First Polygon", data=f1) 71 | 72 | geo_json_2 = GeoJSON(name="Second Polygon", data=f2, style={"color": "green"}) 73 | 74 | geojson = GeoJSON( 75 | name="Union", 76 | data=union(FeatureCollection([f1, f2], properties={"combine": "yes"})), 77 | style={"color": "red"}, 78 | ) 79 | 80 | m = Map(center=[35.60069336198429, -82.54892796278001], zoom=13) -------------------------------------------------------------------------------- /docs/source/turfpy.__version__.rst: -------------------------------------------------------------------------------- 1 | turfpy.\_\_version\_\_ module 2 | ============================= 3 | 4 | .. automodule:: turfpy.__version__ 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /docs/source/turfpy._compact.rst: -------------------------------------------------------------------------------- 1 | turfpy.\_compact module 2 | ======================= 3 | 4 | .. automodule:: turfpy._compact 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /docs/source/turfpy.boolean.rst: -------------------------------------------------------------------------------- 1 | turfpy.boolean module 2 | ========================= 3 | 4 | .. automodule:: turfpy.boolean 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /docs/source/turfpy.dev_lib.earcut.rst: -------------------------------------------------------------------------------- 1 | turfpy.dev\_lib.earcut module 2 | ============================= 3 | 4 | .. automodule:: turfpy.dev_lib.earcut 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /docs/source/turfpy.dev_lib.rst: -------------------------------------------------------------------------------- 1 | turfpy.dev\_lib package 2 | ======================= 3 | 4 | .. automodule:: turfpy.dev_lib 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | 10 | Submodules 11 | ---------- 12 | 13 | .. toctree:: 14 | :maxdepth: 4 15 | 16 | turfpy.dev_lib.earcut 17 | turfpy.dev_lib.spline 18 | -------------------------------------------------------------------------------- /docs/source/turfpy.dev_lib.spline.rst: -------------------------------------------------------------------------------- 1 | turfpy.dev\_lib.spline module 2 | ============================= 3 | 4 | .. automodule:: turfpy.dev_lib.spline 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /docs/source/turfpy.extra.rst: -------------------------------------------------------------------------------- 1 | turfpy.extra module 2 | =================== 3 | 4 | .. automodule:: turfpy.extra 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /docs/source/turfpy.feature_conversion.rst: -------------------------------------------------------------------------------- 1 | turfpy.turfpy.feature_conversion module 2 | ========================= 3 | 4 | .. automodule:: turfpy.turfpy.feature_conversion 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /docs/source/turfpy.helper.rst: -------------------------------------------------------------------------------- 1 | turfpy.helper module 2 | ==================== 3 | 4 | .. automodule:: turfpy.helper 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /docs/source/turfpy.measurement.rst: -------------------------------------------------------------------------------- 1 | turfpy.measurement module 2 | ========================= 3 | 4 | .. automodule:: turfpy.measurement 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /docs/source/turfpy.meta.rst: -------------------------------------------------------------------------------- 1 | turfpy.meta module 2 | ================== 3 | 4 | .. automodule:: turfpy.meta 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /docs/source/turfpy.misc.rst: -------------------------------------------------------------------------------- 1 | turfpy.misc module 2 | ================== 3 | 4 | .. automodule:: turfpy.misc 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /docs/source/turfpy.random.rst: -------------------------------------------------------------------------------- 1 | turfpy.random module 2 | ==================== 3 | 4 | .. automodule:: turfpy.random 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /docs/source/turfpy.rst: -------------------------------------------------------------------------------- 1 | turfpy package 2 | ============== 3 | 4 | .. automodule:: turfpy 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | 10 | Subpackages 11 | ----------- 12 | 13 | .. toctree:: 14 | :maxdepth: 4 15 | 16 | turfpy.dev_lib 17 | 18 | Submodules 19 | ---------- 20 | 21 | .. toctree:: 22 | :maxdepth: 4 23 | 24 | turfpy.extra 25 | turfpy.helper 26 | turfpy.measurement 27 | turfpy.meta 28 | turfpy.transformation 29 | turfpy.__version__ 30 | -------------------------------------------------------------------------------- /docs/source/turfpy.transformation.rst: -------------------------------------------------------------------------------- 1 | turfpy.transformation module 2 | ============================ 3 | 4 | .. automodule:: turfpy.transformation 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | :private-members: 9 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: turfpy 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - ipyleaflet 6 | - pip 7 | - pip: 8 | - "-r requirements.txt" 9 | - "-r dev_requirements.txt" 10 | - "-e ." -------------------------------------------------------------------------------- /examples/Misc.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Misc\n", 8 | "This notebook demonstrates Misc examples" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "## Line Intersect\n", 16 | "Takes any LineString or Polygon GeoJSON and returns the intersecting point(s)." 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "from geojson import LineString, Feature\n", 26 | "from turfpy.misc import line_intersect\n", 27 | "l1 = Feature(geometry=LineString([[126, -11], [129, -21]]))\n", 28 | "l2 = Feature(geometry=LineString([[123, -18], [131, -14]]))\n", 29 | "line_intersect(l1, l2)" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "## Line Segment\n", 37 | "Creates a FeatureCollection of 2-vertex LineString segments from a (Multi)LineString or (Multi)Polygon." 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "metadata": {}, 44 | "outputs": [], 45 | "source": [ 46 | "from turfpy.misc import line_segment\n", 47 | "\n", 48 | "poly = {\n", 49 | " \"type\": \"Feature\",\n", 50 | " \"properties\": {},\n", 51 | " \"geometry\": {\n", 52 | " \"type\": \"Polygon\",\n", 53 | " \"coordinates\": [\n", 54 | " [\n", 55 | " [\n", 56 | " 51.17431640625,\n", 57 | " 47.025206001585396\n", 58 | " ],\n", 59 | " [\n", 60 | " 45.17578125,\n", 61 | " 43.13306116240612\n", 62 | " ],\n", 63 | " [\n", 64 | " 54.5361328125,\n", 65 | " 41.85319643776675\n", 66 | " ],\n", 67 | " [\n", 68 | " 51.17431640625,\n", 69 | " 47.025206001585396\n", 70 | " ]\n", 71 | " ]\n", 72 | " ]\n", 73 | " }\n", 74 | "}\n", 75 | "\n", 76 | "line_segment(poly)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": {}, 82 | "source": [ 83 | "## Line Arc\n", 84 | "Creates a circular arc, of a circle of the given radius and center point, between bearing1 and bearing2; 0 bearing is North of center point, positive clockwise." 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "from turfpy.misc import line_arc\n", 94 | "from geojson import Feature, Point\n", 95 | "\n", 96 | "center = Feature(geometry=Point((-75, 40)))\n", 97 | "radius = 5\n", 98 | "bearing1 = 25\n", 99 | "bearing2 = 47\n", 100 | "\n", 101 | "line_arc(center=center, radius=radius, bearing1=bearing1, bearing2=bearing2)" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "metadata": {}, 107 | "source": [ 108 | "## Sector\n", 109 | "Creates a circular sector of a circle of given radius and center Point, between (clockwise) bearing1 and bearing2; 0 bearing is North of center point, positive clockwise." 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": null, 115 | "metadata": {}, 116 | "outputs": [], 117 | "source": [ 118 | "from turfpy.misc import sector\n", 119 | "from geojson import Feature, Point\n", 120 | "\n", 121 | "center = Feature(geometry=Point((-75, 40)))\n", 122 | "radius = 5\n", 123 | "bearing1 = 25\n", 124 | "bearing2 = 45\n", 125 | "\n", 126 | "feature = sector(center, radius, bearing1, bearing2, options={\"properties\":{\"length\":3}})" 127 | ] 128 | } 129 | ], 130 | "metadata": { 131 | "kernelspec": { 132 | "display_name": "Python 3", 133 | "language": "python", 134 | "name": "python3" 135 | }, 136 | "language_info": { 137 | "codemirror_mode": { 138 | "name": "ipython", 139 | "version": 3 140 | }, 141 | "file_extension": ".py", 142 | "mimetype": "text/x-python", 143 | "name": "python", 144 | "nbconvert_exporter": "python", 145 | "pygments_lexer": "ipython3", 146 | "version": "3.7.9" 147 | } 148 | }, 149 | "nbformat": 4, 150 | "nbformat_minor": 4 151 | } 152 | -------------------------------------------------------------------------------- /examples/Random.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Random\n", 8 | "This notebook demonstrates random functionality examples" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "## Random position\n", 16 | "Generates a random position, if bbox provided then the generated position will be in the bbox." 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "from turfpy.random import random_position\n", 26 | "\n", 27 | "random_position(bbox=[11.953125, 18.979025953255267, 52.03125, 46.558860303117164])" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "## Random points\n", 35 | "Generates geojson random points, if bbox provided then the generated points will be in the bbox" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "from turfpy.random import random_points\n", 45 | "\n", 46 | "random_points(count=3, bbox=[11.953125, 18.979025953255267, 52.03125, 46.558860303117164])" 47 | ] 48 | } 49 | ], 50 | "metadata": { 51 | "kernelspec": { 52 | "display_name": "Python 3", 53 | "language": "python", 54 | "name": "python3" 55 | }, 56 | "language_info": { 57 | "codemirror_mode": { 58 | "name": "ipython", 59 | "version": 3 60 | }, 61 | "file_extension": ".py", 62 | "mimetype": "text/x-python", 63 | "name": "python", 64 | "nbconvert_exporter": "python", 65 | "pygments_lexer": "ipython3", 66 | "version": "3.7.9" 67 | } 68 | }, 69 | "nbformat": 4, 70 | "nbformat_minor": 4 71 | } 72 | -------------------------------------------------------------------------------- /examples/boolean.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Boolean\n", 8 | "This notebook demonstrates all the examples of boolean" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "## Boolean Disjoint\n", 16 | "Takes two features and returns (TRUE) if the two geometries do not touch or overlap." 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "from geojson import Feature, Point\n", 26 | "from turfpy.boolean import boolean_disjoint\n", 27 | "\n", 28 | "feature_1 = Feature(geometry=Point((19.0760, 72.8777)))\n", 29 | "feature_2 = Feature(geometry=Point((29.0760, 72.8777)))\n", 30 | "boolean_disjoint(feature_1, feature_2)" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "## Boolean Intersects\n", 38 | "Takes two features and returns (TRUE) if the intersection of the two geometries is NOT an empty set." 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "from geojson import Feature, Point\n", 48 | "from turfpy.boolean import boolean_intersects\n", 49 | "\n", 50 | "feature_1 = Feature(geometry=Point((19.0760, 72.8777)))\n", 51 | "feature_2 = Feature(geometry=Point((29.0760, 72.8777)))\n", 52 | "boolean_intersects(feature_1, feature_2)" 53 | ] 54 | } 55 | ], 56 | "metadata": { 57 | "kernelspec": { 58 | "display_name": "Python 3", 59 | "language": "python", 60 | "name": "python3" 61 | }, 62 | "language_info": { 63 | "codemirror_mode": { 64 | "name": "ipython", 65 | "version": 3 66 | }, 67 | "file_extension": ".py", 68 | "mimetype": "text/x-python", 69 | "name": "python", 70 | "nbconvert_exporter": "python", 71 | "pygments_lexer": "ipython3", 72 | "version": "3.10.10" 73 | } 74 | }, 75 | "nbformat": 4, 76 | "nbformat_minor": 4 77 | } 78 | -------------------------------------------------------------------------------- /examples/feature_conversion.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Feature Conversion\n", 8 | "This notebook demonstrates all the examples of feature conversion" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "## Polygon To Line\n", 16 | "Takes a Polygon or MultiPolygon and convert it to a line." 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 6, 22 | "metadata": {}, 23 | "outputs": [ 24 | { 25 | "data": { 26 | "application/vnd.jupyter.widget-view+json": { 27 | "model_id": "d91a3338fe6e44328d770d3a215c8220", 28 | "version_major": 2, 29 | "version_minor": 0 30 | }, 31 | "text/plain": [ 32 | "Map(center=[20.04303061200023, -11.832275390625002], controls=(ZoomControl(options=['position', 'zoom_in_text'…" 33 | ] 34 | }, 35 | "execution_count": 6, 36 | "metadata": {}, 37 | "output_type": "execute_result" 38 | } 39 | ], 40 | "source": [ 41 | "from turfpy.feature_conversion import polygon_to_line\n", 42 | "from geojson import Polygon\n", 43 | "from geojson import Feature\n", 44 | "from ipyleaflet import Map, WidgetControl\n", 45 | "from ipywidgets import HTML\n", 46 | "\n", 47 | "feature_1 = Feature(geometry=Polygon([[(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15), (2.38, 57.322)]]))\n", 48 | "\n", 49 | "geo_json = polygon_to_line(feature_1)\n", 50 | "\n", 51 | "m = Map(center=[20.04303061200023, -11.832275390625002], zoom=2)\n", 52 | "\n", 53 | "m.add_layer(geo_json)\n", 54 | "\n", 55 | "html = HTML()\n", 56 | "html.layout.margin = \"0px 20px 10px 20px\"\n", 57 | "html.value = \"\"\"\n", 58 | "

Polygon to Line for given geojson

\n", 59 | "

{}

\n", 60 | " \"\"\".format(\n", 61 | " geo_json\n", 62 | ")\n", 63 | "control = WidgetControl(widget=html, position=\"topright\")\n", 64 | "m.add_control(control)" 65 | ] 66 | } 67 | ], 68 | "metadata": { 69 | "kernelspec": { 70 | "display_name": "Python 3", 71 | "language": "python", 72 | "name": "python3" 73 | }, 74 | "language_info": { 75 | "codemirror_mode": { 76 | "name": "ipython", 77 | "version": 3 78 | }, 79 | "file_extension": ".py", 80 | "mimetype": "text/x-python", 81 | "name": "python", 82 | "nbconvert_exporter": "python", 83 | "pygments_lexer": "ipython3", 84 | "version": "3.10.10" 85 | } 86 | }, 87 | "nbformat": 4, 88 | "nbformat_minor": 4 89 | } 90 | -------------------------------------------------------------------------------- /feature_conversion.md: -------------------------------------------------------------------------------- 1 | ## Feature Conversion Examples : 2 | * polygon_to_line : Takes a Polygon or MultiPolygon and convert it to a line. 3 | 4 | | Argument| Type | Description| 5 | | ------- |------ | ----------- | 6 | | `polygon` | Polygon | Multipolygon | a polygon or multipolygon | 7 | | `options` | float | A dict representing additional properties | 8 | 9 | 10 | | Return | Type | Description | 11 | | ------- | ------ | ----------- | 12 | | `object` | Feature | FeatureCollection | Return a feature or feature collection | 13 | 14 | ```python 15 | from geojson import Feature, Polygon 16 | from turfpy.feature_conversion import polygon_to_line 17 | 18 | feature_1 = Feature(geometry=Polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]])) 19 | polygon_to_line(feature_1) 20 | ``` 21 | -------------------------------------------------------------------------------- /postBuild: -------------------------------------------------------------------------------- 1 | jupyter labextension install \ 2 | @jupyter-widgets/jupyterlab-manager \ 3 | jupyter-leaflet \ 4 | 5 | # Notebooks with extensions that auto-run code must be "trusted" to work the first time 6 | jupyter trust examples/*.ipynb 7 | 8 | jupyter lab build --dev-build=False --minimize=False 9 | -------------------------------------------------------------------------------- /random.md: -------------------------------------------------------------------------------- 1 | ## Random Examples : 2 | * Random Position : Generates a random position, if bbox provided then the generated position will be in the bbox. 3 | 4 | | Argument | Type | Description | 5 | | ------- | ------ | ----------- | 6 | | `bbox` | list | Bounding Box in which position to be generated | 7 | 8 | | Return | Type | Description | 9 | | ------- | ------ | ----------- | 10 | | `position` | list | A position as coordinates| 11 | 12 | ```python 13 | from turfpy.random import random_position 14 | 15 | random_position(bbox=[11.953125, 18.979025953255267, 52.03125, 46.558860303117164]) 16 | ``` 17 | 18 | * Random Points : Generates geojson random points, if bbox provided then the generated points will be in the bbox. 19 | 20 | | Argument | Type | Description | 21 | | ------- | ------ | ----------- | 22 | | `count` | int | Number of points to be generated, default value is one | 23 | | `bbox` | list | Bounding Box in which points are to be generated | 24 | 25 | | Return | Type | Description | 26 | | ------- | ------ | ----------- | 27 | | `points` | FeatureCollection | A FeatureCollection of generated points | 28 | 29 | ```python 30 | from turfpy.random import random_points 31 | 32 | random_points(count=3, bbox=[11.953125, 18.979025953255267, 52.03125, 46.558860303117164]) 33 | ``` -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # Core 2 | geojson==3.1.0 3 | geopandas==1.0.1 4 | shapely==2.0.6 5 | scipy==1.14.1 6 | numpy==1.26.4 -------------------------------------------------------------------------------- /scripts/build_apiref.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | export DEST=docs/source 4 | #rm -f $DEST/*.rst 5 | rm -rf $DEST/_build 6 | rm -rf $DEST/_static 7 | rm -rf $DEST/_templates 8 | 9 | # Just creating conf.py, Makefile and make.bat once, hence commenting below. 10 | 11 | #sphinx-quickstart --quiet --author 'Omkar Mestry, Sachin Kharude' --project turfpy \ 12 | # --ext-coverage --ext-autodoc --ext-viewcode --ext-doctest \ 13 | # $DEST 14 | 15 | sphinx-apidoc --private --separate --module-first --full -o $DEST turfpy 16 | sphinx-build -b html -D html_theme=sphinx_rtd_theme $DEST $DEST/_build/html 17 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 90 3 | ignore = E203,W503 4 | 5 | [mypy] 6 | ignore_missing_imports = True 7 | 8 | [isort] 9 | line_length=90 -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """Project setup file.""" 2 | import sys 3 | from codecs import open 4 | from os import path 5 | 6 | from setuptools import find_packages, setup 7 | 8 | needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv) 9 | pytest_runner = ["pytest-runner"] if needs_pytest else [] 10 | 11 | here = path.abspath(path.dirname(__file__)) 12 | 13 | # get the core dependencies and installs 14 | with open(path.join(here, "requirements.txt"), encoding="utf-8") as f: 15 | all_reqs = f.read().split("\n") 16 | install_requires = [x.strip() for x in all_reqs if "git+" not in x] 17 | 18 | packages = find_packages(exclude=["docs", "tests"]) 19 | version = {} 20 | with open('{}/__version__.py'.format(packages[0])) as f: 21 | exec(f.read(), version) 22 | 23 | download_url = ( 24 | "https://github.com/omanges/turfpy" 25 | "/archive/" + version['__version__'] + ".zip" 26 | ) 27 | 28 | # The directory containing this file 29 | HERE = path.abspath(path.dirname(__file__)) 30 | 31 | # The text of the README file 32 | with open(path.join(HERE, "README.md")) as fid: 33 | README = fid.read() 34 | 35 | setup( 36 | name="turfpy", 37 | version=version['__version__'], 38 | description="A Python library for performing geospatial data analysis which reimplements turf.js.", 39 | long_description=README, 40 | long_description_content_type="text/markdown", 41 | download_url=download_url, 42 | license="MIT", 43 | classifiers=[ 44 | "Development Status :: 4 - Beta", 45 | "Intended Audience :: Developers", 46 | "Topic :: Software Development :: Libraries", 47 | "License :: OSI Approved :: MIT License", 48 | "Programming Language :: Python :: 3", 49 | "Programming Language :: Python :: 3 :: Only", 50 | "Programming Language :: Python :: 3.10", 51 | "Programming Language :: Python :: 3.11", 52 | "Programming Language :: Python :: 3.12", 53 | "Programming Language :: Python :: 3.13", 54 | ], 55 | project_urls={ 56 | "Documentation": "https://turfpy.readthedocs.io", 57 | "Source": "https://github.com/omanges/turfpy" 58 | }, 59 | packages=packages, 60 | keywords="Python Library for Turf", 61 | include_package_data=True, 62 | author="Omkar Mestry, Sachin Kharude", 63 | install_requires=install_requires, 64 | author_email="om.m.mestry@gmail.com, sachinkharude10@gmail.com", 65 | setup_requires=[] + pytest_runner, 66 | tests_require=["pytest"], 67 | py_modules=["turfpy"] 68 | ) 69 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/LineString/LineString/LineString-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [0, 2], 11 | [12, 2], 12 | [12, 3], 13 | [12, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "LineString", 22 | "coordinates": [ 23 | [1, 1], 24 | [1, 2], 25 | [1, 3], 26 | [1, 4] 27 | ] 28 | } 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/LineString/Point/LineString-Point-1.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [1, 1], 11 | [1, 2], 12 | [1, 3], 13 | [1, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "Point", 22 | "coordinates": [1, 1] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/LineString/Point/LineString-Point-2.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [1, 1], 11 | [1, 2], 12 | [1, 3], 13 | [1, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "Point", 22 | "coordinates": [1, 1.5] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/LineString/Polygon/LineString-In-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [1, 2.5], 11 | [2, 2.5] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "Polygon", 20 | "coordinates": [ 21 | [ 22 | [-1, 2], 23 | [3, 2], 24 | [3, 3], 25 | [-1, 3], 26 | [-1, 2] 27 | ] 28 | ] 29 | } 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/LineString/Polygon/LineString-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [0, 2], 11 | [12, 2], 12 | [12, 3], 13 | [12, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "Polygon", 22 | "coordinates": [ 23 | [ 24 | [-1, 2], 25 | [3, 2], 26 | [3, 3], 27 | [-1, 3], 28 | [-1, 2] 29 | ] 30 | ] 31 | } 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/MultiPoint/LineString/MultiPoint-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [1, 1], 11 | [0, 0] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "LineString", 20 | "coordinates": [ 21 | [1, 1], 22 | [1, 2], 23 | [1, 3], 24 | [1, 4] 25 | ] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/MultiPoint/MultiPoint/MultiPoint-MultiPoint.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [0, 0], 11 | [12, 12] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "MultiPoint", 20 | "coordinates": [ 21 | [0, 0], 22 | [12, 12] 23 | ] 24 | } 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/MultiPoint/Polygon/MultiPoint-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [-1, 2], 11 | [-2, -2] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "Polygon", 20 | "coordinates": [ 21 | [ 22 | [-1, 2], 23 | [3, 2], 24 | [3, 3], 25 | [-1, 3], 26 | [-1, 2] 27 | ] 28 | ] 29 | } 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/MultiPolygon/Polygon/MultiPolygon-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": { 7 | "fill": "#ff0000" 8 | }, 9 | "geometry": { 10 | "type": "MultiPolygon", 11 | "coordinates": [ 12 | [ 13 | [ 14 | [122.6953125, -19.186677697957833], 15 | [128.759765625, -19.186677697957833], 16 | [128.759765625, -15.28418511407642], 17 | [122.6953125, -15.28418511407642], 18 | [122.6953125, -19.186677697957833] 19 | ] 20 | ], 21 | [ 22 | [ 23 | [123.74999999999999, -25.918526162075153], 24 | [130.25390625, -25.918526162075153], 25 | [130.25390625, -20.715015145512087], 26 | [123.74999999999999, -20.715015145512087], 27 | [123.74999999999999, -25.918526162075153] 28 | ] 29 | ] 30 | ] 31 | } 32 | }, 33 | { 34 | "type": "Feature", 35 | "properties": { 36 | "fill": "#0000ff" 37 | }, 38 | "geometry": { 39 | "type": "Polygon", 40 | "coordinates": [ 41 | [ 42 | [119.20166015624999, -22.776181505086495], 43 | [125.09033203124999, -22.776181505086495], 44 | [125.09033203124999, -18.417078658661257], 45 | [119.20166015624999, -18.417078658661257], 46 | [119.20166015624999, -22.776181505086495] 47 | ] 48 | ] 49 | } 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Point/LineString/Point-LineString-1.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [1, 1] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "LineString", 17 | "coordinates": [ 18 | [1, 1], 19 | [1, 2], 20 | [1, 3], 21 | [1, 4] 22 | ] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Point/LineString/Point-LineString-2.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [1, 1.5] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "LineString", 17 | "coordinates": [ 18 | [1, 1], 19 | [1, 2], 20 | [1, 3], 21 | [1, 4] 22 | ] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Point/LineString/Point-LineString-3.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [2.5, 1] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "LineString", 17 | "coordinates": [ 18 | [1, 1], 19 | [2, 1], 20 | [3, 1], 21 | [4, 1] 22 | ] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Point/LineString/Point-LineString-4.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [2.5, 2.5] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "LineString", 17 | "coordinates": [ 18 | [1, 1], 19 | [2, 2], 20 | [3, 3], 21 | [4, 4] 22 | ] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Point/MultiPoint/Point-MultiPoint.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [1, 1] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "MultiPoint", 17 | "coordinates": [ 18 | [1, 1], 19 | [12, 12] 20 | ] 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Point/Point/Point-Point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [0, 0] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "Point", 17 | "coordinates": [0, 0] 18 | } 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Point/Polygon/Point-Polygon-1.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [1, 2.5] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "Polygon", 17 | "coordinates": [ 18 | [ 19 | [-1, 2], 20 | [3, 2], 21 | [3, 3], 22 | [-1, 3], 23 | [-1, 2] 24 | ] 25 | ] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Point/Polygon/Point-Polygon-2.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [-1, 2] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "Polygon", 17 | "coordinates": [ 18 | [ 19 | [-1, 2], 20 | [3, 2], 21 | [3, 3], 22 | [-1, 3], 23 | [-1, 2] 24 | ] 25 | ] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Polygon/LineString/Polygon-Containing-Linestring.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-1, 2], 12 | [3, 2], 13 | [3, 3], 14 | [-1, 3], 15 | [-1, 2] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "LineString", 25 | "coordinates": [ 26 | [1, 2.5], 27 | [2, 2.5] 28 | ] 29 | } 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Polygon/LineString/Polygon-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-1, 2], 12 | [3, 2], 13 | [3, 3], 14 | [-1, 3], 15 | [-1, 2] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "LineString", 25 | "coordinates": [ 26 | [0, 2], 27 | [12, 2], 28 | [12, 3], 29 | [12, 4] 30 | ] 31 | } 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Polygon/MultiPolygon/Polygon-MultiPolygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": { 7 | "fill": "#0000ff" 8 | }, 9 | "geometry": { 10 | "type": "Polygon", 11 | "coordinates": [ 12 | [ 13 | [119.20166015624999, -22.776181505086495], 14 | [125.09033203124999, -22.776181505086495], 15 | [125.09033203124999, -18.417078658661257], 16 | [119.20166015624999, -18.417078658661257], 17 | [119.20166015624999, -22.776181505086495] 18 | ] 19 | ] 20 | } 21 | }, 22 | { 23 | "type": "Feature", 24 | "properties": { 25 | "fill": "#ff0000" 26 | }, 27 | "geometry": { 28 | "type": "MultiPolygon", 29 | "coordinates": [ 30 | [ 31 | [ 32 | [122.6953125, -19.186677697957833], 33 | [128.759765625, -19.186677697957833], 34 | [128.759765625, -15.28418511407642], 35 | [122.6953125, -15.28418511407642], 36 | [122.6953125, -19.186677697957833] 37 | ] 38 | ], 39 | [ 40 | [ 41 | [123.74999999999999, -25.918526162075153], 42 | [130.25390625, -25.918526162075153], 43 | [130.25390625, -20.715015145512087], 44 | [123.74999999999999, -20.715015145512087], 45 | [123.74999999999999, -25.918526162075153] 46 | ] 47 | ] 48 | ] 49 | } 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Polygon/Point/Polygon-Point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-1, 2], 12 | [3, 2], 13 | [3, 3], 14 | [-1, 3], 15 | [-1, 2] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "Point", 25 | "coordinates": [1, 2.5] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Polygon/Polygon/Large-Inside-Small.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [19.6875, 34.016241889667015], 12 | [14.765625, 26.745610382199022], 13 | [19.6875, 23.563987128451217], 14 | [23.203125, 26.43122806450644], 15 | [22.148437499999996, 30.44867367928756], 16 | [19.6875, 34.016241889667015] 17 | ] 18 | ] 19 | } 20 | }, 21 | { 22 | "type": "Feature", 23 | "properties": {}, 24 | "geometry": { 25 | "type": "Polygon", 26 | "coordinates": [ 27 | [ 28 | [18.984375, 40.44694705960048], 29 | [7.03125, 25.48295117535531], 30 | [19.335937499999996, 18.979025953255267], 31 | [31.640625, 24.206889622398023], 32 | [24.960937499999996, 34.88593094075317], 33 | [18.984375, 40.44694705960048] 34 | ] 35 | ] 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Polygon/Polygon/Polygon-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-1, 2], 12 | [-13, -12], 13 | [-13, -13], 14 | [-11, -13], 15 | [-1, 2] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "Polygon", 25 | "coordinates": [ 26 | [ 27 | [-1, 2], 28 | [3, 2], 29 | [3, 3], 30 | [-1, 3], 31 | [-1, 2] 32 | ] 33 | ] 34 | } 35 | } 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Polygon/Polygon/Small-Inside-Large.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [18.984375, 40.44694705960048], 12 | [7.03125, 25.48295117535531], 13 | [19.335937499999996, 18.979025953255267], 14 | [31.640625, 24.206889622398023], 15 | [24.960937499999996, 34.88593094075317], 16 | [18.984375, 40.44694705960048] 17 | ] 18 | ] 19 | } 20 | }, 21 | { 22 | "type": "Feature", 23 | "properties": {}, 24 | "geometry": { 25 | "type": "Polygon", 26 | "coordinates": [ 27 | [ 28 | [19.6875, 34.016241889667015], 29 | [14.765625, 26.745610382199022], 30 | [19.6875, 23.563987128451217], 31 | [23.203125, 26.43122806450644], 32 | [22.148437499999996, 30.44867367928756], 33 | [19.6875, 34.016241889667015] 34 | ] 35 | ] 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/false/Polygon/Polygon/issue-1216.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [6.638240782825051, 46.513552354874435], 12 | [6.638240782825051, 46.52452567471025], 13 | [6.632039186485088, 46.52452567471025], 14 | [6.632039186485088, 46.513552354874435], 15 | [6.638240782825051, 46.513552354874435] 16 | ] 17 | ] 18 | }, 19 | "bbox": [ 20 | 6.632039186485088, 46.513552354874435, 6.638240782825051, 46.52452567471025 21 | ] 22 | }, 23 | { 24 | "type": "Feature", 25 | "properties": {}, 26 | "geometry": { 27 | "type": "Polygon", 28 | "coordinates": [ 29 | [ 30 | [6.645459572232596, 46.51709747623775], 31 | [6.645459572232596, 46.52102619404951], 32 | [6.626132904233913, 46.52102619404951], 33 | [6.626132904233913, 46.51709747623775], 34 | [6.645459572232596, 46.51709747623775] 35 | ] 36 | ] 37 | }, 38 | "bbox": [6.626132904233913, 46.51709747623775, 6.645459572232596, 46.52102619404951] 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/LineString/LineString/LineString-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [0, 0], 11 | [12, 2], 12 | [12, 3], 13 | [12, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "LineString", 22 | "coordinates": [ 23 | [1, 1], 24 | [1, 2], 25 | [1, 3], 26 | [1, 4] 27 | ] 28 | } 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/LineString/Point/LineString-Point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [1, 1], 11 | [1, 2], 12 | [1, 3], 13 | [1, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "Point", 22 | "coordinates": [0, 0] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/LineString/Polygon/LineString-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [0, 0], 11 | [12, 2], 12 | [12, 3], 13 | [12, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "Polygon", 22 | "coordinates": [ 23 | [ 24 | [-1, 2], 25 | [3, 2], 26 | [3, 3], 27 | [-1, 3], 28 | [-1, 2] 29 | ] 30 | ] 31 | } 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/MultiPoint/LineString/MultiPoint-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [2, 2], 11 | [0, 0] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "LineString", 20 | "coordinates": [ 21 | [1, 1], 22 | [1, 2], 23 | [1, 3], 24 | [1, 4] 25 | ] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/MultiPoint/MultiPoint/MultiPoint-MultiPoint.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [0, 0], 11 | [13, 13] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "MultiPoint", 20 | "coordinates": [ 21 | [1, 1], 22 | [12, 12] 23 | ] 24 | } 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/MultiPoint/Point/MultiPoint-Point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [1, 1], 11 | [12, 12] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "Point", 20 | "coordinates": [0, 0] 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/MultiPoint/Polygon/MultiPoint-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [-3, -3], 11 | [-2, -2] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "Polygon", 20 | "coordinates": [ 21 | [ 22 | [-1, 2], 23 | [3, 2], 24 | [3, 3], 25 | [-1, 3], 26 | [-1, 2] 27 | ] 28 | ] 29 | } 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/MultiPolygon/Polygon/MultiPolygon-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": { 7 | "fill": "#ff0000" 8 | }, 9 | "geometry": { 10 | "type": "MultiPolygon", 11 | "coordinates": [ 12 | [ 13 | [ 14 | [122.6953125, -19.186677697957833], 15 | [128.759765625, -19.186677697957833], 16 | [128.759765625, -15.28418511407642], 17 | [122.6953125, -15.28418511407642], 18 | [122.6953125, -19.186677697957833] 19 | ] 20 | ], 21 | [ 22 | [ 23 | [123.74999999999999, -25.918526162075153], 24 | [130.25390625, -25.918526162075153], 25 | [130.25390625, -20.715015145512087], 26 | [123.74999999999999, -20.715015145512087], 27 | [123.74999999999999, -25.918526162075153] 28 | ] 29 | ] 30 | ] 31 | } 32 | }, 33 | { 34 | "type": "Feature", 35 | "properties": { 36 | "fill": "#0000ff" 37 | }, 38 | "geometry": { 39 | "type": "Polygon", 40 | "coordinates": [ 41 | [ 42 | [116.98242187499999, -24.647017162630352], 43 | [122.87109375, -24.647017162630352], 44 | [122.87109375, -20.34462694382967], 45 | [116.98242187499999, -20.34462694382967], 46 | [116.98242187499999, -24.647017162630352] 47 | ] 48 | ] 49 | } 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/Point/LineString/Point-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [0, 0] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "LineString", 17 | "coordinates": [ 18 | [1, 1], 19 | [1, 2], 20 | [1, 3], 21 | [1, 4] 22 | ] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/Point/MultiPoint/Point-Multipoint.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [0, 0] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "MultiPoint", 17 | "coordinates": [ 18 | [1, 1], 19 | [12, 12] 20 | ] 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/Point/Point/Point-Point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [0, 0] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "Point", 17 | "coordinates": [0, 1] 18 | } 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/Point/Polygon/Point-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [1, 1] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "Polygon", 17 | "coordinates": [ 18 | [ 19 | [-1, 2], 20 | [3, 2], 21 | [3, 3], 22 | [-1, 3], 23 | [-1, 2] 24 | ] 25 | ] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/Polygon/LineString/Polygon-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-1, 2], 12 | [3, 2], 13 | [3, 3], 14 | [-1, 3], 15 | [-1, 2] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "LineString", 25 | "coordinates": [ 26 | [0, 0], 27 | [12, 2], 28 | [12, 3], 29 | [12, 4] 30 | ] 31 | } 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/Polygon/MultiPolygon/Polygon-MultiPolygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": { 7 | "fill": "#0000ff" 8 | }, 9 | "geometry": { 10 | "type": "Polygon", 11 | "coordinates": [ 12 | [ 13 | [116.98242187499999, -24.647017162630352], 14 | [122.87109375, -24.647017162630352], 15 | [122.87109375, -20.34462694382967], 16 | [116.98242187499999, -20.34462694382967], 17 | [116.98242187499999, -24.647017162630352] 18 | ] 19 | ] 20 | } 21 | }, 22 | { 23 | "type": "Feature", 24 | "properties": { 25 | "fill": "#ff0000" 26 | }, 27 | "geometry": { 28 | "type": "MultiPolygon", 29 | "coordinates": [ 30 | [ 31 | [ 32 | [122.6953125, -19.186677697957833], 33 | [128.759765625, -19.186677697957833], 34 | [128.759765625, -15.28418511407642], 35 | [122.6953125, -15.28418511407642], 36 | [122.6953125, -19.186677697957833] 37 | ] 38 | ], 39 | [ 40 | [ 41 | [123.74999999999999, -25.918526162075153], 42 | [130.25390625, -25.918526162075153], 43 | [130.25390625, -20.715015145512087], 44 | [123.74999999999999, -20.715015145512087], 45 | [123.74999999999999, -25.918526162075153] 46 | ] 47 | ] 48 | ] 49 | } 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/Polygon/Point/Polygon-Point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-1, 2], 12 | [3, 2], 13 | [3, 3], 14 | [-1, 3], 15 | [-1, 2] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "Point", 25 | "coordinates": [1, 1] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_disjoint_test/true/Polygon/Polygon/Polygon-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-11, -12], 12 | [-13, -12], 13 | [-13, -13], 14 | [-11, -13], 15 | [-11, -12] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "Polygon", 25 | "coordinates": [ 26 | [ 27 | [-1, 2], 28 | [3, 2], 29 | [3, 3], 30 | [-1, 3], 31 | [-1, 2] 32 | ] 33 | ] 34 | } 35 | } 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/LineString/LineString/LineString-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [0, 0], 11 | [12, 2], 12 | [12, 3], 13 | [12, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "LineString", 22 | "coordinates": [ 23 | [1, 1], 24 | [1, 2], 25 | [1, 3], 26 | [1, 4] 27 | ] 28 | } 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/LineString/Point/LineString-Point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [1, 1], 11 | [1, 2], 12 | [1, 3], 13 | [1, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "Point", 22 | "coordinates": [0, 0] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/LineString/Polygon/LineString-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [0, 0], 11 | [12, 2], 12 | [12, 3], 13 | [12, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "Polygon", 22 | "coordinates": [ 23 | [ 24 | [-1, 2], 25 | [3, 2], 26 | [3, 3], 27 | [-1, 3], 28 | [-1, 2] 29 | ] 30 | ] 31 | } 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/MultiPoint/LineString/MultiPoint-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [2, 2], 11 | [0, 0] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "LineString", 20 | "coordinates": [ 21 | [1, 1], 22 | [1, 2], 23 | [1, 3], 24 | [1, 4] 25 | ] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/MultiPoint/MultiPoint/MultiPoint-MultiPoint.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [0, 0], 11 | [13, 13] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "MultiPoint", 20 | "coordinates": [ 21 | [1, 1], 22 | [12, 12] 23 | ] 24 | } 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/MultiPoint/Point/MultiPoint-Point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [1, 1], 11 | [12, 12] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "Point", 20 | "coordinates": [0, 0] 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/MultiPoint/Polygon/MultiPoint-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [-3, -3], 11 | [-2, -2] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "Polygon", 20 | "coordinates": [ 21 | [ 22 | [-1, 2], 23 | [3, 2], 24 | [3, 3], 25 | [-1, 3], 26 | [-1, 2] 27 | ] 28 | ] 29 | } 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/MultiPolygon/Polygon/MultiPolygon-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": { 7 | "fill": "#ff0000" 8 | }, 9 | "geometry": { 10 | "type": "MultiPolygon", 11 | "coordinates": [ 12 | [ 13 | [ 14 | [122.6953125, -19.186677697957833], 15 | [128.759765625, -19.186677697957833], 16 | [128.759765625, -15.28418511407642], 17 | [122.6953125, -15.28418511407642], 18 | [122.6953125, -19.186677697957833] 19 | ] 20 | ], 21 | [ 22 | [ 23 | [123.74999999999999, -25.918526162075153], 24 | [130.25390625, -25.918526162075153], 25 | [130.25390625, -20.715015145512087], 26 | [123.74999999999999, -20.715015145512087], 27 | [123.74999999999999, -25.918526162075153] 28 | ] 29 | ] 30 | ] 31 | } 32 | }, 33 | { 34 | "type": "Feature", 35 | "properties": { 36 | "fill": "#0000ff" 37 | }, 38 | "geometry": { 39 | "type": "Polygon", 40 | "coordinates": [ 41 | [ 42 | [116.98242187499999, -24.647017162630352], 43 | [122.87109375, -24.647017162630352], 44 | [122.87109375, -20.34462694382967], 45 | [116.98242187499999, -20.34462694382967], 46 | [116.98242187499999, -24.647017162630352] 47 | ] 48 | ] 49 | } 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/Point/LineString/Point-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [0, 0] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "LineString", 17 | "coordinates": [ 18 | [1, 1], 19 | [1, 2], 20 | [1, 3], 21 | [1, 4] 22 | ] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/Point/MultiPoint/Point-Multipoint.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [0, 0] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "MultiPoint", 17 | "coordinates": [ 18 | [1, 1], 19 | [12, 12] 20 | ] 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/Point/Point/Point-Point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [0, 0] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "Point", 17 | "coordinates": [0, 1] 18 | } 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/Point/Polygon/Point-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [1, 1] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "Polygon", 17 | "coordinates": [ 18 | [ 19 | [-1, 2], 20 | [3, 2], 21 | [3, 3], 22 | [-1, 3], 23 | [-1, 2] 24 | ] 25 | ] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/Polygon/LineString/Polygon-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-1, 2], 12 | [3, 2], 13 | [3, 3], 14 | [-1, 3], 15 | [-1, 2] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "LineString", 25 | "coordinates": [ 26 | [0, 0], 27 | [12, 2], 28 | [12, 3], 29 | [12, 4] 30 | ] 31 | } 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/Polygon/MultiPolygon/Polygon-MultiPolygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": { 7 | "fill": "#0000ff" 8 | }, 9 | "geometry": { 10 | "type": "Polygon", 11 | "coordinates": [ 12 | [ 13 | [116.98242187499999, -24.647017162630352], 14 | [122.87109375, -24.647017162630352], 15 | [122.87109375, -20.34462694382967], 16 | [116.98242187499999, -20.34462694382967], 17 | [116.98242187499999, -24.647017162630352] 18 | ] 19 | ] 20 | } 21 | }, 22 | { 23 | "type": "Feature", 24 | "properties": { 25 | "fill": "#ff0000" 26 | }, 27 | "geometry": { 28 | "type": "MultiPolygon", 29 | "coordinates": [ 30 | [ 31 | [ 32 | [122.6953125, -19.186677697957833], 33 | [128.759765625, -19.186677697957833], 34 | [128.759765625, -15.28418511407642], 35 | [122.6953125, -15.28418511407642], 36 | [122.6953125, -19.186677697957833] 37 | ] 38 | ], 39 | [ 40 | [ 41 | [123.74999999999999, -25.918526162075153], 42 | [130.25390625, -25.918526162075153], 43 | [130.25390625, -20.715015145512087], 44 | [123.74999999999999, -20.715015145512087], 45 | [123.74999999999999, -25.918526162075153] 46 | ] 47 | ] 48 | ] 49 | } 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/Polygon/Point/Polygon-Point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-1, 2], 12 | [3, 2], 13 | [3, 3], 14 | [-1, 3], 15 | [-1, 2] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "Point", 25 | "coordinates": [1, 1] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/false/Polygon/Polygon/Polygon-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-11, -12], 12 | [-13, -12], 13 | [-13, -13], 14 | [-11, -13], 15 | [-11, -12] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "Polygon", 25 | "coordinates": [ 26 | [ 27 | [-1, 2], 28 | [3, 2], 29 | [3, 3], 30 | [-1, 3], 31 | [-1, 2] 32 | ] 33 | ] 34 | } 35 | } 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/LineString/LineString/LineString-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [0, 2], 11 | [12, 2], 12 | [12, 3], 13 | [12, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "LineString", 22 | "coordinates": [ 23 | [1, 1], 24 | [1, 2], 25 | [1, 3], 26 | [1, 4] 27 | ] 28 | } 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/LineString/Point/LineString-Point-1.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [1, 1], 11 | [1, 2], 12 | [1, 3], 13 | [1, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "Point", 22 | "coordinates": [1, 1] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/LineString/Point/LineString-Point-2.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [1, 1], 11 | [1, 2], 12 | [1, 3], 13 | [1, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "Point", 22 | "coordinates": [1, 1.5] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/LineString/Polygon/LineString-In-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [1, 2.5], 11 | [2, 2.5] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "Polygon", 20 | "coordinates": [ 21 | [ 22 | [-1, 2], 23 | [3, 2], 24 | [3, 3], 25 | [-1, 3], 26 | [-1, 2] 27 | ] 28 | ] 29 | } 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/LineString/Polygon/LineString-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [0, 2], 11 | [12, 2], 12 | [12, 3], 13 | [12, 4] 14 | ] 15 | } 16 | }, 17 | { 18 | "type": "Feature", 19 | "properties": {}, 20 | "geometry": { 21 | "type": "Polygon", 22 | "coordinates": [ 23 | [ 24 | [-1, 2], 25 | [3, 2], 26 | [3, 3], 27 | [-1, 3], 28 | [-1, 2] 29 | ] 30 | ] 31 | } 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/MultiPoint/LineString/MultiPoint-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [1, 1], 11 | [0, 0] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "LineString", 20 | "coordinates": [ 21 | [1, 1], 22 | [1, 2], 23 | [1, 3], 24 | [1, 4] 25 | ] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/MultiPoint/MultiPoint/MultiPoint-MultiPoint.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [0, 0], 11 | [12, 12] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "MultiPoint", 20 | "coordinates": [ 21 | [0, 0], 22 | [12, 12] 23 | ] 24 | } 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/MultiPoint/Polygon/MultiPoint-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "MultiPoint", 9 | "coordinates": [ 10 | [-1, 2], 11 | [-2, -2] 12 | ] 13 | } 14 | }, 15 | { 16 | "type": "Feature", 17 | "properties": {}, 18 | "geometry": { 19 | "type": "Polygon", 20 | "coordinates": [ 21 | [ 22 | [-1, 2], 23 | [3, 2], 24 | [3, 3], 25 | [-1, 3], 26 | [-1, 2] 27 | ] 28 | ] 29 | } 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/MultiPolygon/Polygon/MultiPolygon-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": { 7 | "fill": "#ff0000" 8 | }, 9 | "geometry": { 10 | "type": "MultiPolygon", 11 | "coordinates": [ 12 | [ 13 | [ 14 | [122.6953125, -19.186677697957833], 15 | [128.759765625, -19.186677697957833], 16 | [128.759765625, -15.28418511407642], 17 | [122.6953125, -15.28418511407642], 18 | [122.6953125, -19.186677697957833] 19 | ] 20 | ], 21 | [ 22 | [ 23 | [123.74999999999999, -25.918526162075153], 24 | [130.25390625, -25.918526162075153], 25 | [130.25390625, -20.715015145512087], 26 | [123.74999999999999, -20.715015145512087], 27 | [123.74999999999999, -25.918526162075153] 28 | ] 29 | ] 30 | ] 31 | } 32 | }, 33 | { 34 | "type": "Feature", 35 | "properties": { 36 | "fill": "#0000ff" 37 | }, 38 | "geometry": { 39 | "type": "Polygon", 40 | "coordinates": [ 41 | [ 42 | [119.20166015624999, -22.776181505086495], 43 | [125.09033203124999, -22.776181505086495], 44 | [125.09033203124999, -18.417078658661257], 45 | [119.20166015624999, -18.417078658661257], 46 | [119.20166015624999, -22.776181505086495] 47 | ] 48 | ] 49 | } 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Point/LineString/Point-LineString-1.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [1, 1] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "LineString", 17 | "coordinates": [ 18 | [1, 1], 19 | [1, 2], 20 | [1, 3], 21 | [1, 4] 22 | ] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Point/LineString/Point-LineString-2.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [1, 1.5] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "LineString", 17 | "coordinates": [ 18 | [1, 1], 19 | [1, 2], 20 | [1, 3], 21 | [1, 4] 22 | ] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Point/LineString/Point-LineString-3.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [2.5, 1] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "LineString", 17 | "coordinates": [ 18 | [1, 1], 19 | [2, 1], 20 | [3, 1], 21 | [4, 1] 22 | ] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Point/LineString/Point-LineString-4.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [2.5, 2.5] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "LineString", 17 | "coordinates": [ 18 | [1, 1], 19 | [2, 2], 20 | [3, 3], 21 | [4, 4] 22 | ] 23 | } 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Point/MultiPoint/Point-MultiPoint.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [1, 1] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "MultiPoint", 17 | "coordinates": [ 18 | [1, 1], 19 | [12, 12] 20 | ] 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Point/Point/Point-Point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [0, 0] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "Point", 17 | "coordinates": [0, 0] 18 | } 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Point/Polygon/Point-Polygon-1.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [1, 2.5] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "Polygon", 17 | "coordinates": [ 18 | [ 19 | [-1, 2], 20 | [3, 2], 21 | [3, 3], 22 | [-1, 3], 23 | [-1, 2] 24 | ] 25 | ] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Point/Polygon/Point-Polygon-2.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [-1, 2] 10 | } 11 | }, 12 | { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "Polygon", 17 | "coordinates": [ 18 | [ 19 | [-1, 2], 20 | [3, 2], 21 | [3, 3], 22 | [-1, 3], 23 | [-1, 2] 24 | ] 25 | ] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Polygon/LineString/Polygon-Containing-Linestring.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-1, 2], 12 | [3, 2], 13 | [3, 3], 14 | [-1, 3], 15 | [-1, 2] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "LineString", 25 | "coordinates": [ 26 | [1, 2.5], 27 | [2, 2.5] 28 | ] 29 | } 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Polygon/LineString/Polygon-LineString.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-1, 2], 12 | [3, 2], 13 | [3, 3], 14 | [-1, 3], 15 | [-1, 2] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "LineString", 25 | "coordinates": [ 26 | [0, 2], 27 | [12, 2], 28 | [12, 3], 29 | [12, 4] 30 | ] 31 | } 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Polygon/MultiPolygon/Polygon-MultiPolygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": { 7 | "fill": "#0000ff" 8 | }, 9 | "geometry": { 10 | "type": "Polygon", 11 | "coordinates": [ 12 | [ 13 | [119.20166015624999, -22.776181505086495], 14 | [125.09033203124999, -22.776181505086495], 15 | [125.09033203124999, -18.417078658661257], 16 | [119.20166015624999, -18.417078658661257], 17 | [119.20166015624999, -22.776181505086495] 18 | ] 19 | ] 20 | } 21 | }, 22 | { 23 | "type": "Feature", 24 | "properties": { 25 | "fill": "#ff0000" 26 | }, 27 | "geometry": { 28 | "type": "MultiPolygon", 29 | "coordinates": [ 30 | [ 31 | [ 32 | [122.6953125, -19.186677697957833], 33 | [128.759765625, -19.186677697957833], 34 | [128.759765625, -15.28418511407642], 35 | [122.6953125, -15.28418511407642], 36 | [122.6953125, -19.186677697957833] 37 | ] 38 | ], 39 | [ 40 | [ 41 | [123.74999999999999, -25.918526162075153], 42 | [130.25390625, -25.918526162075153], 43 | [130.25390625, -20.715015145512087], 44 | [123.74999999999999, -20.715015145512087], 45 | [123.74999999999999, -25.918526162075153] 46 | ] 47 | ] 48 | ] 49 | } 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Polygon/Point/Polygon-Point.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-1, 2], 12 | [3, 2], 13 | [3, 3], 14 | [-1, 3], 15 | [-1, 2] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "Point", 25 | "coordinates": [1, 2.5] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Polygon/Polygon/Large-Inside-Small.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [19.6875, 34.016241889667015], 12 | [14.765625, 26.745610382199022], 13 | [19.6875, 23.563987128451217], 14 | [23.203125, 26.43122806450644], 15 | [22.148437499999996, 30.44867367928756], 16 | [19.6875, 34.016241889667015] 17 | ] 18 | ] 19 | } 20 | }, 21 | { 22 | "type": "Feature", 23 | "properties": {}, 24 | "geometry": { 25 | "type": "Polygon", 26 | "coordinates": [ 27 | [ 28 | [18.984375, 40.44694705960048], 29 | [7.03125, 25.48295117535531], 30 | [19.335937499999996, 18.979025953255267], 31 | [31.640625, 24.206889622398023], 32 | [24.960937499999996, 34.88593094075317], 33 | [18.984375, 40.44694705960048] 34 | ] 35 | ] 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Polygon/Polygon/Polygon-Polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-1, 2], 12 | [-13, -12], 13 | [-13, -13], 14 | [-11, -13], 15 | [-1, 2] 16 | ] 17 | ] 18 | } 19 | }, 20 | { 21 | "type": "Feature", 22 | "properties": {}, 23 | "geometry": { 24 | "type": "Polygon", 25 | "coordinates": [ 26 | [ 27 | [-1, 2], 28 | [3, 2], 29 | [3, 3], 30 | [-1, 3], 31 | [-1, 2] 32 | ] 33 | ] 34 | } 35 | } 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Polygon/Polygon/Small-Inside-Large.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [18.984375, 40.44694705960048], 12 | [7.03125, 25.48295117535531], 13 | [19.335937499999996, 18.979025953255267], 14 | [31.640625, 24.206889622398023], 15 | [24.960937499999996, 34.88593094075317], 16 | [18.984375, 40.44694705960048] 17 | ] 18 | ] 19 | } 20 | }, 21 | { 22 | "type": "Feature", 23 | "properties": {}, 24 | "geometry": { 25 | "type": "Polygon", 26 | "coordinates": [ 27 | [ 28 | [19.6875, 34.016241889667015], 29 | [14.765625, 26.745610382199022], 30 | [19.6875, 23.563987128451217], 31 | [23.203125, 26.43122806450644], 32 | [22.148437499999996, 30.44867367928756], 33 | [19.6875, 34.016241889667015] 34 | ] 35 | ] 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /tests/boolean_intersects_test/true/Polygon/Polygon/issue-1216.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": {}, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [6.638240782825051, 46.513552354874435], 12 | [6.638240782825051, 46.52452567471025], 13 | [6.632039186485088, 46.52452567471025], 14 | [6.632039186485088, 46.513552354874435], 15 | [6.638240782825051, 46.513552354874435] 16 | ] 17 | ] 18 | }, 19 | "bbox": [ 20 | 6.632039186485088, 46.513552354874435, 6.638240782825051, 46.52452567471025 21 | ] 22 | }, 23 | { 24 | "type": "Feature", 25 | "properties": {}, 26 | "geometry": { 27 | "type": "Polygon", 28 | "coordinates": [ 29 | [ 30 | [6.645459572232596, 46.51709747623775], 31 | [6.645459572232596, 46.52102619404951], 32 | [6.626132904233913, 46.52102619404951], 33 | [6.626132904233913, 46.51709747623775], 34 | [6.645459572232596, 46.51709747623775] 35 | ] 36 | ] 37 | }, 38 | "bbox": [6.626132904233913, 46.51709747623775, 6.645459572232596, 46.52102619404951] 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /tests/feature_conversion_polygon_to_line_test/in/geometry-polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Polygon", 3 | "coordinates": [ 4 | [ 5 | [-2.275543, 53.464547], 6 | [-2.275543, 53.489271], 7 | [-2.215118, 53.489271], 8 | [-2.215118, 53.464547], 9 | [-2.275543, 53.464547] 10 | ] 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /tests/feature_conversion_polygon_to_line_test/in/multi-polygon-outer-doughnut.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "properties": { 4 | "stroke": "#F0F", 5 | "stroke-width": 6 6 | }, 7 | "geometry": { 8 | "type": "MultiPolygon", 9 | "coordinates": [ 10 | [ 11 | [ 12 | [115.927734375, -34.016241889667015], 13 | [134.560546875, -34.016241889667015], 14 | [134.560546875, -16.8886597873816], 15 | [115.927734375, -16.8886597873816], 16 | [115.927734375, -34.016241889667015] 17 | ], 18 | [ 19 | [118.65234374999999, -30.90222470517144], 20 | [131.484375, -30.90222470517144], 21 | [131.484375, -19.808054128088575], 22 | [118.65234374999999, -19.808054128088575], 23 | [118.65234374999999, -30.90222470517144] 24 | ] 25 | ], 26 | [ 27 | [ 28 | [120.9375, -28.998531814051795], 29 | [129.7265625, -28.998531814051795], 30 | [129.7265625, -22.105998799750566], 31 | [120.9375, -22.105998799750566], 32 | [120.9375, -28.998531814051795] 33 | ], 34 | [ 35 | [123.48632812499999, -27.137368359795584], 36 | [127.44140625, -27.137368359795584], 37 | [127.44140625, -24.126701958681668], 38 | [123.48632812499999, -24.126701958681668], 39 | [123.48632812499999, -27.137368359795584] 40 | ] 41 | ] 42 | ] 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/feature_conversion_polygon_to_line_test/in/multi-polygon-with-holes.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "properties": { 4 | "stroke": "#F00", 5 | "stroke-width": 6 6 | }, 7 | "geometry": { 8 | "type": "MultiPolygon", 9 | "coordinates": [ 10 | [ 11 | [ 12 | [102, 2], 13 | [103, 2], 14 | [103, 3], 15 | [102, 3], 16 | [102, 2] 17 | ], 18 | [ 19 | [102.227783203125, 2.191238104506552], 20 | [102.227783203125, 2.8223442468940902], 21 | [102.843017578125, 2.8223442468940902], 22 | [102.843017578125, 2.191238104506552], 23 | [102.227783203125, 2.191238104506552] 24 | ] 25 | ], 26 | [ 27 | [ 28 | [100, 0], 29 | [101, 0], 30 | [101, 1], 31 | [100, 1], 32 | [100, 0] 33 | ], 34 | [ 35 | [100.206298828125, 0.2526847277643438], 36 | [100.206298828125, 0.7909904981540058], 37 | [100.8050537109375, 0.7909904981540058], 38 | [100.8050537109375, 0.2526847277643438], 39 | [100.206298828125, 0.2526847277643438] 40 | ] 41 | ], 42 | [ 43 | [ 44 | [101.700439453125, 0.5273363048115169], 45 | [102.645263671875, 0.5273363048115169], 46 | [102.645263671875, 1.3511930983018892], 47 | [101.700439453125, 1.3511930983018892], 48 | [101.700439453125, 0.5273363048115169] 49 | ] 50 | ] 51 | ] 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/feature_conversion_polygon_to_line_test/in/multi-polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "properties": { 4 | "stroke": "#F00", 5 | "stroke-width": 6 6 | }, 7 | "geometry": { 8 | "type": "MultiPolygon", 9 | "coordinates": [ 10 | [ 11 | [ 12 | [102, 2], 13 | [103, 2], 14 | [103, 3], 15 | [102, 3], 16 | [102, 2] 17 | ] 18 | ], 19 | [ 20 | [ 21 | [100, 0], 22 | [101, 0], 23 | [101, 1], 24 | [100, 1], 25 | [100, 0] 26 | ] 27 | ] 28 | ] 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/feature_conversion_polygon_to_line_test/in/polygon-with-hole.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "properties": { 4 | "stroke": "#F00", 5 | "stroke-width": 6 6 | }, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-2.275543, 53.464547], 12 | [-2.215118, 53.464547], 13 | [-2.215118, 53.489271], 14 | [-2.275543, 53.489271], 15 | [-2.275543, 53.464547] 16 | ], 17 | [ 18 | [-2.261037826538086, 53.47062762161877], 19 | [-2.2293663024902344, 53.47062762161877], 20 | [-2.2293663024902344, 53.48196795587917], 21 | [-2.261037826538086, 53.48196795587917], 22 | [-2.261037826538086, 53.47062762161877] 23 | ] 24 | ] 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/feature_conversion_polygon_to_line_test/in/polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "properties": { 4 | "stroke": "#F00", 5 | "stroke-width": 6 6 | }, 7 | "geometry": { 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ 11 | [-2.275543, 53.464547], 12 | [-2.275543, 53.489271], 13 | [-2.215118, 53.489271], 14 | [-2.215118, 53.464547], 15 | [-2.275543, 53.464547] 16 | ] 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/feature_conversion_polygon_to_line_test/out/geometry-polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "properties": {}, 4 | "geometry": { 5 | "type": "LineString", 6 | "coordinates": [ 7 | [-2.275543, 53.464547], 8 | [-2.275543, 53.489271], 9 | [-2.215118, 53.489271], 10 | [-2.215118, 53.464547], 11 | [-2.275543, 53.464547] 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/feature_conversion_polygon_to_line_test/out/multi-polygon-outer-doughnut.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "features": [ 3 | { 4 | "geometry": { 5 | "coordinates": [ 6 | [ 7 | [ 8 | 115.927734, 9 | -34.016242 10 | ], 11 | [ 12 | 134.560547, 13 | -34.016242 14 | ], 15 | [ 16 | 134.560547, 17 | -16.88866 18 | ], 19 | [ 20 | 115.927734, 21 | -16.88866 22 | ], 23 | [ 24 | 115.927734, 25 | -34.016242 26 | ] 27 | ], 28 | [ 29 | [ 30 | 118.652344, 31 | -30.902225 32 | ], 33 | [ 34 | 131.484375, 35 | -30.902225 36 | ], 37 | [ 38 | 131.484375, 39 | -19.808054 40 | ], 41 | [ 42 | 118.652344, 43 | -19.808054 44 | ], 45 | [ 46 | 118.652344, 47 | -30.902225 48 | ] 49 | ] 50 | ], 51 | "type": "MultiLineString" 52 | }, 53 | "properties": { 54 | "stroke": "#F0F", 55 | "stroke-width": 6 56 | }, 57 | "type": "Feature" 58 | }, 59 | { 60 | "geometry": { 61 | "coordinates": [ 62 | [ 63 | [ 64 | 120.9375, 65 | -28.998532 66 | ], 67 | [ 68 | 129.726562, 69 | -28.998532 70 | ], 71 | [ 72 | 129.726562, 73 | -22.105999 74 | ], 75 | [ 76 | 120.9375, 77 | -22.105999 78 | ], 79 | [ 80 | 120.9375, 81 | -28.998532 82 | ] 83 | ], 84 | [ 85 | [ 86 | 123.486328, 87 | -27.137368 88 | ], 89 | [ 90 | 127.441406, 91 | -27.137368 92 | ], 93 | [ 94 | 127.441406, 95 | -24.126702 96 | ], 97 | [ 98 | 123.486328, 99 | -24.126702 100 | ], 101 | [ 102 | 123.486328, 103 | -27.137368 104 | ] 105 | ] 106 | ], 107 | "type": "MultiLineString" 108 | }, 109 | "properties": { 110 | "stroke": "#F0F", 111 | "stroke-width": 6 112 | }, 113 | "type": "Feature" 114 | } 115 | ], 116 | "type": "FeatureCollection" 117 | } -------------------------------------------------------------------------------- /tests/feature_conversion_polygon_to_line_test/out/multi-polygon-with-holes.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "features": [ 3 | { 4 | "geometry": { 5 | "coordinates": [ 6 | [ 7 | [ 8 | 102, 9 | 2 10 | ], 11 | [ 12 | 103, 13 | 2 14 | ], 15 | [ 16 | 103, 17 | 3 18 | ], 19 | [ 20 | 102, 21 | 3 22 | ], 23 | [ 24 | 102, 25 | 2 26 | ] 27 | ], 28 | [ 29 | [ 30 | 102.227783, 31 | 2.191238 32 | ], 33 | [ 34 | 102.227783, 35 | 2.822344 36 | ], 37 | [ 38 | 102.843018, 39 | 2.822344 40 | ], 41 | [ 42 | 102.843018, 43 | 2.191238 44 | ], 45 | [ 46 | 102.227783, 47 | 2.191238 48 | ] 49 | ] 50 | ], 51 | "type": "MultiLineString" 52 | }, 53 | "properties": { 54 | "stroke": "#F00", 55 | "stroke-width": 6 56 | }, 57 | "type": "Feature" 58 | }, 59 | { 60 | "geometry": { 61 | "coordinates": [ 62 | [ 63 | [ 64 | 100, 65 | 0 66 | ], 67 | [ 68 | 101, 69 | 0 70 | ], 71 | [ 72 | 101, 73 | 1 74 | ], 75 | [ 76 | 100, 77 | 1 78 | ], 79 | [ 80 | 100, 81 | 0 82 | ] 83 | ], 84 | [ 85 | [ 86 | 100.206299, 87 | 0.252685 88 | ], 89 | [ 90 | 100.206299, 91 | 0.79099 92 | ], 93 | [ 94 | 100.805054, 95 | 0.79099 96 | ], 97 | [ 98 | 100.805054, 99 | 0.252685 100 | ], 101 | [ 102 | 100.206299, 103 | 0.252685 104 | ] 105 | ] 106 | ], 107 | "type": "MultiLineString" 108 | }, 109 | "properties": { 110 | "stroke": "#F00", 111 | "stroke-width": 6 112 | }, 113 | "type": "Feature" 114 | }, 115 | { 116 | "geometry": { 117 | "coordinates": [ 118 | [ 119 | 101.700439, 120 | 0.527336 121 | ], 122 | [ 123 | 102.645264, 124 | 0.527336 125 | ], 126 | [ 127 | 102.645264, 128 | 1.351193 129 | ], 130 | [ 131 | 101.700439, 132 | 1.351193 133 | ], 134 | [ 135 | 101.700439, 136 | 0.527336 137 | ] 138 | ], 139 | "type": "LineString" 140 | }, 141 | "properties": { 142 | "stroke": "#F00", 143 | "stroke-width": 6 144 | }, 145 | "type": "Feature" 146 | } 147 | ], 148 | "type": "FeatureCollection" 149 | } -------------------------------------------------------------------------------- /tests/feature_conversion_polygon_to_line_test/out/multi-polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": { 7 | "stroke": "#F00", 8 | "stroke-width": 6 9 | }, 10 | "geometry": { 11 | "type": "LineString", 12 | "coordinates": [ 13 | [102, 2], 14 | [103, 2], 15 | [103, 3], 16 | [102, 3], 17 | [102, 2] 18 | ] 19 | } 20 | }, 21 | { 22 | "type": "Feature", 23 | "properties": { 24 | "stroke": "#F00", 25 | "stroke-width": 6 26 | }, 27 | "geometry": { 28 | "type": "LineString", 29 | "coordinates": [ 30 | [100, 0], 31 | [101, 0], 32 | [101, 1], 33 | [100, 1], 34 | [100, 0] 35 | ] 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /tests/feature_conversion_polygon_to_line_test/out/polygon-with-hole.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "geometry": { 3 | "coordinates": [ 4 | [ 5 | [ 6 | -2.275543, 7 | 53.464547 8 | ], 9 | [ 10 | -2.215118, 11 | 53.464547 12 | ], 13 | [ 14 | -2.215118, 15 | 53.489271 16 | ], 17 | [ 18 | -2.275543, 19 | 53.489271 20 | ], 21 | [ 22 | -2.275543, 23 | 53.464547 24 | ] 25 | ], 26 | [ 27 | [ 28 | -2.261038, 29 | 53.470628 30 | ], 31 | [ 32 | -2.229366, 33 | 53.470628 34 | ], 35 | [ 36 | -2.229366, 37 | 53.481968 38 | ], 39 | [ 40 | -2.261038, 41 | 53.481968 42 | ], 43 | [ 44 | -2.261038, 45 | 53.470628 46 | ] 47 | ] 48 | ], 49 | "type": "MultiLineString" 50 | }, 51 | "properties": { 52 | "stroke": "#F00", 53 | "stroke-width": 6 54 | }, 55 | "type": "Feature" 56 | } -------------------------------------------------------------------------------- /tests/feature_conversion_polygon_to_line_test/out/polygon.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "properties": { 4 | "stroke": "#F00", 5 | "stroke-width": 6 6 | }, 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [-2.275543, 53.464547], 11 | [-2.275543, 53.489271], 12 | [-2.215118, 53.489271], 13 | [-2.215118, 53.464547], 14 | [-2.275543, 53.464547] 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/test_boolean.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test module for booleans. 3 | """ 4 | 5 | import glob 6 | import json 7 | import os 8 | import unittest 9 | 10 | from turfpy.boolean import boolean_disjoint, boolean_intersects 11 | 12 | 13 | def load_json_file_sync(filepath): 14 | with open(filepath) as f: 15 | return json.load(f) 16 | 17 | 18 | class TestTurfBooleanDisjoint(unittest.TestCase): 19 | def setUp(self): 20 | self.dirname = os.path.dirname(os.path.abspath(__file__)) 21 | 22 | def test_true_fixtures(self): 23 | for filepath in glob.glob( 24 | os.path.join( 25 | self.dirname, "boolean_disjoint_test", "true", "**", "*.geojson" 26 | ), 27 | recursive=True, 28 | ): 29 | geojson = load_json_file_sync(filepath) 30 | feature1 = geojson["features"][0] 31 | feature2 = geojson["features"][1] 32 | result = boolean_disjoint(feature1, feature2) 33 | self.assertTrue(result, True) 34 | 35 | def test_false_fixtures(self): 36 | for filepath in glob.glob( 37 | os.path.join( 38 | self.dirname, "boolean_disjoint_test", "false", "**", "*.geojson" 39 | ), 40 | recursive=True, 41 | ): 42 | geojson = load_json_file_sync(filepath) 43 | feature1 = geojson["features"][0] 44 | feature2 = geojson["features"][1] 45 | result = boolean_disjoint(feature1, feature2) 46 | self.assertFalse(result, False) 47 | 48 | 49 | class TestTurfBooleanIntersects(unittest.TestCase): 50 | def setUp(self): 51 | self.dirname = os.path.dirname(os.path.abspath(__file__)) 52 | 53 | def test_true_fixtures(self): 54 | for filepath in glob.glob( 55 | os.path.join( 56 | self.dirname, "boolean_intersects_test", "true", "**", "*.geojson" 57 | ), 58 | recursive=True, 59 | ): 60 | geojson = load_json_file_sync(filepath) 61 | feature1 = geojson["features"][0] 62 | feature2 = geojson["features"][1] 63 | result = boolean_intersects(feature1, feature2) 64 | self.assertTrue(result, True) 65 | 66 | def test_false_fixtures(self): 67 | for filepath in glob.glob( 68 | os.path.join( 69 | self.dirname, "boolean_intersects_test", "false", "**", "*.geojson" 70 | ), 71 | recursive=True, 72 | ): 73 | geojson = load_json_file_sync(filepath) 74 | feature1 = geojson["features"][0] 75 | feature2 = geojson["features"][1] 76 | result = boolean_intersects(feature1, feature2) 77 | self.assertFalse(result, False) 78 | -------------------------------------------------------------------------------- /tests/test_feature_conversion.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test module for feature conversions. 3 | """ 4 | 5 | import json 6 | import os 7 | import unittest 8 | from pathlib import Path 9 | 10 | from turfpy.feature_conversion import polygon_to_line 11 | 12 | # Define directories 13 | current_dir = Path(__file__).resolve().parent 14 | directories = { 15 | "in": current_dir / "feature_conversion_polygon_to_line_test" / "in", 16 | "out": current_dir / "feature_conversion_polygon_to_line_test" / "out", 17 | } 18 | 19 | # Load fixtures 20 | fixtures = [] 21 | for filename in os.listdir(directories["in"]): 22 | filepath = directories["in"] / filename 23 | with open(filepath, "r") as file: 24 | geojson = json.load(file) 25 | fixtures.append( 26 | { 27 | "filename": filename, 28 | "name": Path(filename).stem, 29 | "geojson": geojson, 30 | } 31 | ) 32 | 33 | 34 | class TestPolygonToLine(unittest.TestCase): 35 | 36 | def test_polygon_to_linestring(self): 37 | for fixture in fixtures: 38 | name = fixture["name"] 39 | filename = fixture["filename"] 40 | geojson = fixture["geojson"] 41 | 42 | # Perform the conversion 43 | results = polygon_to_line(geojson) 44 | 45 | # Load the expected results 46 | with open(directories["out"] / filename, "r") as file: 47 | expected_results = json.load(file) 48 | 49 | # Assert the results are as expected 50 | self.assertEqual(results, expected_results, name) 51 | -------------------------------------------------------------------------------- /tests/test_helper.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module will test all functions in helper module. 3 | """ 4 | 5 | from geojson import Feature, Point, Polygon 6 | 7 | from turfpy.helper import get_coord, get_coords 8 | from turfpy.measurement import distance 9 | 10 | 11 | def test_get_coord(): 12 | """Test get_coord function.""" 13 | 14 | point = Point((73, 19)) 15 | feature = Feature(geometry=point) 16 | flist = [73, 19] 17 | c1 = get_coord(point) 18 | c2 = get_coord(feature) 19 | c3 = get_coord(flist) 20 | assert c1 == [73, 19] 21 | assert c1 == c2 == c3 22 | 23 | # Test for derived class from Feature 24 | class Vertex(Feature): 25 | """Derived from Feature""" 26 | 27 | def __init__(self, node: str, point: Point): 28 | Feature.__init__(self, geometry=point) 29 | self.nodeid = node 30 | 31 | p1 = Point((25.25458, 51.623879)) 32 | f1 = Feature(geometry=p1) 33 | v1 = Vertex("v1", point=p1) 34 | p2 = Point((25.254626, 51.624053)) 35 | f2 = Feature(geometry=p2) 36 | v2 = Vertex("v2", point=p2) 37 | 38 | df = distance(f1, f2) 39 | dv = distance(v1, v2) 40 | assert df == dv 41 | 42 | 43 | def test_get_coords(): 44 | """Test get_coords function""" 45 | poly = Polygon([[(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15), (2.38, 57.322)]]) 46 | coords = get_coords(poly) 47 | assert coords == poly.coordinates 48 | -------------------------------------------------------------------------------- /tests/test_misc.py: -------------------------------------------------------------------------------- 1 | from geojson import Feature, LineString, Point 2 | from pytest import approx 3 | 4 | from turfpy.misc import line_intersect, line_segment, line_slice, nearest_point_on_line 5 | 6 | 7 | def test_line_intersect(): 8 | l1 = Feature(geometry=LineString([[126, -11], [129, -21]])) 9 | l2 = Feature(geometry=LineString([[123, -18], [131, -14]])) 10 | 11 | li = line_intersect(l1, l2) 12 | 13 | assert li["type"] == "FeatureCollection" 14 | assert len(li["features"]) == 1 15 | assert li["features"][0]["geometry"]["coordinates"] == [127.434783, -15.782609] 16 | 17 | 18 | def test_line_segment(): 19 | poly = { 20 | "type": "Feature", 21 | "properties": {}, 22 | "geometry": { 23 | "type": "Polygon", 24 | "coordinates": [ 25 | [ 26 | [51.17431640625, 47.025206001585396], 27 | [45.17578125, 43.13306116240612], 28 | [54.5361328125, 41.85319643776675], 29 | [51.17431640625, 47.025206001585396], 30 | ] 31 | ], 32 | }, 33 | } 34 | 35 | segments = line_segment(poly) 36 | 37 | assert segments["type"] == "FeatureCollection" 38 | assert len(segments["features"]) == 3 39 | assert segments["features"] == [ 40 | { 41 | "bbox": [45.175781, 43.133061, 51.174316, 47.025206], 42 | "geometry": { 43 | "coordinates": [[45.175781, 43.133061], [51.174316, 47.025206]], 44 | "type": "LineString", 45 | }, 46 | "id": 0, 47 | "properties": {}, 48 | "type": "Feature", 49 | }, 50 | { 51 | "bbox": [45.175781, 41.853196, 54.536133, 43.133061], 52 | "geometry": { 53 | "coordinates": [[54.536133, 41.853196], [45.175781, 43.133061]], 54 | "type": "LineString", 55 | }, 56 | "id": 1, 57 | "properties": {}, 58 | "type": "Feature", 59 | }, 60 | { 61 | "bbox": [51.174316, 41.853196, 54.536133, 47.025206], 62 | "geometry": { 63 | "coordinates": [[51.174316, 47.025206], [54.536133, 41.853196]], 64 | "type": "LineString", 65 | }, 66 | "id": 2, 67 | "properties": {}, 68 | "type": "Feature", 69 | }, 70 | ] 71 | 72 | 73 | def test_nearest_point_on_line(): 74 | pt = Point([2.5, 1.75]) 75 | ls = Feature(geometry=LineString([(1, 2), (2, 2), (3, 2)])) 76 | opts = {"key1": "value1", "key2": "value2"} 77 | 78 | npl = nearest_point_on_line(ls, pt, options={"properties": opts.copy()}) 79 | 80 | assert npl.geometry["type"] == "Point" 81 | assert npl.properties["index"] == 1 82 | assert 27.798 == approx(npl.properties["dist"], abs=1e-3) 83 | assert 166.682 == approx(npl.properties["location"], abs=1e-3) 84 | assert npl.geometry.coordinates == approx([2.5, 2], abs=1e-3) 85 | for key in opts.keys(): 86 | assert npl.properties[key] == opts[key] 87 | 88 | 89 | def test_line_slice(): 90 | start = Point([1.5, 1.5]) 91 | stop = Point([4.5, 1.5]) 92 | line = Feature(geometry=LineString([[1, 1], [2, 2], [3, 1], [4, 2], [5, 1]])) 93 | 94 | sliced = line_slice(start, stop, line) 95 | 96 | assert sliced.geometry["type"] == "LineString" 97 | assert len(sliced.geometry["coordinates"]) == 5 98 | crds = line.geometry.coordinates 99 | crds[0] = start.coordinates 100 | crds[4] = stop.coordinates 101 | ref_crds = [i for crd in crds for i in crd] 102 | sliced_crds = [i for crd in sliced.geometry.coordinates for i in crd] 103 | assert sliced_crds == approx(ref_crds, abs=1e-3) 104 | -------------------------------------------------------------------------------- /tests/test_random.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test module for randoms. 3 | """ 4 | 5 | from geojson import Feature, Point 6 | 7 | from turfpy.measurement import bbox, boolean_point_in_polygon 8 | from turfpy.random import random_points, random_position 9 | 10 | 11 | def test_random_position(): 12 | data = { 13 | "type": "Feature", 14 | "properties": {}, 15 | "geometry": { 16 | "type": "Polygon", 17 | "coordinates": [ 18 | [ 19 | [11.953125, 18.979025953255267], 20 | [52.03125, 18.979025953255267], 21 | [52.03125, 46.558860303117164], 22 | [11.953125, 46.558860303117164], 23 | [11.953125, 18.979025953255267], 24 | ] 25 | ], 26 | }, 27 | } 28 | 29 | pos = random_position(bbox=bbox(data)) 30 | assert len(pos) == 2 31 | pos = Feature(geometry=Point(pos)) 32 | assert boolean_point_in_polygon(point=pos, polygon=data) 33 | 34 | 35 | def test_random_points(): 36 | data = { 37 | "type": "Feature", 38 | "properties": {}, 39 | "geometry": { 40 | "type": "Polygon", 41 | "coordinates": [ 42 | [ 43 | [11.953125, 18.979025953255267], 44 | [52.03125, 18.979025953255267], 45 | [52.03125, 46.558860303117164], 46 | [11.953125, 46.558860303117164], 47 | [11.953125, 18.979025953255267], 48 | ] 49 | ], 50 | }, 51 | } 52 | 53 | pos = random_points(count=3, bbox=bbox(data)) 54 | assert len(pos["features"]) == 3 55 | for point in pos["features"]: 56 | assert boolean_point_in_polygon(point=point, polygon=data) 57 | -------------------------------------------------------------------------------- /turfpy/__init__.py: -------------------------------------------------------------------------------- 1 | """A Python library for performing geospatial data analysis which reimplements turf.js 2 | """ 3 | 4 | from .__version__ import __version__ # noqa F401 5 | -------------------------------------------------------------------------------- /turfpy/__version__.py: -------------------------------------------------------------------------------- 1 | """Project version information.""" 2 | 3 | __version__ = "0.0.8" 4 | -------------------------------------------------------------------------------- /turfpy/_compact.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module is used to check if set variables which 3 | can be used to check whether a dependency is installed 4 | or not. 5 | """ 6 | 7 | HAS_PYGEOS = None 8 | 9 | HAS_GEOPANDAS = None 10 | 11 | HAS_RTREE = None 12 | 13 | try: 14 | import pygeos # noqa 15 | 16 | HAS_PYGEOS = True 17 | except ImportError: 18 | HAS_PYGEOS = False 19 | 20 | 21 | try: 22 | import geopandas # noqa 23 | 24 | HAS_GEOPANDAS = True 25 | except ImportError: 26 | HAS_GEOPANDAS = False 27 | 28 | 29 | try: 30 | import rtree # noqa 31 | 32 | HAS_RTREE = True 33 | except ImportError: 34 | HAS_RTREE = False 35 | -------------------------------------------------------------------------------- /turfpy/dev_lib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/omanges/turfpy/db510553a6166f6e4b4c5d6ec44bc53d02086657/turfpy/dev_lib/__init__.py -------------------------------------------------------------------------------- /turfpy/extra.py: -------------------------------------------------------------------------------- 1 | # def center_of_mass(geojson, properties: dict = None): 2 | # type = get_type(geojson) 3 | # 4 | # if type == 'Point': 5 | # point = Point(geojson['coordinates']) 6 | # return Feature(geometry=point, properties=properties if properties else {}) 7 | # elif type == 'Polygon': 8 | # coords = [] 9 | # 10 | # def callback_coord_each(coord, coord_index, feature_index, multi_feature_index, 11 | # geometry_index): 12 | # nonlocal coords 13 | # coords.append(coord) 14 | # 15 | # coord_each(geojson, callback_coord_each) 16 | # 17 | # centre = centroid(geojson, properties) 18 | # translation = centre['geometry']['coordinates'] 19 | # sx = 0 20 | # sy = 0 21 | # sArea = 0 22 | # 23 | # neutralizedPoints = [] 24 | # 25 | # for point in coords: 26 | # neutralizedPoints.append((point[0] - translation[0], 27 | # point[1] - translation[1])) 28 | # 29 | # for i in range(0, len(coords)): 30 | # pi = neutralizedPoints[i] 31 | # xi = pi[0] 32 | # yi = pi[1] 33 | # 34 | # pj = neutralizedPoints[i + 1] 35 | # xj = pj[0] 36 | # yj = pj[1] 37 | # 38 | # a = xi * yj - xj * yi 39 | # 40 | # sArea += a 41 | # 42 | # sx += (xi + xj) * a 43 | # sy += (yi + yj) * a 44 | # 45 | # if sArea == 0: 46 | # return centre 47 | # else: 48 | # area = sArea * 0.5 49 | # areaFactor = 1 / (6 * area) 50 | # 51 | # point = Point(translation[0] + areaFactor * sx, 52 | # translation[1] + areaFactor * sy) 53 | # 54 | # return Feature(geometry=point, properties=properties if properties else {}) 55 | # 56 | # else: 57 | -------------------------------------------------------------------------------- /turfpy/feature_conversion.py: -------------------------------------------------------------------------------- 1 | from geojson import ( 2 | Feature, 3 | FeatureCollection, 4 | LineString, 5 | MultiLineString, 6 | MultiPolygon, 7 | Polygon, 8 | ) 9 | 10 | from turfpy.helper import get_geom 11 | 12 | 13 | def __coords_to_line(coords, properties) -> Feature: 14 | """ 15 | Convert a list of coordinates to a line 16 | 17 | :param coords: input coordinates 18 | :param properties: properties 19 | :return: A GeoJSON Feature 20 | """ 21 | if len(coords) > 1: 22 | return Feature(geometry=MultiLineString(coords), properties=properties) 23 | return Feature(geometry=LineString(coords[0]), properties=properties) 24 | 25 | 26 | def __single_polygon_to_line(polygon: Polygon, options=None) -> Feature: 27 | """ 28 | Convert a single polygon to a line 29 | 30 | :param polygon: input polygon 31 | :param options: options 32 | :return: A GeoJSON Feature 33 | """ 34 | if options is None: 35 | options = {} 36 | geom = get_geom(polygon) 37 | coords = geom["coordinates"] 38 | properties = options.get("properties", polygon.get("properties", {})) 39 | return __coords_to_line(coords, properties) 40 | 41 | 42 | def __multi_polygon_to_line( 43 | multi_polygon: MultiPolygon, options=None 44 | ) -> FeatureCollection: 45 | """ 46 | Convert a multi polygon to a line 47 | 48 | :param multi_polygon: input multi polygon 49 | :param options: options 50 | :return: A GeoJSON FeatureCollection 51 | """ 52 | if options is None: 53 | options = {} 54 | geom = get_geom(multi_polygon) 55 | coords = geom["coordinates"] 56 | properties = options.get("properties", multi_polygon.get("properties", {})) 57 | lines = [__coords_to_line(coord, properties) for coord in coords] 58 | return FeatureCollection(lines) 59 | 60 | 61 | def polygon_to_line( 62 | polygon: Polygon | MultiPolygon, options=None 63 | ) -> Feature | FeatureCollection: 64 | """ 65 | Convert a polygon to line 66 | 67 | :param polygon: input polygon 68 | :param options: options 69 | :return: A GeoJSON Feature or FeatureCollection 70 | """ 71 | 72 | if options is None: 73 | options = {} 74 | geom = get_geom(polygon) 75 | if not options.get("properties") and polygon["type"] == "Feature": 76 | options["properties"] = polygon.get("properties", {}) 77 | 78 | if geom["type"] == "Polygon": 79 | return __single_polygon_to_line(polygon, options) 80 | elif geom["type"] == "MultiPolygon": 81 | return __multi_polygon_to_line(polygon, options) 82 | else: 83 | raise ValueError("invalid polygon") 84 | -------------------------------------------------------------------------------- /turfpy/random.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module implements some of the methods that allows to 3 | generate some random spatial data. 4 | This is mainly inspired by turf.js. 5 | link: http://turfjs.org/ 6 | """ 7 | 8 | import random 9 | from typing import Any, Optional 10 | 11 | from geojson import Feature, FeatureCollection, Point 12 | 13 | 14 | def random_position(bbox: Optional[list[Any]] = None): 15 | """ 16 | Generates a random position, if bbox provided then the 17 | generated position will be in the bbox. 18 | 19 | :param bbox: Bounding box extent in west, south, east, north order 20 | :return: A position as coordinates. 21 | 22 | Exmample: 23 | 24 | >>> from turfpy.random import random_position 25 | >>> random_position(bbox=[11.953125, 26 | >>> 18.979025953255267, 52.03125, 46.558860303117164]) 27 | """ 28 | if not bbox: 29 | return [lon(), lat()] 30 | 31 | if len(bbox) != 4: 32 | raise Exception("bbox with 4 positions are only supported") 33 | 34 | return coord_in_bbox(bbox) 35 | 36 | 37 | def rnd(): 38 | return random.random() - 0.5 39 | 40 | 41 | def lon(): 42 | return rnd() * 360 43 | 44 | 45 | def lat(): 46 | return rnd() * 180 47 | 48 | 49 | def coord_in_bbox(bbox: list): 50 | return [ 51 | random.random() * (bbox[2] - bbox[0]) + bbox[0], 52 | random.random() * (bbox[3] - bbox[1]) + bbox[1], 53 | ] 54 | 55 | 56 | def random_points(count: int = 1, bbox: Optional[list[Any]] = None) -> FeatureCollection: 57 | """ 58 | Generates geojson random points, if bbox provided then the 59 | generated points will be in the bbox. 60 | 61 | :param count: Number of points to be generated, default value is one. 62 | :param bbox: Bounding box extent in west, south, east, north order 63 | :return: A FeatureCollection of generated points. 64 | 65 | Exmample: 66 | 67 | >>> from turfpy.random import random_points 68 | >>> random_points(count=3, bbox=[11.953125, 69 | >>> 18.979025953255267, 52.03125, 46.558860303117164]) 70 | """ 71 | features = [] 72 | for i in range(count): 73 | features.append(Feature(geometry=Point(random_position(bbox)))) 74 | 75 | return FeatureCollection(features) 76 | --------------------------------------------------------------------------------