geojson


Namegeojson JSON
Version 3.1.0 PyPI version JSON
download
home_pagehttps://github.com/jazzband/geojson
SummaryPython bindings and utilities for GeoJSON
upload_time2023-11-05 21:06:50
maintainerRay Riga
docs_urlNone
authorSean Gillies
requires_python>=3.7
licenseBSD
keywords gis geography json
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            geojson
==============

.. image:: https://github.com/jazzband/geojson/actions/workflows/test.yml/badge.svg
   :target: https://github.com/jazzband/geojson/actions/workflows/test.yml
   :alt: GitHub Actions
.. image:: https://img.shields.io/codecov/c/github/jazzband/geojson.svg
   :target: https://codecov.io/github/jazzband/geojson?branch=main
   :alt: Codecov
.. image:: https://jazzband.co/static/img/badge.svg
   :target: https://jazzband.co/
   :alt: Jazzband

This Python library contains:

- Functions for encoding and decoding GeoJSON_ formatted data
- Classes for all GeoJSON Objects
- An implementation of the Python `__geo_interface__ Specification`_

**Table of Contents**

.. contents::
   :backlinks: none
   :local:

Installation
------------

geojson is compatible with Python 3.7 - 3.12. The recommended way to install is via pip_:

.. code::

  pip install geojson

.. _PyPi as 'geojson': https://pypi.python.org/pypi/geojson/
.. _pip: https://www.pip-installer.org

GeoJSON Objects
---------------

This library implements all the `GeoJSON Objects`_ described in `The GeoJSON Format Specification`_.

.. _GeoJSON Objects: https://tools.ietf.org/html/rfc7946#section-3

All object keys can also be used as attributes.

The objects contained in GeometryCollection and FeatureCollection can be indexed directly.

Point
~~~~~

.. code:: python

  >>> from geojson import Point

  >>> Point((-115.81, 37.24))  # doctest: +ELLIPSIS
  {"coordinates": [-115.8..., 37.2...], "type": "Point"}

Visualize the result of the example above `here <https://gist.github.com/frewsxcv/b5768a857f5598e405fa>`__. General information about Point can be found in `Section 3.1.2`_ and `Appendix A: Points`_ within `The GeoJSON Format Specification`_.

.. _Section 3.1.2: https://tools.ietf.org/html/rfc7946#section-3.1.2
.. _Appendix A\: Points: https://tools.ietf.org/html/rfc7946#appendix-A.1

MultiPoint
~~~~~~~~~~

.. code:: python

  >>> from geojson import MultiPoint

  >>> MultiPoint([(-155.52, 19.61), (-156.22, 20.74), (-157.97, 21.46)])  # doctest: +ELLIPSIS
  {"coordinates": [[-155.5..., 19.6...], [-156.2..., 20.7...], [-157.9..., 21.4...]], "type": "MultiPoint"}

Visualize the result of the example above `here <https://gist.github.com/frewsxcv/be02025c1eb3aa2040ee>`__. General information about MultiPoint can be found in `Section 3.1.3`_ and `Appendix A: MultiPoints`_ within `The GeoJSON Format Specification`_.

.. _Section 3.1.3: https://tools.ietf.org/html/rfc7946#section-3.1.3
.. _Appendix A\: MultiPoints: https://tools.ietf.org/html/rfc7946#appendix-A.4


LineString
~~~~~~~~~~

.. code:: python

  >>> from geojson import LineString

  >>> LineString([(8.919, 44.4074), (8.923, 44.4075)])  # doctest: +ELLIPSIS
  {"coordinates": [[8.91..., 44.407...], [8.92..., 44.407...]], "type": "LineString"}

Visualize the result of the example above `here <https://gist.github.com/frewsxcv/758563182ca49ce8e8bb>`__. General information about LineString can be found in `Section 3.1.4`_ and `Appendix A: LineStrings`_ within `The GeoJSON Format Specification`_.

.. _Section 3.1.4: https://tools.ietf.org/html/rfc7946#section-3.1.4
.. _Appendix A\: LineStrings: https://tools.ietf.org/html/rfc7946#appendix-A.2

MultiLineString
~~~~~~~~~~~~~~~

.. code:: python

  >>> from geojson import MultiLineString

  >>> MultiLineString([
  ...     [(3.75, 9.25), (-130.95, 1.52)],
  ...     [(23.15, -34.25), (-1.35, -4.65), (3.45, 77.95)]
  ... ])  # doctest: +ELLIPSIS
  {"coordinates": [[[3.7..., 9.2...], [-130.9..., 1.52...]], [[23.1..., -34.2...], [-1.3..., -4.6...], [3.4..., 77.9...]]], "type": "MultiLineString"}

Visualize the result of the example above `here <https://gist.github.com/frewsxcv/20b6522d8242ede00bb3>`__. General information about MultiLineString can be found in `Section 3.1.5`_ and `Appendix A: MultiLineStrings`_ within `The GeoJSON Format Specification`_.

.. _Section 3.1.5: https://tools.ietf.org/html/rfc7946#section-3.1.5
.. _Appendix A\: MultiLineStrings: https://tools.ietf.org/html/rfc7946#appendix-A.5

