File: base.pxi

package info (click to toggle)
python-pyproj 3.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,720 kB
  • sloc: python: 13,468; sh: 273; makefile: 90
file content (39 lines) | stat: -rw-r--r-- 1,005 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from cpython.ref cimport PyObject

from math import degrees, radians


cdef double _DG2RAD = radians(1.)
cdef double _RAD2DG = degrees(1.)
cdef int _DOUBLESIZE = sizeof(double)


cdef extern from "math.h" nogil:
    ctypedef enum:
        HUGE_VAL


cdef extern from "Python.h":
    ctypedef enum:
        PyBUF_WRITABLE
    int PyObject_GetBuffer(PyObject *exporter, Py_buffer *view, int flags)
    void PyBuffer_Release(Py_buffer *view)


cdef class PyBuffWriteManager:
    cdef Py_buffer buffer
    cdef double* data
    cdef public Py_ssize_t len

    def __cinit__(self):
        self.data = NULL

    def __init__(self, object data):
        if PyObject_GetBuffer(<PyObject *>data, &self.buffer, PyBUF_WRITABLE) <> 0:
            raise BufferError("pyproj had a problem getting the buffer from data.")
        self.data = <double *>self.buffer.buf
        self.len = self.buffer.len // self.buffer.itemsize

    def __dealloc__(self):
        PyBuffer_Release(&self.buffer)
        self.data = NULL