Skip to content

Commit 4ed2b01

Browse files
Merge pull request #42 from gregory-halverson/main
resampling method option for mosaic
2 parents 28fc24d + 502d719 commit 4ed2b01

3 files changed

Lines changed: 138 additions & 10 deletions

File tree

Bounding Box Transformation.ipynb

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "d7a281f3",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from rasters import BBox"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 2,
16+
"id": "5bde08f4",
17+
"metadata": {},
18+
"outputs": [
19+
{
20+
"data": {
21+
"text/plain": [
22+
"BBox(xmin=-118.753625032771, ymin=36.5914562284022, xmax=-118.331319677407, ymax=37.1398151261614, crs=\"EPSG:4326\")"
23+
]
24+
},
25+
"execution_count": 2,
26+
"metadata": {},
27+
"output_type": "execute_result"
28+
}
29+
],
30+
"source": [
31+
"bbox_latlon = BBox(xmin=-118.753625032771, ymin=36.5914562284022, xmax=-118.331319677407, ymax=37.1398151261614, crs=\"EPSG:4326\")\n",
32+
"bbox_latlon"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 3,
38+
"id": "63bb94d8",
39+
"metadata": {},
40+
"outputs": [
41+
{
42+
"data": {
43+
"text/plain": [
44+
"POINT (-118.54247235508899 36.8656356772818)"
45+
]
46+
},
47+
"execution_count": 3,
48+
"metadata": {},
49+
"output_type": "execute_result"
50+
}
51+
],
52+
"source": [
53+
"bbox_latlon.centroid"
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": 4,
59+
"id": "c025cf4b",
60+
"metadata": {},
61+
"outputs": [
62+
{
63+
"data": {
64+
"text/plain": [
65+
"'+proj=utm +zone=11 +ellps=WGS84 +datum=WGS84 +units=m +no_defs'"
66+
]
67+
},
68+
"execution_count": 4,
69+
"metadata": {},
70+
"output_type": "execute_result"
71+
}
72+
],
73+
"source": [
74+
"bbox_latlon.local_UTM_proj4"
75+
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": null,
80+
"id": "27e13506",
81+
"metadata": {},
82+
"outputs": [],
83+
"source": []
84+
}
85+
],
86+
"metadata": {
87+
"kernelspec": {
88+
"display_name": "rasters",
89+
"language": "python",
90+
"name": "python3"
91+
},
92+
"language_info": {
93+
"codemirror_mode": {
94+
"name": "ipython",
95+
"version": 3
96+
},
97+
"file_extension": ".py",
98+
"mimetype": "text/x-python",
99+
"name": "python",
100+
"nbconvert_exporter": "python",
101+
"pygments_lexer": "ipython3",
102+
"version": "3.11.12"
103+
}
104+
},
105+
"nbformat": 4,
106+
"nbformat_minor": 5
107+
}

rasters/bbox.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import List, Union
55

66
from .CRS import CRS, WGS84
7+
from .point import Point
78
from .polygon import Polygon
89
from .spatial_geometry import SpatialGeometry
910

@@ -212,6 +213,20 @@ def buffer(self, buffer) -> BBox:
212213
crs=self.crs
213214
)
214215

216+
@property
217+
def centroid(self) -> Point:
218+
"""
219+
Calculates the centroid of the BBox.
220+
221+
Returns:
222+
Point: The centroid of the BBox.
223+
"""
224+
return Point(
225+
x=(self.x_min + self.x_max) / 2,
226+
y=(self.y_min + self.y_max) / 2,
227+
crs=self.crs
228+
)
229+
215230
@property
216231
def bbox(self) -> BBox:
217232
"""

rasters/point.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
from rasters.wrap_geometry import wrap_geometry
1010
from .CRS import CRS, WGS84
11-
from .bbox import BBox
12-
from .polygon import Polygon
11+
# from .bbox import BBox
12+
# from .polygon import Polygon
1313
from .vector_geometry import VectorGeometry, SingleVectorGeometry
1414

1515

@@ -34,18 +34,21 @@ class Point(SingleVectorGeometry):
3434
>>> print(point.x, point.y, point.crs)
3535
10 20 WGS84
3636
"""
37-
def __init__(self, *args, crs: Union[CRS, str] = WGS84):
38-
if isinstance(args[0], Point):
37+
def __init__(self, *args, crs: Union[CRS, str] = WGS84, x: float = None, y: float = None):
38+
if len(args) > 0 and isinstance(args[0], Point):
3939
# If the first argument is a Point, extract geometry and crs
4040
geometry = args[0].geometry
4141
crs = args[0].crs
42+
elif x is not None and y is not None:
43+
# If x and y are provided as keyword arguments
44+
geometry = shapely.geometry.Point(x, y)
4245
else:
43-
# Otherwise, create a new shapely Point from the arguments
46+
# Otherwise, create a new shapely Point from the positional arguments
4447
geometry = shapely.geometry.Point(*args)
45-
48+
4649
# Initialize the base VectorGeometry class
4750
VectorGeometry.__init__(self, crs=crs)
48-
51+
4952
self.geometry = geometry
5053

5154
@property
@@ -101,7 +104,7 @@ def buffer(
101104
cap_style=CAP_STYLE.round,
102105
join_style=JOIN_STYLE.round,
103106
mitre_limit=5.0,
104-
single_sided=False) -> Polygon:
107+
single_sided=False) -> "Polygon":
105108
"""
106109
Creates a buffer polygon around the point.
107110
@@ -117,6 +120,8 @@ def buffer(
117120
Returns:
118121
Polygon: The buffer polygon.
119122
"""
123+
from .polygon import Polygon
124+
120125
# Create the buffer using shapely's buffer method
121126
buffer_geom = shapely.geometry.Point.buffer(
122127
self.geometry,
@@ -132,13 +137,14 @@ def buffer(
132137
return Polygon(buffer_geom, crs=self.crs)
133138

134139
@property
135-
def bbox(self) -> BBox:
140+
def bbox(self) -> "BBox":
136141
"""
137142
Returns the bounding box of the point.
138-
143+
139144
Returns:
140145
BBox: The bounding box of the point.
141146
"""
147+
from .bbox import BBox
142148
return BBox(self.x, self.y, self.x, self.y, crs=self.crs)
143149

144150
def distance(self, other: Point) -> float:

0 commit comments

Comments
 (0)