Polygon
~~~~~~~

.. code:: python

  >>> from geojson import Polygon

  >>> # no hole within polygon
  >>> Polygon([[(2.38, 57.322), (-120.43, 19.15), (23.194, -20.28), (2.38, 57.322)]])  # doctest: +ELLIPSIS
  {"coordinates": [[[2.3..., 57.32...], [-120.4..., 19.1...], [23.19..., -20.2...]]], "type": "Polygon"}

  >>> # hole within polygon
  >>> Polygon([
  ...     [(2.38, 57.322), (-120.43, 19.15), (23.194, -20.28), (2.38, 57.322)],
  ...     [(-5.21, 23.51), (15.21, -10.81), (-20.51, 1.51), (-5.21, 23.51)]
  ... ])  # doctest: +ELLIPSIS
  {"coordinates": [[[2.3..., 57.32...], [-120.4..., 19.1...], [23.19..., -20.2...]], [[-5.2..., 23.5...], [15.2..., -10.8...], [-20.5..., 1.5...], [-5.2..., 23.5...]]], "type": "Polygon"}

Visualize the results of the example above `here <https://gist.github.com/frewsxcv/b2f5c31c10e399a63679>`__. General information about Polygon can be found in `Section 3.1.6`_ and `Appendix A: Polygons`_ within `The GeoJSON Format Specification`_.

.. _Section 3.1.6: https://tools.ietf.org/html/rfc7946#section-3.1.6
.. _Appendix A\: Polygons: https://tools.ietf.org/html/rfc7946#appendix-A.3

MultiPolygon
~~~~~~~~~~~~

.. code:: python

  >>> from geojson import MultiPolygon

  >>> MultiPolygon([
  ...     ([(3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28)],),
  ...     ([(23.18, -34.29), (-1.31, -4.61), (3.41, 77.91), (23.18, -34.29)],)
  ... ])  # doctest: +ELLIPSIS
  {"coordinates": [[[[3.7..., 9.2...], [-130.9..., 1.5...], [35.1..., 72.23...]]], [[[23.1..., -34.2...], [-1.3..., -4.6...], [3.4..., 77.9...]]]], "type": "MultiPolygon"}

Visualize the result of the example above `here <https://gist.github.com/frewsxcv/e0388485e28392870b74>`__. General information about MultiPolygon can be found in `Section 3.1.7`_ and `Appendix A: MultiPolygons`_ within `The GeoJSON Format Specification`_.

.. _Section 3.1.7: https://tools.ietf.org/html/rfc7946#section-3.1.7
.. _Appendix A\: MultiPolygons: https://tools.ietf.org/html/rfc7946#appendix-A.6

GeometryCollection
~~~~~~~~~~~~~~~~~~

.. code:: python

  >>> from geojson import GeometryCollection, Point, LineString

  >>> my_point = Point((23.532, -63.12))

  >>> my_line = LineString([(-152.62, 51.21), (5.21, 10.69)])

  >>> geo_collection = GeometryCollection([my_point, my_line])

  >>> geo_collection  # doctest: +ELLIPSIS
  {"geometries": [{"coordinates": [23.53..., -63.1...], "type": "Point"}, {"coordinates": [[-152.6..., 51.2...], [5.2..., 10.6...]], "type": "LineString"}], "type": "GeometryCollection"}

  >>> geo_collection[1]
  {"coordinates": [[-152.62, 51.21], [5.21, 10.69]], "type": "LineString"}

  >>> geo_collection[0] == geo_collection.geometries[0]
  True

Visualize the result of the example above `here <https://gist.github.com/frewsxcv/6ec8422e97d338a101b0>`__. General information about GeometryCollection can be found in `Section 3.1.8`_ and `Appendix A: GeometryCollections`_ within `The GeoJSON Format Specification`_.

.. _Section 3.1.8: https://tools.ietf.org/html/rfc7946#section-3.1.8
.. _Appendix A\: GeometryCollections: https://tools.ietf.org/html/rfc7946#appendix-A.7

Feature
~~~~~~~

.. code:: python

  >>> from geojson import Feature, Point

  >>> my_point = Point((-3.68, 40.41))

  >>> Feature(geometry=my_point)  # doctest: +ELLIPSIS
  {"geometry": {"coordinates": [-3.68..., 40.4...], "type": "Point"}, "properties": {}, "type": "Feature"}

  >>> Feature(geometry=my_point, properties={"country": "Spain"})  # doctest: +ELLIPSIS
  {"geometry": {"coordinates": [-3.68..., 40.4...], "type": "Point"}, "properties": {"country": "Spain"}, "type": "Feature"}

  >>> Feature(geometry=my_point, id=27)  # doctest: +ELLIPSIS
  {"geometry": {"coordinates": [-3.68..., 40.4...], "type": "Point"}, "id": 27, "properties": {}, "type": "Feature"}

Visualize the results of the examples above `here <https://gist.github.com/frewsxcv/4488d30209d22685c075>`__. General information about Feature can be found in `Section 3.2`_ within `The GeoJSON Format Specification`_.

