Skip to content

Commit

Permalink
allow rotations to be performed on Points
Browse files Browse the repository at this point in the history
implements Rotatable for singlepart geometries and Multipoints
  • Loading branch information
njwilson23 committed Mar 3, 2017
1 parent 63b7857 commit a56f5cf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# The short X.Y version.
version = '0.8'
# The full version, including alpha/beta/rc tags.
release = '0.8.0'
release = '0.8.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
44 changes: 23 additions & 21 deletions karta/vector/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,26 @@ def __init__(self, properties=None, crs=Cartesian):
self._geotype = None
return

class Point(Geometry, GeoJSONOutMixin, ShapefileOutMixin):
class Rotatable(object):

def rotate(self, thetad, origin=(0, 0)):
""" Rotate rank 2 geometry.
Parameters
----------
thetad : float
degreesof rotation
origin : tuple of two floats, optional
pivot for rotation (default (0, 0))
"""
ct = math.cos(thetad*math.pi / 180.0)
st = math.sin(thetad*math.pi / 180.0)
x, y = origin
M = np.array([[ct, -st, -x*ct + y*st + x],
[st, ct, -x*st - y*ct + y]], dtype=np.float64)
return self.apply_transform(M)

class Point(Geometry, Rotatable, GeoJSONOutMixin, ShapefileOutMixin):
""" Point object instantiated with:
Parameters
Expand Down Expand Up @@ -550,23 +569,6 @@ def shift(self, shift_vector):
[0, 1, shift_vector[1]]], dtype=np.float64)
return self.apply_transform(trans_mat)

def rotate(self, thetad, origin=(0, 0)):
""" Rotate rank 2 geometry.
Parameters
----------
thetad : float
degreesof rotation
origin : tuple of two floats, optional
pivot for rotation (default (0, 0))
"""
ct = math.cos(thetad*math.pi / 180.0)
st = math.sin(thetad*math.pi / 180.0)
x, y = origin
M = np.array([[ct, -st, -x*ct + y*st + x],
[st, ct, -x*st - y*ct + y]], dtype=np.float64)
return self.apply_transform(M)

def _subset(self, idxs):
""" Return a subset defined by indices. """
vertices = [self.vertices[i] for i in idxs]
Expand Down Expand Up @@ -832,7 +834,7 @@ def _seg_crosses_dateline(seg):

return any(_seg_crosses_dateline(seg) for seg in self.segments)

class Line(MultiVertexBase, ConnectedMultiVertexMixin, GeoJSONOutMixin, ShapefileOutMixin):
class Line(MultiVertexBase, ConnectedMultiVertexMixin, Rotatable, GeoJSONOutMixin, ShapefileOutMixin):
""" Line composed of connected vertices.
Parameters
Expand Down Expand Up @@ -986,7 +988,7 @@ def to_polygon(self):
""" Returns a polygon. """
return Polygon(self.vertices, properties=self.properties, crs=self.crs)

class Polygon(MultiVertexBase, ConnectedMultiVertexMixin, GeoJSONOutMixin, ShapefileOutMixin):
class Polygon(MultiVertexBase, Rotatable, ConnectedMultiVertexMixin, GeoJSONOutMixin, ShapefileOutMixin):
""" Polygon, composed of a closed sequence of vertices.
Parameters
Expand Down Expand Up @@ -1244,7 +1246,7 @@ def __len__(self):
return len(self.vertices)


class Multipoint(Multipart, MultiVertexMixin, GeoJSONOutMixin, ShapefileOutMixin):
class Multipoint(Multipart, Rotatable, MultiVertexMixin, GeoJSONOutMixin, ShapefileOutMixin):
""" Point cloud with associated attributes.
Parameters
Expand Down
2 changes: 1 addition & 1 deletion karta/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.8.0"
__version__ = "0.8.1"

0 comments on commit a56f5cf

Please sign in to comment.