title: Checking whether a list of points lie within a multipolygon (Python)
body: <p>I am trying to check whether a list of points (which are stored in <code>df.Coords</code>) are found inside my shapefile (multipolygon). I wrote a code below, however, I realised that python only reads in the coordinates of my final layer of my multipolygon. </p>
  
  <pre><code>import shapefile
  from shapely.geometry import shape, Point
  
  # read your shapefile
  r = shapefile.Reader("C:\\filename.shp")
  
  # get the shapes
  shapes = r.shapes()
  
  # build a shapely polygon from your shape
  hold = []
  for k in range(len(shapes)-1): 
      polygon = shape(shapes[k])
      hold.append(polygon)
  
  
      for x in df.Coords: 
  
          if polygon.contains(Point(x)):
  
              hold.append(x) 
  </code></pre>
  
  <p>I tried to search for some code on stackoverflow (reference: <a href="https://gis.stackexchange.com/questions/208546/check-if-a-point-falls-within-a-multipolygon-with-python/208574">https://gis.stackexchange.com/questions/208546/check-if-a-point-falls-within-a-multipolygon-with-python/208574</a>) and edited it (as shown below). However, I think I have edited it incorrectly. </p>
  
  <pre><code>from shapely.geometry import Polygon, Point, MultiPolygon
  import shapefile 
  
  polygon = shapefile.Reader("C:\\filename.shp") 
  
  polygon = polygon.shapes() 
  
  shpfilePoints = [ shape.points for shape in polygon ]
  
  #print(shpfilePoints)
  
  
  polygons = shpfilePoints
  hold = []
  
  for polygon in polygons:
      poly = Polygon(polygon)
      hold.append(poly)
      for x in hold: 
  
          for y in df.Coords:
              if x.contains(Point(y)):
                  hold.append(y) 
  print('hold',hold)
  </code></pre>
  
  <p>How can I check if my list of points (<code>df.Coords</code>) lie within my multipolygon (with 26 layers?) </p>