1/69
Introduction to Geocomputing
Name  | Mastery  | Learn  | Test  | Matching  | Spaced  | 
|---|
No study sessions yet.
Well-known Text (WKT)
a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects and transformations between spatial reference system
Well-known Binary (WKB)
used to transfer and store the same information on databases
Points/Lines/Polygons
an area consists of lines, which consist of points, which consist of coordinates
.shp
shapefiles are storing vector-based geometric informtion of geographic features
.prj
a file containing coordinate system information to provide spatial referencing of data in ArcGIS
.shx
the index file that stores the index feature geometry
.dbf
the dBASE table that stores the attribute information of features
Topology Matters
allows many GIS operations to be done without accessing the point files (efficiency)
Incorrect calculations (perimeter, area, attributes)
Avoid data analysis nightmares
Raster data is best for:
Continuous data- things that change smoothly across space
Examples: elevation, temperature, rainfall, satellite images or aerial photos
Vector data is best for:
Discrete data- things that have clear boundaries or locations
Examples: raods, rivers, city boundaries, land parcels, utility lines
Interpreter
a program that executes computer code (source code →interpreter→ output)
Compiler
translates the program into low-level machine instructions (source code→compiler→object code→executor→output)
Syntax Errors
refer to the structure of a program and the rules about syntax
Runtime Errors
error does not appear until you run the program; also called exceptions
Semantic/Logic Errors
codes can run succesfully but it will give out the wrong result
long (data type in python)
used for huge integers that are outside the range of int
complex (python data type)
representing numbers with a fractional part
type()
displays the python type for any value
type(3) → int
type(True) → bool
Logical Operators
<,>,==,!=,>=,<=, and, or, not
Membership Operators
in, not in
float(), str(), int()
converts the value inside to whatever type it will be (type conversion)
id() function
takes a value or a variable and returns an integer that acts as a unique identifer which is guaranteed to be unique and constant for this object during its lifetime
dot notation
specify the module and then the function followed by a dot (e.g. math.log(x))
Modularity
breaking a system or program into smaller, independart parts that can be developed, tested, and reused separtely
if__name==”__main__”:
to make sure certain code only runs when the file is executed directly, not when it is imported as a module into another program
for loop
picks each element out of the sequence and sets the loop variable equal to that item (perform a block of code for a number of times)
a sequence is:
a string of characters: “Python”
a list ex: [1,2,3], [‘a’,’b’,’c’]
a tuple (“geog”, 378, “intro to geocomputing”)
range(start,stop,step)
range(5) → [0,1,2,3,4]
range(7,3,-1) → [7,6,5,4]
break
end (or break out of) a loop
continue
skip the rest of the loop body statements, but do not end the loop
while loops
causes a block statement to be repeated as long as iteration condition is true
ex:
count = 10
while count > 0
print count
count -=1
print(“Blastoff”)
try/except statements
let you “try” a piece of code that might cause an error, and then “handle” that error if it happens instead of stopping your whole program
example:
try:
#code that might cause an error
except:
#code that runs if there is an error
5 Types of Containers
lists, strings, typles, dictionaires, and sets
Lists
values that make up lists are elements [0,1,2,3]
list()
use this when converting another iterable/copying
Slicing Lists
a[1:3] → 1,2
a[2:] → 2, 3,4,5…
[:] → the whole list
Lists are…
mutable (we can change elements)
del
removes an element from a list
ex: del a[1]
len()
returns the length of a list
list.append(x)
append an item x to the end of a list
list.sort()
order items in ascending orders
list.sort(reverse = True)
order items in descending order
Give a sequence of numbers, how to find the largest? (8,15,45,23,88,68,75)
numbers = [8,15,45,23,88,68,75]
largests = numbers[0]
for n in numbers:
if n > largest:
largest = n
print(largest)
dictionary {}
key value pairs
keys must be immutable (cannot be change)
keys must be unique - no dulpicates
repeated values are okay
Access to Dict
dictName[Key] = value
Strings
can slice strings
strings are immutable, can’t change an existing strings
to get the last letter do:
last[length-1]
String Transversal
processing a string one character at a time
How to count the frequency of a character in a string? Define a function in Python
Find the frequency of ‘a’ in “banana”
fruit = “banana”
count = 0
for char in fruit:
if char == ‘a’:
count = count + 1
print count
Tuples
like list, elements can be any type and variable from element to element
also immutable (cannot be change)
Set
an unordered collection of unique elements
used for checking duplicates or generating unquie collections
open a file
f = open(filename, mode, buffering)
mode/buffering optional
Read and/or Write a file
f.write(…)
Close a File
f.closed
Open File Modes
rt", "rb", "wt"
read text, read binary, write text
Methods for Reading a File
use a for loop to read every line
use a while loop to read every line until the end of the line
Good practice to use the with keyword when dealing with files
PRO: file is closed properly close after it is suite finishes, even if exception is raised on the way
with open (filename, ‘r’) as f:
read_data = f.readlines()
print(f.closed) #TRUE
How to list all files in a directory, and then print all files names with the .csv extensions?
import os
files = os.list.dir(‘.’)
for f in files:
if f.endwith(‘csv’):
print(f)
Class
describes what something is and what it can do
(concept of lake)
Object
a thing (something you can imagine or describe)
attribute: detailes or characteristics (what it has)
behaviors: actions (what it can do)
Ex: a paticular lake
Syntax for generating an instance of a class
classInstance = ClassName()
Data Attribute Assignment
data attributes, like methods, are accessed by using dot notation
ex: pt1 = Point()
pt1.latitude = 34.05
pt1. longitude = -118.24
Protected Attributes
 Prefixed with a single underscore
 Can still be accessed outside of the class
Private Attributes
 Prefixing with a double underscore
 Can be access but cannot be changed
Class Methods
like functions but are defined within the class and are therefore part of the class
class ClassName:
def method1(self, parm1, parm2,…):
statement 1
statement2
dir() function
returns a list of strings containing all the names of valid attributes and methods for the object
init_:
initialize object attributes automatically when created
str:
defines how the object prints as text
dict or vars(obj)
shows all attributes of an object
Inheritance
lets a new class (child) reuse and exten code from another parent
the child inherits all parent method but can override them
How to represent cities in GIS using the classes and objects in Python?
create a class with several attributes, such as name, latitude, longitude and so one
Class Composition
classes can be nested like functions