Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PyAtlas] Made printouts for geometric objects WKT compatible #146

Merged
merged 1 commit into from
Jun 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Made printouts for geometric objects WKT compatible
  • Loading branch information
lucaspcram committed Jun 21, 2018
commit 81ade776b3cc2afbf67ca7647f52e76b09d9a220
43 changes: 39 additions & 4 deletions pyatlas/pyatlas/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __str__(self):
Get the wkt string representation of this Location. The pair ordering
of Locations is always (LATITUDE, LONGITUDE)
"""
shapely_point = location_to_shapely_point(self)
shapely_point = location_to_shapely_point_wkt_compat(self)
return shapely_point.wkt

def __eq__(self, other):
Expand Down Expand Up @@ -167,7 +167,7 @@ def __str__(self):
"""
Get the wkt string representation of this PolyLine.
"""
shapely_poly = polyline_to_shapely_linestring(self)
shapely_poly = polyline_to_shapely_linestring_wkt_compat(self)
return shapely_poly.wkt

def __eq__(self, other):
Expand Down Expand Up @@ -258,7 +258,7 @@ def __str__(self):
"""
Get the wkt string representation of this Polygon.
"""
shapely_poly = polygon_to_shapely_polygon(self)
shapely_poly = polygon_to_shapely_polygon_wkt_compat(self)
return shapely_poly.wkt

def fully_geometrically_encloses_location(self, location):
Expand Down Expand Up @@ -468,7 +468,7 @@ def boundable_to_shapely_box(boundable):

def polygon_to_shapely_polygon(polygon):
"""
Convert a pyatlas Polygon to its Shapely Polygon representation.
Convert a Polygon to its Shapely Polygon representation.
"""
shapely_points = []
for location in polygon.locations():
Expand All @@ -477,6 +477,18 @@ def polygon_to_shapely_polygon(polygon):
return shapely.geometry.Polygon(shapely.geometry.LineString(shapely_points))


def polygon_to_shapely_polygon_wkt_compat(polygon):
"""
Convert a Polygon to its Shapely Polygon representation but with WKT
compatible coordinates.
"""
shapely_points = []
for location in polygon.locations():
shapely_points.append(location_to_shapely_point_wkt_compat(location))

return shapely.geometry.Polygon(shapely.geometry.LineString(shapely_points))


def location_to_shapely_point(location):
"""
Convert a Location to its Shapely Point representation.
Expand All @@ -487,6 +499,17 @@ def location_to_shapely_point(location):
return shapely.geometry.Point(latitude, longitude)


def location_to_shapely_point_wkt_compat(location):
"""
Convert a Location to its Shapely Point representation but with WKT
compatible coordinates.
"""
latitude = location.get_latitude_deg()
longitude = location.get_longitude_deg()

return shapely.geometry.Point(longitude, latitude)


def polyline_to_shapely_linestring(polyline):
"""
Convert a PolyLine to its Shapely LineString representation.
Expand All @@ -498,6 +521,18 @@ def polyline_to_shapely_linestring(polyline):
return shapely.geometry.LineString(shapely_points)


def polyline_to_shapely_linestring_wkt_compat(polyline):
"""
Convert a PolyLine to its Shapely LineString representation but with
WKT compatible coordinates.
"""
shapely_points = []
for location in polyline.locations():
shapely_points.append(location_to_shapely_point_wkt_compat(location))

return shapely.geometry.LineString(shapely_points)


def _encode_number(number):
"""
Encode a number as a unicode character.
Expand Down