GIS Logo GSP 118 (318): GIS Programming

Assignment 1: Series of Numbers

The purpose of these assignments are to get you comfortable in the Wing IDE, start programming in Python, and also to do something useful. It is of great value to be able to generate a specific series of numbers based on mathematical functions. These series can be used to; sub-sample data, test new statistical methods, and create fake or "synthetic" data for modeling.

1.1 A Simple Series

Create a loop that outputs a series of numbers. This can be done with a "while" loop, some print statements, and a statement to increment a counter. Then, use the counter as a parameter for a mathematical function. This can be a function you create or one from a math package (remember to include the math package). You'll want to make two series of numbers. You can do this in one loop or two. Loop enough times that you can see the series clearly in a graph (30 to 100 works well). Use "print" functions to output the values and you'll see them appear in the "Debug I/O" tab. Then, paste the values into Excel (or another spreadsheet package) as two columns, select the columns, and insert a new chart in Excel. You'll want to add a title to the chart and labels on the axis.

The final step is to document your program (or do it as you go along). You'll want to add a header block with the purpose of the program, author's name (or initials), and the date it was last modified.

Turn In

  • A program that creates two series of numbers, one with out randomness and one with some level of randomness or "noise".
  • Documentation within the file

Remember to send me the code file that ends in ".py" so I can run it to make sure it works.

 

1.2 Fun with Coordinates

A common task in geospatial programming is converting azimuths (directions) and distances to coordinates. This is common from surveying data where they will setup a central station and then "shoot" locations getting their direction and distance from the central station. The distances and directions are also call "meets and bounds".

To convert a direction and a distance to a coordinate we just need the original coordinate and a little trigonometry.

x=sin(Angle)*Distance

y=cos(Angle)*Distance

You can have some fun with this by creating a loop that goes from 0 to 360 recording the x and y values generated by the equations above. You just need to remember that in Python, the trigonometric functions work in radians so you'll need to convert the Angles to radians.

AngleInRadians=(AngleInDegrees/180)*PI

The constant "PI" is defined in the math library. There is also a "radians()" function in the math library if you'd like to use it.

Once you write the loop and import the values in the Excel, plot them in a scatter gram or and you'll see you've created a circle. Now change the value of the "Distance" based on the Angle and you can make a variety of interesting designs. This part is just for fun.

Turn In

1. A Python script that creates a circular design modulating the values of the distance. Output x and y to "Debug I/O" so they can be plotted in Excel.