Python Forum
Covert Shapely Point() to (x, y)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Covert Shapely Point() to (x, y)
#1
I'm trying to convert a Point from a Shapely Linestring.intersection() into (x, y) coordinates that I can use.

Why does this work:
from shapely.geometry import LineString

line1 = LineString([(1,0), (1,1)])
line2 = LineString([(0,1), (1,1)])
coords = []
coords.append(line2.intersection(line1).x)
coords.append(line2.intersection(line1).y)
print(coords)
output: [1.0, 1.0]


Yet this doesn't?
line1 = LineString([(1,790), (790,790)])
line2 = LineString([(self.player.rect.center), (self.station.rect.center)])
coords = []
coords.append(line2.intersection(line1).x)
coords.append(line2.intersection(line1).y)
print(coords)
In the latter I get
Error:
File "C:\Users\owner\Desktop\Python3\python 3.8\Projects\Last_man\main.py", line 1159, in draw coords.append(line2.intersection(line1).x) AttributeError: 'LineString' object has no attribute 'x'
I did try splitting the rect.centers into separate numbers, but that didn't help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Rotated Rectangle overlap using Shapely pyNew 0 1,694 Feb-25-2021, 04:54 AM
Last Post: pyNew
  connecting the first point to the last point Matplotlib omar_mohsen 0 4,574 Jan-15-2020, 01:23 PM
Last Post: omar_mohsen
  is there py code to covert nums to text? Skaperen 6 20,083 Sep-30-2016, 04:20 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020