Python Demo


# 1. Assign numeric values to two variables, add them together, and print the result
#Assigning the variable "a" to equal 2
>>> a=2
#Assigning the variable "b" to equal 6
>>> b=6
#Using the print statement to compute the variables "a"+"b"
>>> print a+b
8
>>> 
#def is short for definition in this line of code. We are defining the variable "myDistance" to equal this list of integers
 def myDistance (x1,y1,x2,y2):
# After assigning the defnition, we then need to assign the variables, "a", "b", and "dist"
	a=(x2-x1)
	b=(y2-y1)
#This line of code is using the built in square root function that Python offers. So it is saying that the variable dist is equal to the square root of "a" +"b"	
        dist=sqrt(a**2+b**2)
#The return statement is a little different then that print statement, in the fact that return gives back a value , such as the mathematical value we are computing up above. 
	return dist



Python demo Questions

1.What major geospatial factor must your consider when interpreting the distance computed by either your method or the Shapely distance method? [ Cartesian plane vs. geoid ]
The major geospatial factor that you must consider would be the type of map projection that you have chosen.
2.What are the units of the computed distance from Shapely?
The units that are computed from the shapely python package are geographic coordinates that have been computed through the series of code.
3.Describe an example scenario in which you might use a distance computation in a GIS analysis.
A scenario where you would use a distance computation in a GIS analyst would be for example planning out a tsunami evacuation zone. You can compute out the area that would be impacted by a tsunami off the coast of Oregon, and you could find out what parts of the city would be more susceptible to being hit by the impending waves. You could use distance computation to find out how close the nearest safe zones would be to the areas that would be hit the hardest by the waves.
4.What does this code do?
a.Describe the process in your own words (proper English sentences)

The process first off is defining the x and y variables in the beginning, in this example x is being defined as five, and y is being defined 3. The third line of code is the command code that is printing the answer to the input code of (x+2) which is really just (5+2). The code prints 7. The next set of code is still using the same defined variables as before, but it is testing them through a different series of mathematical tests. The reusult of this code is 10.
b.what is the result?
The results of the following code is, 7,and 10.
x=5
y=3
print(x+2)

x = x+2
x += y
print(x)

Leave a Reply

Your email address will not be published. Required fields are marked *