Skip to content

Commit eb329db

Browse files
committed
minor updates
1 parent 07f5b19 commit eb329db

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

labelbox/data/annotation_types/geometry/line.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def geometry(self) -> geojson.MultiLineString:
3131
def from_shapely(cls, shapely_obj: SLineString) -> Line:
3232
"""Transforms a shapely object."""
3333
if not isinstance(shapely_obj, SLineString):
34-
raise ValueError(
34+
raise TypeError(
3535
f"Expected Shapely Line. Got {shapely_obj.geom_type}")
3636

3737
obj_coords = shapely_obj.__geo_interface__['coordinates']

labelbox/data/annotation_types/geometry/point.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def geometry(self) -> geojson.Point:
3030
def from_shapely(cls, shapely_obj: SPoint) -> Point:
3131
"""Transforms a shapely object."""
3232
if not isinstance(shapely_obj, SPoint):
33-
raise ValueError(
33+
raise TypeError(
3434
f"Expected Shapely Point. Got {shapely_obj.geom_type}")
3535

3636
obj_coords = shapely_obj.__geo_interface__['coordinates']

labelbox/data/annotation_types/geometry/polygon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def geometry(self) -> geojson.Polygon:
3636
def from_shapely(cls, shapely_obj: SPolygon) -> Polygon:
3737
"""Transforms a shapely object."""
3838
#we only consider 0th index because we only allow for filled polygons
39-
obj_coords = shapely_obj.__geo_interface__['coordinates'][0]
4039
if not isinstance(shapely_obj, SPolygon):
41-
raise ValueError(
40+
raise TypeError(
4241
f"Expected Shapely Polygon. Got {shapely_obj.geom_type}")
42+
obj_coords = shapely_obj.__geo_interface__['coordinates'][0]
4343
return Polygon(
4444
points=[Point(x=coords[0], y=coords[1]) for coords in obj_coords])
4545

labelbox/data/annotation_types/geometry/rectangle.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
from typing import Optional, Union, Tuple
2+
from typing import Optional, Type, Union, Tuple
33

44
import cv2
55
import geojson
@@ -39,14 +39,10 @@ def from_shapely(cls, shapely_obj: SPolygon) -> Rectangle:
3939
If the provided shape is a non-rectangular polygon, a rectangle will be
4040
returned based on the min and max x,y values."""
4141
if not isinstance(shapely_obj, SPolygon):
42-
raise ValueError(
42+
raise TypeError(
4343
f"Expected Shapely Polygon. Got {shapely_obj.geom_type}")
4444

45-
#we only consider 0th index because we only allow for filled polygons
46-
obj_coords = np.array(shapely_obj.__geo_interface__['coordinates'][0])
47-
48-
min_x, max_x = np.min(obj_coords[:, 0]), np.max(obj_coords[:, 0])
49-
min_y, max_y = np.min(obj_coords[:, 1]), np.max(obj_coords[:, 1])
45+
min_x, min_y, max_x, max_y = shapely_obj.bounds
5046

5147
start = [min_x, min_y]
5248
end = [max_x, max_y]

0 commit comments

Comments
 (0)