Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geometry, geography, box2d, and box3d PostGIS types. #518

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion edgedb/protocol/codecs/codecs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ from edgedb import enums
from edgedb.datatypes import datatypes

from libc.string cimport memcpy

from cpython.bytes cimport PyBytes_FromStringAndSize

include "./edb_types.pxi"

Expand Down Expand Up @@ -894,6 +894,27 @@ cdef bigint_decode(pgproto.CodecContext settings, FRBuffer *buf):
return int(result)


cdef geometry_encode(pgproto.CodecContext settings, WriteBuffer buf, obj):
buf.write_int32(len(obj.wkb))
buf.write_bytes(obj.wkb)


cdef geometry_decode(pgproto.CodecContext settings, FRBuffer *buf):
cdef:
object result
# Just wrap the bytes into a named tuple with a single field `wkb`
descriptor = datatypes.record_desc_new(
('wkb',), <object>NULL, <object>NULL)
result = datatypes.namedtuple_new(
datatypes.namedtuple_type_new(descriptor))

elem = PyBytes_FromStringAndSize(frb_read_all(buf), buf.len)
cpython.Py_INCREF(elem)
cpython.PyTuple_SET_ITEM(result, 0, elem)

return result


cdef register_base_scalar_codecs():
register_base_scalar_codec(
'std::uuid',
Expand Down Expand Up @@ -1007,5 +1028,33 @@ cdef register_base_scalar_codecs():
uuid.UUID('9565dd88-04f5-11ee-a691-0b6ebe179825'),
)

register_base_scalar_codec(
'ext::postgis::geometry',
geometry_encode,
geometry_decode,
uuid.UUID('44c901c0-d922-4894-83c8-061bd05e4840'),
)

register_base_scalar_codec(
'ext::postgis::geography',
geometry_encode,
geometry_decode,
uuid.UUID('4d738878-3a5f-4821-ab76-9d8e7d6b32c4'),
)

register_base_scalar_codec(
'ext::postgis::box2d',
geometry_encode,
geometry_decode,
uuid.UUID('7fae5536-6311-4f60-8eb9-096a5d972f48'),
)

register_base_scalar_codec(
'ext::postgis::box3d',
geometry_encode,
geometry_decode,
uuid.UUID('c1a50ff8-fded-48b0-85c2-4905a8481433'),
)


register_base_scalar_codecs()
Loading
Loading