Skip to main content

A python library for preprocessing geospatial vector geometries for use in deep learning

Project description

deep-geometry

A python library for preprocessing geospatial vector geometries for use in deep learning

Rationale

Deep learning can use geospatial vector polygons directly (rather than a feature-extracted pre-processd version), but it requires vectorization and normalisation first, like any data source.

Installation

pip install deep-geometry

Usage

Geometry vectorization

Make a numerical vector from a geometry:

>>> from deep_geometry import vectorizer as gv

>>> geoms = [
...     'POINT(0 0)',
...     'POINT(1 1)',
...     'POINT(2 2)',
...     'POINT(3 3)',
...     'POINT(4 4)',
...     'POINT(5 5)',
...     'POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))',
... ]

>>> gv.vectorize_wkt(geoms[0])
array([[ 0.,  0.,  0.,  0.,  0.,  0.,  1.]])

>>> gv.vectorize_wkt(geoms[6])
array([[ 0.,  0.,  0., 1., 1.,  0.,  0.],
       [ 1.,  0.,  0., 1., 1.,  0.,  0.],
       [ 1.,  1.,  0., 1., 1.,  0.,  0.],
       [ 0.,  1.,  0., 1., 1.,  0.,  0.],
       [ 0.,  0.,  0., 1., 0.,  0.,  1.]])

Collect the max length from a set of geometries:

>>> max_len = gv.get_max_points(geoms)
>>> print('Maximum geometry node size in set:', max_len)
Maximum geometry node size in set: 7

Numerical data normalization

Geometries regularly are in some kind of earth projection that is far from the origin of the coordinate system. In order for machine learning models to learn, data needs to be normalized. A usual way to go about this is to mean-center the instances and to divide by the dataset standard deviation.

The library provides a convenience class for normalization, modeled after the scalers from scikit-learn with a .fit() and a .transform() method:

>>> from deep_geometry import GeomScaler
>>> import numpy
>>> gs = GeomScaler()  # simply initialize
>>> geom6 = gv.vectorize_wkt(geoms[6])
>>> dataset = numpy.repeat([geom6], 4, axis=0)
>>> gs.fit(dataset)
>>> gs.scale_factor
0.5
>>> normalized_data = gs.transform(dataset)
>>> normalized_data[0]  # see: zero-mean and scaled to standard deviation
array([[-1., -1.,  0.,  1.,  1.,  0.,  0.],
       [ 1., -1.,  0.,  1.,  1.,  0.,  0.],
       [ 1.,  1.,  0.,  1.,  1.,  0.,  0.],
       [-1.,  1.,  0.,  1.,  1.,  0.,  0.],
       [-1., -1.,  0.,  1.,  0.,  0.,  1.]])

Project details


Download files

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

Source Distribution

deep-geometry-2.0.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

deep_geometry-2.0.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file deep-geometry-2.0.0.tar.gz.

File metadata

  • Download URL: deep-geometry-2.0.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for deep-geometry-2.0.0.tar.gz
Algorithm Hash digest
SHA256 89f002cd985ff527519d02b715ee648d04329cf4c37046b3226d5ecf856b505a
MD5 a3c38e81c06929ba585acfb1b0cca5c2
BLAKE2b-256 1deba0f672e09354772bfb17ee45900efb64751b9d0f42632958123a119bf4d7

See more details on using hashes here.

File details

Details for the file deep_geometry-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: deep_geometry-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for deep_geometry-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d8552203fcc03850ef45127f8f04eed8d7d452a11d1f0293f8b43a7df9adbcf
MD5 24989b78479c0670097c18ea92f17910
BLAKE2b-256 e213c473bd468fe1aff821a1e7b9835e95efde53b3430f997a94e992be4181c3

See more details on using hashes here.

Supported by

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