Skip to main content

SpatialTypes functions for extend PyPika with GIS

Project description

PyPika GIS

This library contains SpatialTypes functions for extending PyPika with GIS.

ci_badge

Table of Contents

Install

pip install pypika-gis

Examples

PostGIS

from pypika import Query, Table
from pypika_gis.spatialtypes import postgis as st

table = Table('table')
query = Query.from_(table).select(table.id, st.AsGeoJSON(table.geom))
print(str(query))
# SELECT "id",ST_AsGeoJSON('geom') FROM "table"

query = Query.from_(table).select('id').where(
    st.Intersects(table.geom, st.SetSRID(st.MakePoint(10, 5), 4326)))
print(str(query))
# SELECT "id" FROM "table" WHERE ST_Intersects('geom',ST_SRID(ST_MakePoint(10,5),4326))

MSSQLSpatial

from pypika import Query, Table
from pypika_gis.spatialtypes import mssql as st

table = Table('table')
query = Query.from_(table).select(table.id, st.AsText(table.geom))
print(str(query))
# SELECT "id",geom.STAsText() FROM "table"

query = Query.from_(table).select(table.id).where(
    st.Intersects(table.geom, st.GeomFromText('POINT(10 10)', 4326)))
print(str(query))
# SELECT "id" FROM "table" WHERE geom.STIntersects(geometry::STGeomFromText('POINT(10 10)',4326))

Available functions

pypika-gis PostGIS MSSQLSpatial
Area ST_Area STArea
AsBinary ST_AsBinary STAsBinary
AsGeoJSON ST_AsGeoJSON
AsMVT ST_AsMVT
AsText ST_AsText STAsText
Boundary ST_Boundary STBoundary
Buffer ST_Buffer STBuffer
Centroid ST_Centroid STCentroid
ClosestPoint ST_ClosestPoint
Contains ST_Contains STContains
ConvexHull ST_ConvexHull STConvexHull
CoveredBy ST_CoveredBy
Covers ST_Covers
Crosses ST_Crosses STCrosses
CurveN STCurveN
CurveToLine ST_CurveToLine STCurveToLine
Difference ST_Difference STDifference
Dimension ST_Dimension STDimension
Disjoint ST_Disjoint STDisjoint
Distance ST_Distance STDistance
DWithin ST_DWithin
EndPoint ST_EndPoint STEndPoint
Envelope ST_Envelope STEnvelope
Equals ST_Equals STEquals
ExteriorRing ST_ExteriorRing STExteriorRing
Extent ST_Extent
GeoHash ST_GeoHash
GeometryN ST_GeometryN STGeometryN
GeometryType ST_GeometryType STGeometryType
GeogFromGeoJSON ST_GeogFromGeoJSON
GeogFromText ST_GeogFromText STGeomFromText
GeogFromWKB ST_GeogFromWKB STGeomFromWKB
GeogPoint ST_GeogPoint
GeogPointFromGeoHash ST_GeogPointFromGeoHash
GeomFromGeoJSON ST_GeomFromGeoJSON
InteriorRingN ST_InteriorRingN STInteriorRingN
Intersection ST_Intersection STIntersection
Intersects ST_Intersects STIntersects
IsCollection ST_IsCollection
IsClosed ST_IsClosed STIsClosed
IsEmpty ST_IsEmpty STIsEmpty
IsRing ST_IsRing STIsRing
IsSimple ST_IsSimple STIsSimple
IsValid ST_IsValid STIsValid
Length ST_Length STLength
MakeLine ST_MakeLine
MakePoint ST_MakePoint
MakePolygon ST_MakePolygon
NumCurves STNumCurves
NumGeometries STNumGeometries
NumInteriorRing STNumInteriorRing
NumPoints STNumPoints
Overlaps ST_Overlaps STOverlaps
Perimeter ST_Perimeter
Point ST_Point Point
PointN ST_PointN STPointN
PointOnSurface ST_PointOnSurface STPointOnSurface
Relate ST_Relate STRelate
SetSRID ST_SetSRID
SRID STSrid[^1]
StartPoint ST_StartPoint STStartPoint
SymDifference STSymDifference
Touches ST_Touches STTouches
Union ST_Union STUnion
Within ST_Within STWithin
X ST_X STX[^1]
Y ST_Y STY[^1]
Z ST_Z

[^1]: In MSSQL this is technically a method of the geography/geometry class, and returns a pypika Field instead of a Function.

Development

Dependencies

Setup

poetry install
poetry run pre-commit install

Tests

Full tests and coverage

poetry run pytest

Publish

poetry build
poetry publish

Credits

pypika-gis is based on PyPika. Check their page for further query buider instructions, examples and more details about PyPika core.

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

pypika-gis-2.0.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypika_gis-2.0.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file pypika-gis-2.0.0.tar.gz.

File metadata

  • Download URL: pypika-gis-2.0.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.10 Linux/5.11.0-37-generic

File hashes

Hashes for pypika-gis-2.0.0.tar.gz
Algorithm Hash digest
SHA256 ae1b26d383ee3c1546da03b7e4e31906d899db9a45d7af480b7eb87e036ca172
MD5 f4ec30f8e5708d2d6c1f660e8b354624
BLAKE2b-256 a22a72d406e621a65b2a4ce5bf9b10960705d1470cddf3a507dcdfe6959e8916

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pypika_gis-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.10 Linux/5.11.0-37-generic

File hashes

Hashes for pypika_gis-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36c2ae3f01bad76ecb0a21e45452b422a5f9972ccf40beb1bcc18db83d75c8a7
MD5 fa645f9dcd36410d48bf067a7d1bc70a
BLAKE2b-256 af627b2a0205a44b18740029949b83eae4b05ca76f186951272f3132d96f9dd5

See more details on using hashes here.

Supported by

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