.. _Section 3.2: https://tools.ietf.org/html/rfc7946#section-3.2

FeatureCollection
~~~~~~~~~~~~~~~~~

.. code:: python

  >>> from geojson import Feature, Point, FeatureCollection

  >>> my_feature = Feature(geometry=Point((1.6432, -19.123)))

  >>> my_other_feature = Feature(geometry=Point((-80.234, -22.532)))

  >>> feature_collection = FeatureCollection([my_feature, my_other_feature])

  >>> feature_collection # doctest: +ELLIPSIS
  {"features": [{"geometry": {"coordinates": [1.643..., -19.12...], "type": "Point"}, "properties": {}, "type": "Feature"}, {"geometry": {"coordinates": [-80.23..., -22.53...], "type": "Point"}, "properties": {}, "type": "Feature"}], "type": "FeatureCollection"}

  >>> feature_collection.errors()
  []

  >>> (feature_collection[0] == feature_collection['features'][0], feature_collection[1] == my_other_feature)
  (True, True)

Visualize the result of the example above `here <https://gist.github.com/frewsxcv/34513be6fb492771ef7b>`__. General information about FeatureCollection can be found in `Section 3.3`_ within `The GeoJSON Format Specification`_.

.. _Section 3.3: https://tools.ietf.org/html/rfc7946#section-3.3

GeoJSON encoding/decoding
-------------------------

All of the GeoJSON Objects implemented in this library can be encoded and decoded into raw GeoJSON with the ``geojson.dump``, ``geojson.dumps``, ``geojson.load``, and ``geojson.loads`` functions. Note that each of these functions is a wrapper around the core `json` function with the same name, and will pass through any additional arguments. This allows you to control the JSON formatting or parsing behavior with the underlying core `json` functions.

.. code:: python

  >>> import geojson

  >>> my_point = geojson.Point((43.24, -1.532))

  >>> my_point  # doctest: +ELLIPSIS
  {"coordinates": [43.2..., -1.53...], "type": "Point"}

  >>> dump = geojson.dumps(my_point, sort_keys=True)

  >>> dump  # doctest: +ELLIPSIS
  '{"coordinates": [43.2..., -1.53...], "type": "Point"}'

  >>> geojson.loads(dump)  # doctest: +ELLIPSIS
  {"coordinates": [43.2..., -1.53...], "type": "Point"}

Custom classes
~~~~~~~~~~~~~~

This encoding/decoding functionality shown in the previous can be extended to custom classes using the interface described by the `__geo_interface__ Specification`_.

.. code:: python

  >>> import geojson

  >>> class MyPoint():
  ...     def __init__(self, x, y):
  ...         self.x = x
  ...         self.y = y
  ...
  ...     @property
  ...     def __geo_interface__(self):
  ...         return {'type': 'Point', 'coordinates': (self.x, self.y)}

  >>> point_instance = MyPoint(52.235, -19.234)

  >>> geojson.dumps(point_instance, sort_keys=True)  # doctest: +ELLIPSIS
  '{"coordinates": [52.23..., -19.23...], "type": "Point"}'

Default and custom precision
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

GeoJSON Object-based classes in this package have an additional `precision` attribute which rounds off
coordinates to 6 decimal places (roughly 0.1 meters) by default and can be customized per object instance.

.. code:: python

  >>> from geojson import Point

  >>> Point((-115.123412341234, 37.123412341234))  # rounded to 6 decimal places by default
  {"coordinates": [-115.123412, 37.123412], "type": "Point"}

  >>> Point((-115.12341234, 37.12341234), precision=8)  # rounded to 8 decimal places
  {"coordinates": [-115.12341234, 37.12341234], "type": "Point"}


Precision can be set at the package level by setting `geojson.geometry.DEFAULT_PRECISION`


.. code:: python

  >>> import geojson

  >>> geojson.geometry.DEFAULT_PRECISION = 5

  >>> from geojson import Point

  >>> Point((-115.12341234, 37.12341234))  # rounded to 8 decimal places
  {"coordinates": [-115.12341, 37.12341], "type": "Point"}


After setting the DEFAULT_PRECISION, coordinates will be rounded off to that precision with `geojson.load` or `geojson.loads`. Following one of those with `geojson.dump` is a quick and easy way to scale down the precision of excessively precise, arbitrarily-sized GeoJSON data.


Helpful utilities
-----------------

coords
~~~~~~

:code:`geojson.utils.coords` yields all coordinate tuples from a geometry or feature object.

.. code:: python

  >>> import geojson

  >>> my_line = LineString([(-152.62, 51.21), (5.21, 10.69)])

  >>> my_feature = geojson.Feature(geometry=my_line)

  >>> list(geojson.utils.coords(my_feature))  # doctest: +ELLIPSIS
  [(-152.62..., 51.21...), (5.21..., 10.69...)]

map_coords
~~~~~~~~~~

:code:`geojson.utils.map_coords` maps a function over all coordinate values and returns a geometry of the same type. Useful for scaling a geometry.

.. code:: python

  >>> import geojson

  >>> new_point = geojson.utils.map_coords(lambda x: x/2, geojson.Point((-115.81, 37.24)))

  >>> geojson.dumps(new_point, sort_keys=True)  # doctest: +ELLIPSIS
  '{"coordinates": [-57.905..., 18.62...], "type": "Point"}'

