Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a file with weather data (daily) for multiple weather stations for multiple years. I am looking for some python script to automate the database creation process and its interpolation on a daily basis. The weather data looks like this:

YEAR    MONTH   DAY     Date        STID    TMAX    TMIN    TAVG
2000    1       1       1/1/2000    WENT    72.63   44.02   58.27
2000    1       1       1/1/2000    DKOM    70.66   40.77   55.76
2000    1       1       1/1/2000    OLLU    73.15   33.47   51.67
2000    1       1       1/1/2000    LKNP    -999    -999    -999
2000    1       1       1/1/2000    OWNB    70.88   32.01   52.2
2000    1       1       1/1/2000    ANTL    71.85   31.13   51.66

There is a separate shapefile that is associate with the location of the weather stations. How do I create database using python script so that it can be used later for spatial interpolation? Thanks in advance.

share|improve this question
    
How does the shapefile relate to the CSV file? STID? –  blah238 Feb 27 '12 at 21:10
    
Shapefile has STID with its lat/long, STID is unique –  kdekalb Feb 27 '12 at 21:13
add comment

2 Answers

  1. I would first design the schema of your desired feature class either using ArcGIS Diagrammer or through ArcCatalog. Save this in a file geodatabase which will be used solely as a template.

  2. Next use Copy (Data Management) to copy the template file geodatabase to the desired location, renaming it if necessary.

  3. Next, use Make Feature Layer (Data Management) and Make Table View (Data Management) to create a feature layer from your shapefile and a table view from your CSV file.

  4. Next, use Add Join (Data Management) to join the table view to the feature layer on STID.

  5. Finally, use Append (Data Management) with the appropriate field mappings to append the contents of the feature layer with the join to the template feature class in the new file geodatabase.

    Tip: Do the Append step interactively in ArcCatalog with the field mappings set up as desired and then go to the Results tab, right click the result entry and do "Copy as Python Snippet" to get the fiddly field mapping string you need. Alternatively you can use the FieldMappings object to create this parameter programmatically.

Apart from the first step (designing the template geodatabase), these can all be scripted easily using arcpy function calls. See the help for each command for example usage.

share|improve this answer
    
In all fairness, the first step can be programmed in python too. This is the way I would do it otherwise. +1 –  Hairy Feb 28 '12 at 12:34
add comment
<begin shameless plug>

In 2008 I wrote "Tapping Into the Power of Python: Data mining, data processing, logging, and e-mails" for ArcUser. Here are the code listings - some of the code is outdated, but the concepts could be helpful.

<end shameless plug>
share|improve this answer
    
Great article, Chad! @Kenton it would be a great exercise to get the tabular data for your weather stations directly from the internet as in Listing 3. –  blah238 Feb 27 '12 at 22:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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