| 7 | |
| 8 | |
| 9 | class Point(GEOSGeometry): |
| 10 | _minlength = 2 |
| 11 | _maxlength = 3 |
| 12 | has_cs = True |
| 13 | |
| 14 | def __init__(self, x=None, y=None, z=None, srid=None): |
| 15 | """ |
| 16 | The Point object may be initialized with either a tuple, or individual |
| 17 | parameters. |
| 18 | |
| 19 | For example: |
| 20 | >>> p = Point((5, 23)) # 2D point, passed in as a tuple |
| 21 | >>> p = Point(5, 23, 8) # 3D point, passed as individual parameters |
| 22 | """ |
| 23 | if x is None: |
| 24 | coords = [] |
| 25 | elif isinstance(x, (tuple, list)): |
| 26 | # Here a tuple or list was passed in under the `x` parameter. |
| 27 | coords = x |
| 28 | elif isinstance(x, (float, int)) and isinstance(y, (float, int)): |
| 29 | # Here X, Y, and (optionally) Z were passed in individually, as |
| 30 | # parameters. |
| 31 | if isinstance(z, (float, int)): |
| 32 | coords = [x, y, z] |
| 33 | else: |
| 34 | coords = [x, y] |
| 35 | else: |
| 36 | raise TypeError("Invalid parameters given for Point initialization.") |
| 37 | |
| 38 | point = self._create_point(len(coords), coords) |
| 39 | |
| 40 | # Initializing using the address returned from the GEOS |
| 41 | # createPoint factory. |
| 42 | super().__init__(point, srid=srid) |
| 43 | |
| 44 | def _to_pickle_wkb(self): |
| 45 | return None if self.empty else super()._to_pickle_wkb() |
| 46 | |
| 47 | def _from_pickle_wkb(self, wkb): |
| 48 | return self._create_empty() if wkb is None else super()._from_pickle_wkb(wkb) |
| 49 | |
| 50 | def _ogr_ptr(self): |
| 51 | return ( |
| 52 | gdal.geometries.Point._create_empty() if self.empty else super()._ogr_ptr() |
| 53 | ) |
| 54 | |
| 55 | @classmethod |
| 56 | def _create_empty(cls): |
| 57 | return cls._create_point(None, None) |
| 58 | |
| 59 | @classmethod |
| 60 | def _create_point(cls, ndim, coords): |
| 61 | """ |
| 62 | Create a coordinate sequence, set X, Y, [Z], and create point |
| 63 | """ |
| 64 | if not ndim: |
| 65 | return capi.create_point(None) |
| 66 |
no outgoing calls