map_tuples
~~~~~~~~~~

:code:`geojson.utils.map_tuples` maps a function over all coordinates and returns a geometry of the same type. Useful for changing coordinate order or applying coordinate transforms.

.. code:: python

  >>> import geojson

  >>> new_point = geojson.utils.map_tuples(lambda c: (c[1], c[0]), geojson.Point((-115.81, 37.24)))

  >>> geojson.dumps(new_point, sort_keys=True)  # doctest: +ELLIPSIS
  '{"coordinates": [37.24..., -115.81], "type": "Point"}'

map_geometries
~~~~~~~~~~~~~~

:code:`geojson.utils.map_geometries` maps a function over each geometry in the input.

.. code:: python

  >>> import geojson

  >>> new_point = geojson.utils.map_geometries(lambda g: geojson.MultiPoint([g["coordinates"]]), geojson.GeometryCollection([geojson.Point((-115.81, 37.24))]))

  >>> geojson.dumps(new_point, sort_keys=True)
  '{"geometries": [{"coordinates": [[-115.81, 37.24]], "type": "MultiPoint"}], "type": "GeometryCollection"}'

validation
~~~~~~~~~~

:code:`is_valid` property provides simple validation of GeoJSON objects.

.. code:: python

  >>> import geojson

  >>> obj = geojson.Point((-3.68,40.41,25.14,10.34))
  >>> obj.is_valid
  False

:code:`errors` method provides collection of errors when validation GeoJSON objects.

.. code:: python

  >>> import geojson

  >>> obj = geojson.Point((-3.68,40.41,25.14,10.34))
  >>> obj.errors()
  'a position must have exactly 2 or 3 values'

generate_random
~~~~~~~~~~~~~~~

:code:`geojson.utils.generate_random` yields a geometry type with random data

.. code:: python

  >>> import geojson

  >>> geojson.utils.generate_random("LineString")  # doctest: +ELLIPSIS
  {"coordinates": [...], "type": "LineString"}

  >>> geojson.utils.generate_random("Polygon")  # doctest: +ELLIPSIS
  {"coordinates": [...], "type": "Polygon"}


Development
-----------

To build this project, run :code:`python setup.py build`.
To run the unit tests, run :code:`python -m pip install tox && tox`.
To run the style checks, run :code:`flake8` (install `flake8` if needed).

Credits
-------

* Sean Gillies <sgillies@frii.com>
* Matthew Russell <matt@sanoodi.com>
* Corey Farwell <coreyf@rwell.org>
* Blake Grotewold <hello@grotewold.me>
* Zsolt Ero <zsolt.ero@gmail.com>
* Sergey Romanov <xxsmotur@gmail.com>
* Ray Riga <ray@strongoutput.com>


