title: Determine the "left" and "right" side of a split shapely geometry
body: <p>My question is: how can I determine which of the <code>Aside</code> and <code>Bside</code> sides of <a href="http://nbviewer.jupyter.org/urls/dl.dropbox.com/s/ll3mchnx0jwzjnf/determine%20left-right%20split.ipynb" rel="nofollow noreferrer">an already split rotated rectangular geometry</a> are the "left" and "right" side of an arbitrary <code>LineString</code> that splits that geometry?</p>
  
  <p>For the purposes of this problem, "left" and "right" are defined as the left-hand and right-hand side of a <code>LineString</code> splitter when "walking" from node to node, in order.</p>
  
  <p>I've created this function for splitting <em>any</em> arbitrary <code>shapely</code> geometry (non collection) into two sides - the "left" and the "right":</p>
  
  <pre><code>import shapely.geometry as geo
  import shapely.ops as ops
  
  def splitLR(geom, splitter):
      """Split a geometry into a 'left' and 'right' side using the shapely API"""
      if not isinstance(splitter, geo.LineString):
          raise TypeError("The splitter must be a LineString")
      if not splitter.is_simple:
          raise ValueError("Only simple splitter objects allowed")
      if hasattr(geom, "__iter__"):
          raise ValueError("Geometry collections not allowed")
      geom_extents = geo.GeometryCollection([geom, splitter]).minimum_rotated_rectangle
      sides = ops.split(geom_extents, splitter)
      try:
          Aside, Bside = sides
      except TypeError:
          # only 1 result - rotated rectangle wasn't split
          if len(ops.split(geom,splitter)) == 1:
              # geom isn't split by splitter
              raise ValueError("the splitter does not appear to split the geometry")
          else:
              # splitter too small for algorithm
              raise ValueError("the splitter must extend beyond minimum_rotated_rectangle "
                               "of the combined geometry")
      # determine which is Lside and Rside here
      Lside,Rside = get_LRsides(Aside, Bside, splitter)
      return tuple(side.intersection(geom) for side in (Lside, Rside))
  </code></pre>
  
  <p>The idea of the above is illustrated in the notebook linked here (same link as above):</p>
  
  <p><a href="http://nbviewer.jupyter.org/urls/dl.dropbox.com/s/ll3mchnx0jwzjnf/determine%20left-right%20split.ipynb" rel="nofollow noreferrer">http://nbviewer.jupyter.org/urls/dl.dropbox.com/s/ll3mchnx0jwzjnf/determine%20left-right%20split.ipynb</a></p>
  
  <p>To summarize: sides A and B are the two sides of the <a href="http://shapely.readthedocs.io/en/stable/manual.html#constructive-methods" rel="nofollow noreferrer"><code>minimum_rotated_rectangle</code></a> surrounding the <code>geom</code> geometry and the <code>splitter</code> line string together. When <code>side.intersection(geom)</code> is executed, the result is the portion of the originally given geometry <code>geom</code> contained in that side.</p>
  
  <p>Notes: </p>
  
  <ul>
  <li>it is possible- for oddly shaped "potato" type objects- for this intersection to result in multiple objects on one or both sides (see the nbviewer example)</li>
  <li>I have created my own function here (rather than using <code>ops.split</code>) because the <code>ops.split</code> function just returns a "bag" of split objects, and there isn't a way to determine which side they are on (that I'm aware of)</li>
  </ul>
  
  <p>Currently my call to <code>get_LRsides</code> just executes this function, which is obviously worthless:</p>
  
  <pre><code>def get_LRsides(Aside, Bside, splitter):
      """Determine the 'left' and 'right' sides of an already split geometry"""
      return Aside,Bside
  </code></pre>
  
  <p>How can I successfully label A and B as "left" and "right"?</p>