0

I am trying to learn Shapely and I ultimately would like to take a series of x,y coordinates and create an offset or parallel line. I previously posted a question on this process last night and realized it may have been confusing, so let me restate it and try to attack it in smaller chunks. I am running Windows 7 64 bit with Anaconda. I have installed Shapely and Shapefile modules. I am trying to create a LineString; however, whenever I do so, I am getting an error. Please find code:

from shapely.geometry import LineString

x1

Out[56]: 1633042.5200605541

y1

Out[57]: 700342.4999843091

x2

Out[58]: 1632943.7118592262

y2

Out[59]: 700441.360350892

LineString([(x1,y1),(x2,y2)])

Out[60]: 
Received invalid SVG data. 

What does this mean 'invalid SVG data'? Am I doing something wrong. I will probably have other questions after this is resolved, but let us do one step at a time. I tried converting x1,y1,x2,y2 into floats and it doesn't seem to help.

  • What are `x` and `y`? (As in what types and what data?) What error or incorrect output are you getting? What output do you expect? Shapely is not arcpy; don't expect it to work exactly the same way. You need to understand what's different about it. (I've worked with ArcGIS; I consider it a blessing when things don't work the same way as it.) – jpmc26 Jan 27 '15 at 06:49

2 Answers2

1

This was a bug, and is fixed. The SVG data was indeed invalid. Upgrade to Shapely>=1.5.6

Mike T
  • 41,085
  • 18
  • 152
  • 203
0

From your question, it looks like you are running your code inside of an IPython (qt)console? The problem appears to be unrelated to Shapely, but rather some issue with IPython trying to render/draw your LineString as a vector image (in SVG format).

Using ipython qtconsole:

In [1]: from shapely.geometry import LineString

In [2]: x = LineString([(16.3,7.0),(16.2,7.1)])

In [3]: x
Out[3]: 
Received invalid SVG data.

If you were to run the same code in the "standard" IPython console, or even in a standard Python interpreter, your code should work just fine.

Using just ipython:

In [1]: from shapely.geometry import LineString

In [2]: x = LineString([(16.3,7.0),(16.2,7.1)])

In [3]: x
Out[3]: <shapely.geometry.linestring.LineString at 0x113c30f60>

Long story short, everything is working just fine with your original code; the error is just the IPython console failing to plot the LineString. All other Shapely operations should be unaffected. For example:

In [4]: list(x.coords)
Out[4]: [(16.3, 7.0), (16.2, 7.1)]

In [5]: x.length
Out[5]: 0.14142135623731025
chdorr
  • 288
  • 3
  • 8
  • Thank you! This made a lot of sense. I am using Spyder that came with anaconda. But your answer made a lot of sense. – Trevor Grout Jan 30 '15 at 03:05