.. _GeoJSON: https://geojson.org/
.. _The GeoJSON Format Specification: https://tools.ietf.org/html/rfc7946
.. _\_\_geo\_interface\_\_ Specification: https://gist.github.com/sgillies/2217756

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jazzband/geojson",
    "name": "geojson",
    "maintainer": "Ray Riga",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "ray@strongoutput.com",
    "keywords": "gis geography json",
    "author": "Sean Gillies",
    "author_email": "sgillies@frii.com",
    "download_url": "https://files.pythonhosted.org/packages/0f/34/0ea653dec93d3a360856e629a897a1d3ab534f2952852bb59d55853055ed/geojson-3.1.0.tar.gz",
    "platform": null,
    "description": "geojson\n==============\n\n.. image:: https://github.com/jazzband/geojson/actions/workflows/test.yml/badge.svg\n   :target: https://github.com/jazzband/geojson/actions/workflows/test.yml\n   :alt: GitHub Actions\n.. image:: https://img.shields.io/codecov/c/github/jazzband/geojson.svg\n   :target: https://codecov.io/github/jazzband/geojson?branch=main\n   :alt: Codecov\n.. image:: https://jazzband.co/static/img/badge.svg\n   :target: https://jazzband.co/\n   :alt: Jazzband\n\nThis Python library contains:\n\n- Functions for encoding and decoding GeoJSON_ formatted data\n- Classes for all GeoJSON Objects\n- An implementation of the Python `__geo_interface__ Specification`_\n\n**Table of Contents**\n\n.. contents::\n   :backlinks: none\n   :local:\n\nInstallation\n------------\n\ngeojson is compatible with Python 3.7 - 3.12. The recommended way to install is via pip_:\n\n.. code::\n\n  pip install geojson\n\n.. _PyPi as 'geojson': https://pypi.python.org/pypi/geojson/\n.. _pip: https://www.pip-installer.org\n\nGeoJSON Objects\n---------------\n\nThis library implements all the `GeoJSON Objects`_ described in `The GeoJSON Format Specification`_.\n\n.. _GeoJSON Objects: https://tools.ietf.org/html/rfc7946#section-3\n\nAll object keys can also be used as attributes.\n\nThe objects contained in GeometryCollection and FeatureCollection can be indexed directly.\n\nPoint\n~~~~~\n\n.. code:: python\n\n  >>> from geojson import Point\n\n  >>> Point((-115.81, 37.24))  # doctest: +ELLIPSIS\n  {\"coordinates\": [-115.8..., 37.2...], \"type\": \"Point\"}\n\nVisualize the result of the example above `here <https://gist.github.com/frewsxcv/b5768a857f5598e405fa>`__. General information about Point can be found in `Section 3.1.2`_ and `Appendix A: Points`_ within `The GeoJSON Format Specification`_.\n\n.. _Section 3.1.2: https://tools.ietf.org/html/rfc7946#section-3.1.2\n.. _Appendix A\\: Points: https://tools.ietf.org/html/rfc7946#appendix-A.1\n\nMultiPoint\n~~~~~~~~~~\n\n.. code:: python\n\n  >>> from geojson import MultiPoint\n\n  >>> MultiPoint([(-155.52, 19.61), (-156.22, 20.74), (-157.97, 21.46)])  # doctest: +ELLIPSIS\n  {\"coordinates\": [[-155.5..., 19.6...], [-156.2..., 20.7...], [-157.9..., 21.4...]], \"type\": \"MultiPoint\"}\n\nVisualize the result of the example above `here <https://gist.github.com/frewsxcv/be02025c1eb3aa2040ee>`__. General information about MultiPoint can be found in `Section 3.1.3`_ and `Appendix A: MultiPoints`_ within `The GeoJSON Format Specification`_.\n\n.. _Section 3.1.3: https://tools.ietf.org/html/rfc7946#section-3.1.3\n.. _Appendix A\\: MultiPoints: https://tools.ietf.org/html/rfc7946#appendix-A.4\n\n\nLineString\n~~~~~~~~~~\n\n.. code:: python\n\n  >>> from geojson import LineString\n\n  >>> LineString([(8.919, 44.4074), (8.923, 44.4075)])  # doctest: +ELLIPSIS\n  {\"coordinates\": [[8.91..., 44.407...], [8.92..., 44.407...]], \"type\": \"LineString\"}\n\nVisualize the result of the example above `here <https://gist.github.com/frewsxcv/758563182ca49ce8e8bb>`__. General information about LineString can be found in `Section 3.1.4`_ and `Appendix A: LineStrings`_ within `The GeoJSON Format Specification`_.\n\n.. _Section 3.1.4: https://tools.ietf.org/html/rfc7946#section-3.1.4\n.. _Appendix A\\: LineStrings: https://tools.ietf.org/html/rfc7946#appendix-A.2\n\nMultiLineString\n~~~~~~~~~~~~~~~\n\n.. code:: python\n\n  >>> from geojson import MultiLineString\n\n  >>> MultiLineString([\n  ...     [(3.75, 9.25), (-130.95, 1.52)],\n  ...     [(23.15, -34.25), (-1.35, -4.65), (3.45, 77.95)]\n  ... ])  # doctest: +ELLIPSIS\n  {\"coordinates\": [[[3.7..., 9.2...], [-130.9..., 1.52...]], [[23.1..., -34.2...], [-1.3..., -4.6...], [3.4..., 77.9...]]], \"type\": \"MultiLineString\"}\n\nVisualize the result of the example above `here <https://gist.github.com/frewsxcv/20b6522d8242ede00bb3>`__. General information about MultiLineString can be found in `Section 3.1.5`_ and `Appendix A: MultiLineStrings`_ within `The GeoJSON Format Specification`_.\n\n.. _Section 3.1.5: https://tools.ietf.org/html/rfc7946#section-3.1.5\n.. _Appendix A\\: MultiLineStrings: https://tools.ietf.org/html/rfc7946#appendix-A.5\n\nPolygon\n~~~~~~~\n\n.. code:: python\n\n  >>> from geojson import Polygon\n\n  >>> # no hole within polygon\n  >>> Polygon([[(2.38, 57.322), (-120.43, 19.15), (23.194, -20.28), (2.38, 57.322)]])  # doctest: +ELLIPSIS\n  {\"coordinates\": [[[2.3..., 57.32...], [-120.4..., 19.1...], [23.19..., -20.2...]]], \"type\": \"Polygon\"}\n\n  >>> # hole within polygon\n  >>> Polygon([\n  ...     [(2.38, 57.322), (-120.43, 19.15), (23.194, -20.28), (2.38, 57.322)],\n  ...     [(-5.21, 23.51), (15.21, -10.81), (-20.51, 1.51), (-5.21, 23.51)]\n  ... ])  # doctest: +ELLIPSIS\n  {\"coordinates\": [[[2.3..., 57.32...], [-120.4..., 19.1...], [23.19..., -20.2...]], [[-5.2..., 23.5...], [15.2..., -10.8...], [-20.5..., 1.5...], [-5.2..., 23.5...]]], \"type\": \"Polygon\"}\n\nVisualize the results of the example above `here <https://gist.github.com/frewsxcv/b2f5c31c10e399a63679>`__. General information about Polygon can be found in `Section 3.1.6`_ and `Appendix A: Polygons`_ within `The GeoJSON Format Specification`_.\n\n.. _Section 3.1.6: https://tools.ietf.org/html/rfc7946#section-3.1.6\n.. _Appendix A\\: Polygons: https://tools.ietf.org/html/rfc7946#appendix-A.3\n\nMultiPolygon\n~~~~~~~~~~~~\n\n.. code:: python\n\n  >>> from geojson import MultiPolygon\n\n  >>> MultiPolygon([\n  ...     ([(3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28)],),\n  ...     ([(23.18, -34.29), (-1.31, -4.61), (3.41, 77.91), (23.18, -34.29)],)\n  ... ])  # doctest: +ELLIPSIS\n  {\"coordinates\": [[[[3.7..., 9.2...], [-130.9..., 1.5...], [35.1..., 72.23...]]], [[[23.1..., -34.2...], [-1.3..., -4.6...], [3.4..., 77.9...]]]], \"type\": \"MultiPolygon\"}\n\nVisualize the result of the example above `here <https://gist.github.com/frewsxcv/e0388485e28392870b74>`__. General information about MultiPolygon can be found in `Section 3.1.7`_ and `Appendix A: MultiPolygons`_ within `The GeoJSON Format Specification`_.\n\n.. _Section 3.1.7: https://tools.ietf.org/html/rfc7946#section-3.1.7\n.. _Appendix A\\: MultiPolygons: https://tools.ietf.org/html/rfc7946#appendix-A.6\n\nGeometryCollection\n~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n  >>> from geojson import GeometryCollection, Point, LineString\n\n  >>> my_point = Point((23.532, -63.12))\n\n  >>> my_line = LineString([(-152.62, 51.21), (5.21, 10.69)])\n\n  >>> geo_collection = GeometryCollection([my_point, my_line])\n\n  >>> geo_collection  # doctest: +ELLIPSIS\n  {\"geometries\": [{\"coordinates\": [23.53..., -63.1...], \"type\": \"Point\"}, {\"coordinates\": [[-152.6..., 51.2...], [5.2..., 10.6...]], \"type\": \"LineString\"}], \"type\": \"GeometryCollection\"}\n\n  >>> geo_collection[1]\n  {\"coordinates\": [[-152.62, 51.21], [5.21, 10.69]], \"type\": \"LineString\"}\n\n  >>> geo_collection[0] == geo_collection.geometries[0]\n  True\n\nVisualize the result of the example above `here <https://gist.github.com/frewsxcv/6ec8422e97d338a101b0>`__. General information about GeometryCollection can be found in `Section 3.1.8`_ and `Appendix A: GeometryCollections`_ within `The GeoJSON Format Specification`_.\n\n.. _Section 3.1.8: https://tools.ietf.org/html/rfc7946#section-3.1.8\n.. _Appendix A\\: GeometryCollections: https://tools.ietf.org/html/rfc7946#appendix-A.7\n\nFeature\n~~~~~~~\n\n.. code:: python\n\n  >>> from geojson import Feature, Point\n\n  >>> my_point = Point((-3.68, 40.41))\n\n  >>> Feature(geometry=my_point)  # doctest: +ELLIPSIS\n  {\"geometry\": {\"coordinates\": [-3.68..., 40.4...], \"type\": \"Point\"}, \"properties\": {}, \"type\": \"Feature\"}\n\n  >>> Feature(geometry=my_point, properties={\"country\": \"Spain\"})  # doctest: +ELLIPSIS\n  {\"geometry\": {\"coordinates\": [-3.68..., 40.4...], \"type\": \"Point\"}, \"properties\": {\"country\": \"Spain\"}, \"type\": \"Feature\"}\n\n  >>> Feature(geometry=my_point, id=27)  # doctest: +ELLIPSIS\n  {\"geometry\": {\"coordinates\": [-3.68..., 40.4...], \"type\": \"Point\"}, \"id\": 27, \"properties\": {}, \"type\": \"Feature\"}\n\nVisualize the results of the examples above `here <https://gist.github.com/frewsxcv/4488d30209d22685c075>`__. General information about Feature can be found in `Section 3.2`_ within `The GeoJSON Format Specification`_.\n\n.. _Section 3.2: https://tools.ietf.org/html/rfc7946#section-3.2\n\nFeatureCollection\n~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n  >>> from geojson import Feature, Point, FeatureCollection\n\n  >>> my_feature = Feature(geometry=Point((1.6432, -19.123)))\n\n  >>> my_other_feature = Feature(geometry=Point((-80.234, -22.532)))\n\n  >>> feature_collection = FeatureCollection([my_feature, my_other_feature])\n\n  >>> feature_collection # doctest: +ELLIPSIS\n  {\"features\": [{\"geometry\": {\"coordinates\": [1.643..., -19.12...], \"type\": \"Point\"}, \"properties\": {}, \"type\": \"Feature\"}, {\"geometry\": {\"coordinates\": [-80.23..., -22.53...], \"type\": \"Point\"}, \"properties\": {}, \"type\": \"Feature\"}], \"type\": \"FeatureCollection\"}\n\n  >>> feature_collection.errors()\n  []\n\n  >>> (feature_collection[0] == feature_collection['features'][0], feature_collection[1] == my_other_feature)\n  (True, True)\n\nVisualize the result of the example above `here <https://gist.github.com/frewsxcv/34513be6fb492771ef7b>`__. General information about FeatureCollection can be found in `Section 3.3`_ within `The GeoJSON Format Specification`_.\n\n.. _Section 3.3: https://tools.ietf.org/html/rfc7946#section-3.3\n\nGeoJSON encoding/decoding\n-------------------------\n\nAll of the GeoJSON Objects implemented in this library can be encoded and decoded into raw GeoJSON with the ``geojson.dump``, ``geojson.dumps``, ``geojson.load``, and ``geojson.loads`` functions. Note that each of these functions is a wrapper around the core `json` function with the same name, and will pass through any additional arguments. This allows you to control the JSON formatting or parsing behavior with the underlying core `json` functions.\n\n.. code:: python\n\n  >>> import geojson\n\n  >>> my_point = geojson.Point((43.24, -1.532))\n\n  >>> my_point  # doctest: +ELLIPSIS\n  {\"coordinates\": [43.2..., -1.53...], \"type\": \"Point\"}\n\n  >>> dump = geojson.dumps(my_point, sort_keys=True)\n\n  >>> dump  # doctest: +ELLIPSIS\n  '{\"coordinates\": [43.2..., -1.53...], \"type\": \"Point\"}'\n\n  >>> geojson.loads(dump)  # doctest: +ELLIPSIS\n  {\"coordinates\": [43.2..., -1.53...], \"type\": \"Point\"}\n\nCustom classes\n~~~~~~~~~~~~~~\n\nThis encoding/decoding functionality shown in the previous can be extended to custom classes using the interface described by the `__geo_interface__ Specification`_.\n\n.. code:: python\n\n  >>> import geojson\n\n  >>> class MyPoint():\n  ...     def __init__(self, x, y):\n  ...         self.x = x\n  ...         self.y = y\n  ...\n  ...     @property\n  ...     def __geo_interface__(self):\n  ...         return {'type': 'Point', 'coordinates': (self.x, self.y)}\n\n  >>> point_instance = MyPoint(52.235, -19.234)\n\n  >>> geojson.dumps(point_instance, sort_keys=True)  # doctest: +ELLIPSIS\n  '{\"coordinates\": [52.23..., -19.23...], \"type\": \"Point\"}'\n\nDefault and custom precision\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nGeoJSON Object-based classes in this package have an additional `precision` attribute which rounds off\ncoordinates to 6 decimal places (roughly 0.1 meters) by default and can be customized per object instance.\n\n.. code:: python\n\n  >>> from geojson import Point\n\n  >>> Point((-115.123412341234, 37.123412341234))  # rounded to 6 decimal places by default\n  {\"coordinates\": [-115.123412, 37.123412], \"type\": \"Point\"}\n\n  >>> Point((-115.12341234, 37.12341234), precision=8)  # rounded to 8 decimal places\n  {\"coordinates\": [-115.12341234, 37.12341234], \"type\": \"Point\"}\n\n\nPrecision can be set at the package level by setting `geojson.geometry.DEFAULT_PRECISION`\n\n\n.. code:: python\n\n  >>> import geojson\n\n  >>> geojson.geometry.DEFAULT_PRECISION = 5\n\n  >>> from geojson import Point\n\n  >>> Point((-115.12341234, 37.12341234))  # rounded to 8 decimal places\n  {\"coordinates\": [-115.12341, 37.12341], \"type\": \"Point\"}\n\n\nAfter setting the DEFAULT_PRECISION, coordinates will be rounded off to that precision with `geojson.load` or `geojson.loads`. Following one of those with `geojson.dump` is a quick and easy way to scale down the precision of excessively precise, arbitrarily-sized GeoJSON data.\n\n\nHelpful utilities\n-----------------\n\ncoords\n~~~~~~\n\n:code:`geojson.utils.coords` yields all coordinate tuples from a geometry or feature object.\n\n.. code:: python\n\n  >>> import geojson\n\n  >>> my_line = LineString([(-152.62, 51.21), (5.21, 10.69)])\n\n  >>> my_feature = geojson.Feature(geometry=my_line)\n\n  >>> list(geojson.utils.coords(my_feature))  # doctest: +ELLIPSIS\n  [(-152.62..., 51.21...), (5.21..., 10.69...)]\n\nmap_coords\n~~~~~~~~~~\n\n:code:`geojson.utils.map_coords` maps a function over all coordinate values and returns a geometry of the same type. Useful for scaling a geometry.\n\n.. code:: python\n\n  >>> import geojson\n\n  >>> new_point = geojson.utils.map_coords(lambda x: x/2, geojson.Point((-115.81, 37.24)))\n\n  >>> geojson.dumps(new_point, sort_keys=True)  # doctest: +ELLIPSIS\n  '{\"coordinates\": [-57.905..., 18.62...], \"type\": \"Point\"}'\n\nmap_tuples\n~~~~~~~~~~\n\n:code:`geojson.utils.map_tuples` maps a function over all coordinates and returns a geometry of the same type. Useful for changing coordinate order or applying coordinate transforms.\n\n.. code:: python\n\n  >>> import geojson\n\n  >>> new_point = geojson.utils.map_tuples(lambda c: (c[1], c[0]), geojson.Point((-115.81, 37.24)))\n\n  >>> geojson.dumps(new_point, sort_keys=True)  # doctest: +ELLIPSIS\n  '{\"coordinates\": [37.24..., -115.81], \"type\": \"Point\"}'\n\nmap_geometries\n~~~~~~~~~~~~~~\n\n:code:`geojson.utils.map_geometries` maps a function over each geometry in the input.\n\n.. code:: python\n\n  >>> import geojson\n\n  >>> new_point = geojson.utils.map_geometries(lambda g: geojson.MultiPoint([g[\"coordinates\"]]), geojson.GeometryCollection([geojson.Point((-115.81, 37.24))]))\n\n  >>> geojson.dumps(new_point, sort_keys=True)\n  '{\"geometries\": [{\"coordinates\": [[-115.81, 37.24]], \"type\": \"MultiPoint\"}], \"type\": \"GeometryCollection\"}'\n\nvalidation\n~~~~~~~~~~\n\n:code:`is_valid` property provides simple validation of GeoJSON objects.\n\n.. code:: python\n\n  >>> import geojson\n\n  >>> obj = geojson.Point((-3.68,40.41,25.14,10.34))\n  >>> obj.is_valid\n  False\n\n:code:`errors` method provides collection of errors when validation GeoJSON objects.\n\n.. code:: python\n\n  >>> import geojson\n\n  >>> obj = geojson.Point((-3.68,40.41,25.14,10.34))\n  >>> obj.errors()\n  'a position must have exactly 2 or 3 values'\n\ngenerate_random\n~~~~~~~~~~~~~~~\n\n:code:`geojson.utils.generate_random` yields a geometry type with random data\n\n.. code:: python\n\n  >>> import geojson\n\n  >>> geojson.utils.generate_random(\"LineString\")  # doctest: +ELLIPSIS\n  {\"coordinates\": [...], \"type\": \"LineString\"}\n\n  >>> geojson.utils.generate_random(\"Polygon\")  # doctest: +ELLIPSIS\n  {\"coordinates\": [...], \"type\": \"Polygon\"}\n\n\nDevelopment\n-----------\n\nTo build this project, run :code:`python setup.py build`.\nTo run the unit tests, run :code:`python -m pip install tox && tox`.\nTo run the style checks, run :code:`flake8` (install `flake8` if needed).\n\nCredits\n-------\n\n* Sean Gillies <sgillies@frii.com>\n* Matthew Russell <matt@sanoodi.com>\n* Corey Farwell <coreyf@rwell.org>\n* Blake Grotewold <hello@grotewold.me>\n* Zsolt Ero <zsolt.ero@gmail.com>\n* Sergey Romanov <xxsmotur@gmail.com>\n* Ray Riga <ray@strongoutput.com>\n\n\n.. _GeoJSON: https://geojson.org/\n.. _The GeoJSON Format Specification: https://tools.ietf.org/html/rfc7946\n.. _\\_\\_geo\\_interface\\_\\_ Specification: https://gist.github.com/sgillies/2217756\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Python bindings and utilities for GeoJSON",
    "version": "3.1.0",
    "project_urls": {
        "Homepage": "https://github.com/jazzband/geojson"
    },
    "split_keywords": [
        "gis",
        "geography",
        "json"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e1b4f57660aa148d3e3043d048b7e1ab87dfeb85204d0fdb5b4e19c08202162",
                "md5": "71200800656cdaf6f483af47ee529d67",
                "sha256": "68a9771827237adb8c0c71f8527509c8f5bef61733aa434cefc9c9d4f0ebe8f3"
            },
            "downloads": -1,
            "filename": "geojson-3.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "71200800656cdaf6f483af47ee529d67",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 15044,
            "upload_time": "2023-11-05T21:15:41",
            "upload_time_iso_8601": "2023-11-05T21:15:41.659056Z",
            "url": "https://files.pythonhosted.org/packages/8e/1b/4f57660aa148d3e3043d048b7e1ab87dfeb85204d0fdb5b4e19c08202162/geojson-3.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0f340ea653dec93d3a360856e629a897a1d3ab534f2952852bb59d55853055ed",
                "md5": "490b514b939cbc0359129eedcad9bb57",
                "sha256": "58a7fa40727ea058efc28b0e9ff0099eadf6d0965e04690830208d3ef571adac"
            },
            "downloads": -1,
            "filename": "geojson-3.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "490b514b939cbc0359129eedcad9bb57",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 24492,
            "upload_time": "2023-11-05T21:06:50",
            "upload_time_iso_8601": "2023-11-05T21:06:50.615444Z",
            "url": "https://files.pythonhosted.org/packages/0f/34/0ea653dec93d3a360856e629a897a1d3ab534f2952852bb59d55853055ed/geojson-3.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-05 21:06:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jazzband",
    "github_project": "geojson",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "geojson"
}
        
Elapsed time: 0.18635s