-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdemo_30min.py
executable file
·94 lines (65 loc) · 3.68 KB
/
demo_30min.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/python
"""
Copyright (c) 2014 High-Performance Computing and GIS (HPCGIS) Laboratory. All rights reserved.
Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Authors and contributors: Eric Shook ([email protected]);
"""
# Import the PCML package to start developing in the parallel cartographic modeling language (PCML)
from pcml import *
# Import the operation system (os) package path
# so that it works with MS Windows, Mac OS X, or Linux
import os.path as path
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# 1. In this section, you will create your own myLocalSum operation
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# This is the 'main' section that will execute our code
if __name__ == '__main__':
print("In 30 minutes or less you can begin developing in the parallel cartographic modeling language.")
print("You will need to create and call your own operation, and if you are bold you can compare your")
print("results with our results to make sure your operation is correct.")
print("You can do this in 5 easy steps and we walk you through every step of the way.")
# Default data directory (where our data -- dataa.asc and datab.asc -- are located)
datadir="data"
# Read 2 layers that we will add together using PCML
layera=ReadASCIIGrid(path.join(datadir,"dataa.asc"))
layerb=ReadASCIIGrid(path.join(datadir,"datab.asc"))
# Print out the layers so that we can see the data
print("layera",layera) # This prints the layer information and bounding box
layera.print_data() # This prints the data
print("layerb",layerb)
layerb.print_data()
# Add the two layers together using PCML-style map algebra
sumresult=layera+layerb
# Print the sum results
print("sumresult",sumresult) # This prints the layer information and bounding box
sumresult.print_data() # This prints the data
# Write the sum results to a file named 'sumresult.asc' in the data directory
WriteASCIIGrid(path.join(datadir,"sumresult.asc"), sumresult)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# 2. In this section, call your myLocalSum operation and save the results to a 'myresult' layer
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# 3. In this section, print your 'myresult' layer (layer information and the data)
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#print("myresult",myresult)
#myresult.print_data()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# 4. Write your 'myresult' layer to a file named 'myresult.asc' by uncommenting the line of code
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#WriteASCIIGrid(path.join(datadir,"myresult.asc"), myresult)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# 5. If you are bold, then uncomment the next three lines of code to see if the difference is zero!
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#differencelayer=myresult-sumresult
#print("\n\nDifference (should be all zeroes)",differencelayer)
#differencelayer.print_data()