mygeometry module

mygeometry.create_wedge(center_pos, radius, angle, center_rel_pos=0.1, width=None)[source]
Parameters:

center_pos : array-like

x and y pixel coordinates of core

height : int, float

Height of box along y axis.

center_rel_pos : float, optional

Core position in box along y-axis as a fraction of the height with the origin in the south.

width : int, float

Width of box along x axis.

Returns:

wedge_vertices : numpy.array

4 x 2 array with box pixel vertices, starting from lower-left going clockwise.

mygeometry.get_polygon_mask(image, polygon, return_indices=False)[source]
Parameters:

image : array-like

N x M array.

polygon : array-like

K x 2 array of vertices.

Returns:

mask : array-like

N x M boolean array. True for any point inside of polygon.

mygeometry.get_rect(x, y, width, height, angle)[source]

Returns four points of a rotated rectangle.

Author: http://stackoverflow.com/questions/12638790/drawing-a-rectangle-inside-a-2d-numpy-array

Parameters:

x, y : int

x and y positions of rectangle

width : float

Width of rectangle.

height : float

Height of rectangle.

angle : float

Angle of rotation in degrees counter clockwise from East.

mygeometry.get_rectangular_mask(image, x, y, width=None, height=None, angle=0.0, return_indices=False)[source]

Returns a mask excluding pixels outside of a rotated rectangular region.

Parameters:

image : array-like

2D array to be masked.

x, y : int

x and y positions of rectangle

width : float

Width of rectangle.

height : float

Height of rectangle.

angle : float

Angle of rotation in degrees counter-clockwise from East.

Returns:

masked_image : array-like

Masked numpy array.

mygeometry.point_in_polygon(xy, poly)[source]

Tests whether a point is in a polygon.

Parameters:

xy : tuple

(x,y) positions of point to test in polygon.

poly : list

List of tuples comprising the polygon.

Returns:

inside : bool

Whether or not the point is inside the polygon.

mygeometry.rotate_polygon(polygon, anchor, angle)[source]
Parameters:

polygon : array-like

N x 2 array with x coordinates in column 0 and y coordinates in column 1.

anchor : tuple

x and y coordinates of pivot point.

angle : float

Angle to rotate polygon clockwise from North.

Returns:

polygon_translate : array-like

N x 2 array of rotated x and y coordinates.

mygeometry.rotate_wedge(wedge_vertices, anchor, angle)[source]
Parameters:

wedge_vertices : numpy.array

4 x 2 array with box pixel vertices, starting from lower-left going clockwise.

anchor : tuple

x and y coordinates of pivot point.

angle : float

Angle to rotate polygon clockwise from North.

Returns:

wedge_vertices_rotated : numpy.array

4 x 2 array with rotated box pixel vertices.