Debian Codegraph @

geomet.egg-info/PKG-INFO

raw
1 Metadata-Version: 2.1
2 Name: geomet
3 Version: 1.1.0
4 Summary: Pure Python conversion library for common geospatial data formats
5 Maintainer-email: Lars Butler <[email protected]>
6 License: Apache-2.0
7 Project-URL: Repository, https://github.com/geomet/geomet
8 Keywords: esri,ewkb,ewkt,geojson,geopackage,geospatial,gis,spatial,wkb,wkt
9 Classifier: Development Status :: 5 - Production/Stable
10 Classifier: License :: OSI Approved :: Apache Software License
11 Classifier: Intended Audience :: Developers
12 Classifier: Intended Audience :: Education
13 Classifier: Intended Audience :: Science/Research
14 Classifier: Operating System :: OS Independent
15 Classifier: Programming Language :: Python :: 3.7
16 Classifier: Programming Language :: Python :: 3.8
17 Classifier: Programming Language :: Python :: 3.9
18 Classifier: Programming Language :: Python :: 3.10
19 Classifier: Programming Language :: Python :: 3.11
20 Classifier: Programming Language :: Python :: 3.12
21 Classifier: Topic :: Scientific/Engineering :: GIS
22 Requires-Python: >=3.7
23 Description-Content-Type: text/markdown
24 License-File: LICENSE
25 License-File: AUTHORS.txt
26
27 # GeoMet [![geomet](https://circleci.com/gh/geomet/geomet.svg?style=shield)](https://app.circleci.com/pipelines/github/geomet)
28
29 Pure-Python conversion library for common geospatial data formats.
30 Supported formats include:
31 - [GeoJSON](http://www.geojson.org/geojson-spec.html)
32 - [WKT/WKB](http://en.wikipedia.org/wiki/Well-known_text) (Well-Known Text/Binary)
33 - [Extended WKB/WKT](https://postgis.net/docs/using_postgis_dbmanagement.html#EWKB_EWKT)
34 - [GeoPackage Binary](http://www.geopackage.org/spec/#gpb_format)
35
36
37 ## Install
38
39 Install the latest version from [PyPI](https://pypi.org/project/geomet/):
40
41 $ pip install geomet
42
43 ## Functionality
44
45 Converion functions are exposed through idiomatic `load/loads/dump/dumps`
46 interfaces.
47
48 GeoMet is intended to cover all common use cases for dealing with 2D, 3D, and
49 4D geometries (including 'Z', 'M', and 'ZM').
50
51 | Geometry | WKT/EWKT | WKB/EWKB | GeoPackage Binary | EsriJSON |
52 | -------- | :------: | :------: | :---------------: | :------: |
53 | Point | ✅ | ✅ | ✅| ✅ |
54 | LineString | ✅ | ✅ | ✅| ✅ |
55 | Polygon | ✅ | ✅ | ✅| ✅ |
56 | MultiPoint | ✅ | ✅ | ✅| ✅ |
57 | MultiLineString | ✅ | ✅ | ✅| ✅ |
58 | MultiPolygon | ✅ | ✅ | ✅| ✅ |
59 | GeometryCollection | ✅ | ✅ | ✅| ✅ |
60
61 ## Example usage
62
63 Coverting a 'Point' GeoJSON object to WKT:
64
65 >>> from geomet import wkt
66 >>> point = {'type': 'Point', 'coordinates': [116.4, 45.2, 11.1]}
67 >>> wkt.dumps(point, decimals=4)
68 'POINT (116.4000 45.2000 11.1000)'
69
70 Converting a 'Point' GeoJSON object to WKB:
71
72 >>> from geomet import wkb
73 >>> wkb.dumps(point)
74 b'\x00\x00\x00\x10\x01@]\x19\x99\x99\x99\x99\x9a@F\x99\x99\x99\x99\x99\x9a@&333333'
75 >>> wkb.dumps(point, big_endian=False)
76 b'\x01\x01\x10\x00\x00\x9a\x99\x99\x99\x99\x19]@\x9a\x99\x99\x99\x99\x99F@333333&@'
77
78 Converting a 'Point' GeoJSON object to GeoPackage Binary:
79
80 >>> from geomet import geopackage
81 >>> geopackage.dumps(point)
82 b'GP\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\xe9@]\x19\x99\x99\x99\x99\x9a@F\x99\x99\x99\x99\x99\x9a@&333333'
83 >>> geopackage.dumps(point, big_endian=False)
84 b'GP\x00\x01\x00\x00\x00\x00\x01\xe9\x03\x00\x00\x9a\x99\x99\x99\x99\x19]@\x9a\x99\x99\x99\x99\x99F@333333&@'
85
86
87 Converting a 'LineString' GeoJSON object to WKT:
88
89 >>> linestring = {'type':'LineString',
90 ... 'coordinates': [[0.0, 0.0, 10.0], [2.0, 1.0, 20.0],
91 ... [4.0, 2.0, 30.0], [5.0, 4.0, 40.0]]}
92 >>> wkt.dumps(linestring, decimals=0)
93 'LINESTRING (0 0 10, 2 1 20, 4 2 30, 5 4 40)'
94
95 Converting a 'LineString' GeoJSON object to WKB:
96
97 >>> wkb.dumps(linestring)
98 b'\x00\x00\x00\x10\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@$\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00@4\x00\x00\x00\x00\x00\x00@\x10\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00@>\x00\x00\x00\x00\x00\x00@\x14\x00\x00\x00\x00\x00\x00@\x10\x00\x00\x00\x00\x00\x00@D\x00\x00\x00\x00\x00\x00'
99 >>> wkb.dumps(linestring, big_endian=False)
100 b'\x01\x02\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00$@\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x004@\x00\x00\x00\x00\x00\x00\x10@\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00>@\x00\x00\x00\x00\x00\x00\x14@\x00\x00\x00\x00\x00\x00\x10@\x00\x00\x00\x00\x00\x00D@'
101
102 Converting a 'LineString' GeoJSON object to GeoPackage Binary:
103
104 >>> geopackage.dumps(linestring)
105 b'GP\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@$\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00?\xf0\x00\x00\x00\x00\x00\x00@4\x00\x00\x00\x00\x00\x00@\x10\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00@>\x00\x00\x00\x00\x00\x00@\x14\x00\x00\x00\x00\x00\x00@\x10\x00\x00\x00\x00\x00\x00@D\x00\x00\x00\x00\x00\x00'
106 >>> geopackage.dumps(linestring, big_endian=False)
107 b'GP\x00\x01\x00\x00\x00\x00\x01\x02\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00$@\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x004@\x00\x00\x00\x00\x00\x00\x10@\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00>@\x00\x00\x00\x00\x00\x00\x14@\x00\x00\x00\x00\x00\x00\x10@\x00\x00\x00\x00\x00\x00D@'
108
109 Converting 'Point' WKT to GeoJSON:
110
111 >>> wkt.loads('POINT(10 20)')
112 {'type': 'Point', 'coordinates': [10.0, 20.0]}
113
114 Coverting 'GeometryCollection' WKT to GeoJSON:
115
116 >>> wkt.loads('GEOMETRYCOLLECTION(POINT(10 20),POLYGON(((0 0), (10 30), (30 10), (0 0)))')
117 {'type': 'GeometryCollection', 'geometries': [{'type': 'Point', 'coordinates': [10.0, 20.0]}, {'type': 'Polygon', 'coordinates': [[[0.0, 0.0]], [[10.0, 30.0]], [[30.0, 10.0]], [[0.0, 0.0]]]}]}
118
119 [EWKT/EWKB](http://postgis.net/documentation/manual-2.1/using_postgis_dbmanagement.html#EWKB_EWKT)
120 are also supported for all geometry types. This uses a custom extension
121 to the GeoJSON standard in order to preserve SRID information through conversions.
122 For example:
123
124 >>> wkt.loads('SRID=4326;POINT(10 20)')
125 {'type': 'Point', 'coordinates': [10.0, 20.0], 'meta': {'srid': '4326'}}
126 >>> wkt.dumps({'type': 'Point', 'coordinates': [10.0, 20.0], 'meta': {'srid': '4326'}, 'crs': {'properties': {'name': 'EPSG4326'}, 'type': 'name'}})
127 'SRID=4326;POINT (10.0000000000000000 20.0000000000000000)'
128 >>> wkb.loads('\x00 \x00\x00\x01\x00\x00\x10\xe6@$\x00\x00\x00\x00\x00\x00@4\x00\x00\x00\x00\x00\x00')
129 {'meta': {'srid': '4326'}, 'type': 'Point', 'coordinates': [10.0, 20.0]}
130 >>> wkb.dumps({'type': 'Point', 'coordinates': [10.0, 20.0], 'meta': {'srid': '4326'}, 'crs': {'properties': {'name': 'EPSG4326'}, 'type': 'name'}})
131 '\x00 \x00\x00\x01\x00\x00\x10\xe6@$\x00\x00\x00\x00\x00\x00@4\x00\x00\x00\x00\x00\x00'
132
133 GeoPackage binary supports encoding of SRID and envelope information. If your geopackage
134 has an envelope specified, then it will be added into the resulting GeoJSON in a key
135 called `'bbox'`:
136
137 >>> gpkg = b'GP\x00\x03\x00\x00\x00\x00\xf0\x9e\xa0\xa7\x05;#@hZ\xbd\x93\x83GC@\xf0\x9e\xa0\xa7\x05;#@hZ\xbd\x93\x83GC@\x01\x01\x00\x00\x00\xf0\x9e\xa0\xa7\x05;#@hZ\xbd\x93\x83GC@'
138 >>> geopackage.loads(gpkg)
139 >>> {'type': 'Point', 'coordinates': [9.615277517659223, 38.55870291467437], 'bbox': (9.615277517659223, 38.55870291467437, 9.615277517659223, 38.55870291467437)}
140
141 In the same way, if a 'bbox' key is present on a `dumps`-ed geometry, it will be added to the
142 header of the GeoPackage geometry:
143
144 >>> polygon = {'type': 'Polygon', 'coordinates': [[[20.0, 20.0], [34.0, 124.0], [70.0, 140.0], [130.0, 130.0], [70.0, 100.0], [110.0, 70.0], [170.0, 20.0], [90.0, 10.0], [20.0, 20.0]]], 'bbox': (20.0, 170.0, 10.0, 140.0)}
145 >>> geopackage.dumps(polygon)
146 b'GP\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x004@\x00\x00\x00\x00\x00@e@\x00\x00\x00\x00\x00\x00$@\x00\x00\x00\x00\x00\x80a@\x00\x00\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\t@4\x00\x00\x00\x00\x00\x00@4\x00\x00\x00\x00\x00\x00@A\x00\x00\x00\x00\x00\x00@_\x00\x00\x00\x00\x00\x00@Q\x80\x00\x00\x00\x00\x00@a\x80\x00\x00\x00\x00\x00@`@\x00\x00\x00\x00\x00@`@\x00\x00\x00\x00\x00@Q\x80\x00\x00\x00\x00\x00@Y\x00\x00\x00\x00\x00\x00@[\x80\x00\x00\x00\x00\x00@Q\x80\x00\x00\x00\x00\x00@e@\x00\x00\x00\x00\x00@4\x00\x00\x00\x00\x00\x00@V\x80\x00\x00\x00\x00\x00@$\x00\x00\x00\x00\x00\x00@4\x00\x00\x00\x00\x00\x00@4\x00\x00\x00\x00\x00\x00'
147
148 If an integer SRID identifier is present in a `'meta'` key (like `'meta': {'srid': 4326}`), then the SRID will be included in the
149 GeoPackage header.
150
151 ## History
152
153 This library was originally created as the result of a bug report related
154 to another project: https://bugs.launchpad.net/openquake-old/+bug/1073909.
155 The source of this issue was largely due to a dependency on
156 [GEOS](https://libgeos.org/), which is written in C/C++. Depending on GEOS
157 requires any data conversion bug fixes to happen upstream, which takes time
158 and effort. Ultimately, this was the inspiration to create a more
159 lightweight, pure-Python conversion library as an alterntive tool for
160 reliably converting data between various geospatial formats.
161
162 The name "GeoMet" was inspired by "met", the German word for
163 [mead](http://en.wikipedia.org/wiki/Mead). It is also a shortened version of
164 the word "geometry".
165
166 ## Limitations
167
168 ### Outputing "empty" geometries to binary formats is not supported
169
170 Attempting to output an empty geometry to a binary format will result in an exception: `ValueError: Empty geometries cannot be represented in WKB. Reason: The dimensionality of the WKB would be ambiguous.` There are a few reasons for this this limitation:
171 - Any `EMTPY` geometry (e.g., `POINT EMPTY`, `MULTIPOLYGON EMPTY`, etc.) cannot be converted into binary format because binary formats such as WKB require an explicit dimension type (2d, Z, M, or ZM). This means that some objects cannot be reliably converted to and from different formats in a [bijective](https://en.wikipedia.org/wiki/Bijection) manner.
172 - The [GeoJSON standard](https://www.rfc-editor.org/rfc/rfc7946) does have a way of representing empty geometries; however, details are minimal and the dimensionality of such an object remains ambiguous.
173 - Representing some geometry types (such as points and lines) as "empty" is [deeply flawed to begin with](http://aleph0.clarku.edu/~djoyce/elements/bookI/defI1.html). For example, a point can represent any location in 2d, 3d, or 4d space. However, a point is infinitesimally small (it has no size) and it can't contain anything (it can't be "full"), therefore, it doesn't make sense for a point to be "empty".
174
175 As a result, GeoMet has chosen to not attempt to address these problems, and
176 simply raise an exception instead.
177
178 Example:
179
180 >>> import geomet
181 >>> import geomet.wkt as wkt
182 >>> import geomet.wkb as wkb
183 >>> pt = wkt.loads('POINT EMPTY')
184 >>> pt
185 {'type': 'Point', 'coordinates': []}
186 >>> wkb.dumps(pt)
187 Traceback (most recent call last):
188 File "<stdin>", line 1, in <module>
189 File "/home/jdoe/geomet/geomet/wkb.py", line 216, in dumps
190 return _dumps(obj, big_endian)
191 File "/home/jdoe/geomet/geomet/wkb.py", line 238, in _dumps
192 raise ValueError(
193 ValueError: Empty geometries cannot be represented in WKB. Reason: The dimensionality of the WKB would be ambiguous.
194
195
196 ## See also
197
198 - [wellknown](https://github.com/mapbox/wellknown): A similar package for Node.js.
199 - [geo](https://github.com/bryanjos/geo): A nearly-identical package for Elixir.