I have 180 point feature classes with rainfall totals. Each feature class represents one days rainfall for a region and has around 36K points (think of each point as a weather station in the region). Each feature class only has one non-required attribute, "RAINFALL" with the total rainfall for a given day at that weather station. I need to join these features together so that the resulting feature class has a attribute column for each day. Here is my simplistic start to my code:

import arcpy
arcpy.env.workspace = r'C:\users\rainfall_data'
fcs = arcpy.ListFeatureClasses()
print fcs
for fc in fcs:
    desc = arcpy.Describe(fc)
    shpname = 'r_'+desc.name[:8]
    print shpname
print "Merging..."
print "Done."

Obviously merging is not getting me the result I want. I get roughly 4 million points and a lot of 0's because it merges every record but I don't know how I can do this with spatial join.

I'm new to arcpy.

  • 1
    This isn't a complete answer to your question as, to be honest, I'm a bit confused as to what exactly you're trying to accomplish (a brief example or more detailed explanation of what the desired outcome is may help, or I may just be missing the point). But, on a related note, you should carefully consider if you have to have the data in Shapefile format or if outputting the data to a file geodatabase feature class would be acceptable. I don't know the file sizes you're getting, but there are known limits for shapefiles. support.esri.com/em/knowledgebase/techarticles/detail/37447 – John Sep 23 '14 at 1:46
  • 1
    How will you decide which day's rainfall is contained within any given shapefile - is this included in the shapefile's name? Or within an attribute in the shapefile? – Stephen Lead Sep 23 '14 at 2:06
  • Stephen, it is contained in the name of the shapefile. In lines 6 and 7 of my code I'm using the describe function to get the shapefile name to be used as the newly added attribute. – Brain Sep 23 '14 at 2:10
  • John, sorry for the lack of clarity. Ultimately I need a shapefile that has 180 attributes (columns) (one for each day) with the rainfall totals at each of the weather stations (rows). I'm under the 2GB limit for shapefiles but I had that same thought. – Brain Sep 23 '14 at 2:16

I am assuming that you have a unique identifier (e.g. SiteID) on your point locations that is common to all 180 shapefiles. I suspect that this is probably the case.

I'll also assume that the Rainfall values are stored in a field with a different name for each shapefile that represents the date e.g. RainJan1, RainJan2, etc. If not, then you may need to use the Add/Calc/DeleteField technique for renaming shapefile fields rather than Alter Field (Data Management) that works for geodatabases nowadays (or do this as part of TableToTable field mapping - see below).

We can then keep the first shapefile as it is and for the other 179 shapefiles do the following:

  1. Use arcpy.TableToTable_conversion to strip just the unique identifier (e.g. SiteID) and rainfall field (e.g. RainJan2) out into a two column table (e.g.RainJan2Table):
  • The Field Map parameter controls how the input fields in the Input Features will be written to the Output Features.
  • To drop fields during the conversion, delete input fields from the Field Map. This will not affect the input feature class.
  1. Use arcpy.JoinField_management to join the two column table (e.g.RainJan2Table) onto the first shapefile using the unique identifier (e.g. SiteID) as the join field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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