GIS Logo GSP 118 (318): GIS Programming

Assignment: Writing Synthetic Data to Text Files

In Review

1. Introduction

You've seen that writing out text files in Python is relatively easy and you can create your own files that contain anything you want them to. Now it's your turn to create two files that contain spatial data that you define.

2. Writing Point Files

Create a text file that contains the entire grid of coordinates on the earth that end in 0 (i.e. (0,0), (10,0), (20,0), etc.) using Latitude and Longitude. The most elegant solution would be a loop within another loop as we used for our synthetic raster example. Also, include an attribute column that includes information on the range of values for the coordinates. As an example, have an attribute column that indicates when the longitude and latitude are less than 0. You'll want to use an "if" statement for this.

The typical way to format a text file that contains points is to have one column for the "x" (longitude or easting) and a column for the "y" values (latitude or northing) and then additional columns for each attribute. If you add a "header" (one row) for the column names, then you can load the file into ArcGIS using the "Add X Y Data" menu command. You can also load the file into Excel to check it and it should look something like the following:

Lon lat Height DBH
-105 40.123 10

30

-122 48.32 30 100

Remember that each row should end in a "newline" character ("\n"). You can use tabs to separate each value and then save the file with a ".txt" extension (tab-delimited text) or use commas to separate the values and then save the file as ".csv" file.

3. A Synthetic Raster

Create a raster that is at least 10 x 10 pixels and contains data defined by you. The data can contain a mathematic function, random data, or random data modulated by a mathematical function.

Remember to take your time, go step by step, and make sure each piece works before moving on. Also remember to load the file into ArcGIS or another GIS package to make sure it works.

Turn In

Turn in just the two code files for this project. I'll just the programs and see what the output does. Your documentation should include what to expect from the files.