I have two shapefiles, one which contains event locations and the the other of which represents regions where events take place.

  • Events polygons with year and region_name attributes
  • Regions polygons, which also have year and region_name attributes

The Event polygons sometimes extend beyond their proper Region. Regions sometimes change boundaries, which is why they also have a year attribute. I would like to clip each Event polygon using the appropriate Region polygon, i.e. the one with matching year and region_name attributes. Here is an image I made to illustrate the basic idea:

Illustration of Event polygons being clipped by the appropriate Region polygons

Some solutions I've tried but which have been unsatisfactory:

  • Doing it manually (selecting each event and region by hand and clipping them), which seems unnecessarily tedious
  • Using Select By Location to isolate the Events in each Region, which still requires working with each selection manually
  • Using Intersect, which 1) leaves lots of event "remnants" outside their proper regions and 2) "oversplits" by dividing all Event polygons by all Region polygons, regardless of year

Note: I use both QGIS 1.8 and ArcMap 10.1. I can't install extensions for ArcGIS (I don't have administrative access) but I can use Python scripts.

  • You say you have "groups of shapefiles". Is there a separate shapefile for 1990 events and 1991 events? How about regions: are they split into annual shapefiles?
    – user3461
    Commented Jul 23, 2013 at 12:31
  • @GeoKevin Sorry, I wasn't clear! I have only two shapefiles: one for Events and one for Regions. I'll edit the post accordingly.
    – ASGM
    Commented Jul 23, 2013 at 12:32

2 Answers 2


In ArcMap, you could use python to run nested search cursors. For example:

arcpy.MakeFeatureLayer_management("region shapefile location", "Regions")
arcpy.MakeFeatureLayer_management("event shapefile location", "Events")

out_features = "name and location for output clips"
out_count = 0

r_rows = arcpy.SearchCursor(Regions)
for r_row in r_rows:
  r_name = r_row.region_name
  r_year = r_row.year
  e_rows = arcpy.SearchCursor(Events)
  for e_row in e_rows:
    e_name = e_row.region_name
    e_year = e_row.year
    if r_name == e_name and r_year == e_year:
      out_count += 1
      out_features = out_features + str(out_count)
      query = "\"region_name\" = '" + r_name + "'"
      arcpy.SelectLayerByAttribute_management(Regions, "", query)
      arcpy.SelectLayerByAttribute_management(Events, "ADD_TO_SELECTION", query)
      arcpy.Clip_analysis(Events, Regions, out_features)
  del e_row, e_rows
del r_row, r_rows

You could also do this in ArcMap using ModelBuilder.

String together these tools:

  • Iterate Feature Selection - Use Region Name and Year as Group Fields
  • Calculate Value - Calculate the expression to use to select an event (arcpy snippet) - Feed the expression into the select tool
  • Select - For each iteration, it selects the events that correspond to the region/year combo
  • Clip - Clips the Events by Region based on Region Name/Year combination
  • Delete - Deletes the temporary select feature after the model executes.

enter image description here

  • Thanks for the answer! I accepted Krauser's because I'm more comfortable with Python than ModelBuilder, but this helps make the structure of the process clearer.
    – ASGM
    Commented Jul 23, 2013 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.