File: epsg_option.tcl

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (287 lines) | stat: -rw-r--r-- 13,045 bytes parent folder | download | duplicates (2)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#=====================================================================================
#   
#            FILE:  epsg_option.tcl
#   
#     DESCRIPTION:  adds the utility to execute Netelers script to create a location 
#                   using the epsg codes
#  
#           NOTES:  ---
#          AUTHOR:  Antonello Andrea
#           EMAIL:  antonell@ing.unitn.it
#         COMPANY:  Engineering, University of Trento / CUDAM
#       COPYRIGHT:  Copyright (C) 2004 University of Trento / CUDAM, ITALY, GPL
#         VERSION:  1.0
#         CREATED:  04/01/2004
#        REVISION:  ---
#=====================================================================================
#
#
# 
#  This library is free software; you can redistribute it and/or 
#  modify it under the terms of the GNU Library General Public 
#  License as published by the Free Software Foundation; either 
#  version 2 of the License, or (at your option) any later version. 
#
#  This library is distributed in the hope that it will be useful, 
#  but WITHOUT ANY WARRANTY; without even the implied warranty of 
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
#  Library General Public License for more details. 
#
#  You should have received a copy of the GNU Library General Public 
#  License along with this library; if not, write to the Free 
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 
#  USA 
#
#1. Redistributions of source code must retain the above copyright   
#   notice, this list of conditions and the following disclaimer.   
#2. Redistributions in binary form must reproduce the above copyright   
#   notice, this list of conditions and the following disclaimer in the   
#   documentation and/or other materials provided with the distribution.   
# 
#############################################################################
#
#   part regarding to the creation of a new location using proj and 
#   the EPSG codes    (routines epsgLocCom and infoEpsg)
#
#############################################################################

global browsedepsg 


# the frame used to set EPSG parameters 
proc epsgLocCom args {
        #vars declaration
        global database
        global epsgLocation 
        global epsg_code
        global env
        global thelocation
        global browsedepsg 
        
        set browsedepsg "/usr/local/share/proj/epsg"
        set epsgLocation "newLocation"
        set epsg_code ""
        
        # creation of the parameter window
        toplevel .optPopup
        wm title .optPopup {Epsg Settings}
        # put it in the middle of the screen
        update idletasks
        set winWidth [winfo reqwidth .optPopup]
        set winHeight [winfo reqheight .optPopup]
        set scrnWidth [winfo screenwidth .optPopup]
        set scrnHeight [winfo screenheight .optPopup]
        set x [expr ($scrnWidth - $winWidth) / 2-250]
        set y [expr ($scrnHeight  - $winHeight) / 2]
        wm geometry .optPopup +$x+$y
        wm deiconify .optPopup
        
        #create the form and buttons
        label .optPopup.input1_ppb -text "Name of new location" -justify center 
        entry .optPopup.input1_ppbEntry -textvariable epsgLocation -width 35
        label .optPopup.input2_ppb -text "Database" -justify center 
        entry .optPopup.input2_ppbEntry -textvariable database  -width 35
        label .optPopup.input3_ppb -text "Path to the EPSG-codes file" -justify center 
        entry .optPopup.input3_ppbEntry -textvariable browsedepsg  -width 35
        label .optPopup.input4_ppb -text "EPSG code number of projection" -justify center 
        entry .optPopup.input4_ppbEntry -textvariable epsg_code  -width 35
        
        button .optPopup.browseepsgfile -justify center -width 9 -text "browse" \
                                        -command "set browsedepsg \[tk_getOpenFile\]" 
                                        
        bind .optPopup.input3_ppbEntry <Leave> {
             if {$browsedepsg == ""} {
                set browsedepsg "/usr/local/share/proj/epsg"
            }
        }

        button .optPopup.codes 	-justify center -width 9 -text "EPSG-codes" \
                        -command {
                                  if {[file exists $browsedepsg]== 0} {
                                    DialogGen .wrnDlg "WARNING: epsg-codes file not found" warning "WARNING: \
                                    The epsg-codes file was not found!" \
                                    0 OK;
                                  }
                                  if {[file exists $browsedepsg]== 1} {
                                    codesEpsg;
                                  }
                                 }
                                
                                     
        pack .optPopup.codes -side left -fill both -expand 1
        
        button .optPopup.param 	-justify center -width 9 -text "?" \
                        -command {infoEpsg}
        pack .optPopup.param -side left -fill both -expand 1
        
        button .optPopup.submit 	-justify center -width 6 -text "ok" -state disabled\
                        -command {
                                  set thelocation "$database/$epsgLocation";
                                  if {[file exists $thelocation ]== 1} {
                                    DialogGen .wrnDlg "WARNING: location exists" warning "WARNING: \
                                    The location '$thelocation' already exists, please try another name" \
                                    0 OK;
                                  }
                                  if {[file exists $browsedepsg]== 0} {
                                    DialogGen .wrnDlg "WARNING: epsg-codes file not found" warning "WARNING: \
                                    The epsg-codes file was not found!" \
                                    0 OK;
                                  }
                                  if {[file exists $browsedepsg]== 1} {
                                      if {[file exists $thelocation ]==0} {  
                                        destroy .optPopup; 
                                        exec -- xterm -e $env(GISBASE)/etc/make_location_epsg.sh \
                                            $epsg_code $epsgLocation $database >@stdout 2>@stderr; 
                                        DialogGen .wrnDlg "WARNING: restart Grass please" warning "WARNING: \
                                            Please restart Grass in order find the created location in the list (closing it for you now)" \
                                            0 OK; 
                                        set env(EPSGSCRIPT) {yes};
                                        puts stdout "exit";
                                        destroy . 
                                      }
                                  }
                                  set thelocation ""
                                 }

        bind .optPopup.input4_ppbEntry <KeyRelease> {
            .optPopup.submit configure -state active
        }

        pack .optPopup.submit -side left -fill both -expand 1
        
        button .optPopup.cancel -justify center -width 6 -text "cancel" \
                        -command {destroy .optPopup}
        pack .optPopup.submit -side left -fill both -expand 1

        # geometry
        grid .optPopup.input1_ppb 	-row 0 -column 0
        grid .optPopup.input1_ppbEntry 	-row 0 -column 1 -columnspan 2
        grid .optPopup.input2_ppb 	-row 1 -column 0
        grid .optPopup.input2_ppbEntry 	-row 1 -column 1 -columnspan 2
        grid .optPopup.input3_ppb 	-row 2 -column 0
        grid .optPopup.input3_ppbEntry 	-row 2 -column 1 -columnspan 2
        grid .optPopup.browseepsgfile   -row 2 -column 3 
        grid .optPopup.input4_ppb 	-row 3 -column 0
        grid .optPopup.input4_ppbEntry 	-row 3 -column 1 -columnspan 2
        grid .optPopup.codes 		-row 3 -column 3 
        grid .optPopup.submit 		-row 4 -column 0
        grid .optPopup.cancel 		-row 4 -column 1
        grid .optPopup.param 		-row 4 -column 3 
}

# listing of the EPSG codes
proc codesEpsg args {
    
        global browsedepsg
    
        toplevel .infoPopup
        wm title .infoPopup {EPSG-codes}
        update idletasks
        set winWidth [winfo reqwidth .infoPopup]
        set winHeight [winfo reqheight .infoPopup]
        set scrnWidth [winfo screenwidth .infoPopup]
        set scrnHeight [winfo screenheight .infoPopup]
        set x [expr ($scrnWidth - $winWidth) / 2-230]
        set y [expr ($scrnHeight  - $winHeight) / 2 - 110]
        wm geometry .infoPopup +$x+$y
        wm deiconify .infoPopup
        
        text .infoPopup.text -width 100 -height 50\
                   -wrap word \
                   -relief raised \
                   -yscrollcommand ".infoPopup.vscroll set"
                   
        # tag configuration
        .infoPopup.text tag configure underline -underline 1
        .infoPopup.text tag configure title -relief raised -borderwidth 2 -background grey -justify center
        .infoPopup.text tag configure lefttitle -relief raised -borderwidth 2 -background grey
        .infoPopup.text tag configure subtitle -relief raised -borderwidth 2 
    
        
        # the text to be inserted
        .infoPopup.text insert end " \nEPSG - code file $browsedepsg\n\n" title
        .infoPopup.text insert end " \n\n" subtitle
        
        # open the file 
        set f [open $browsedepsg "r"]
        set found ""
        while { [eof $f] == 0 } {
            set line [gets $f]
            set firstdash [string first # $line]
            set firstminor [string first < $line]
            if {$firstdash == "0"} {
                .infoPopup.text insert end "$line\n" lefttitle
                set found "yes"
            }
            if {$firstminor == "0"} {
                .infoPopup.text insert end "$line\n\n" subtitle
            }
            if {$firstminor != "0" && $firstdash != "0" && $found != "yes"} {
                .infoPopup.text insert end "\n\nGUESS THAT IS NOT THE EPSG FILE\n\n" title;
                break;
            }
        }
        
        pack .infoPopup.text -side left -fill y 
        
        scrollbar .infoPopup.vscroll \
                    -relief raised \
                    -command ".infoPopup.text yview"
        pack .infoPopup.vscroll -side right -fill y
        
        button .infoPopup.ex -justify center -width 5 -text "ok" \
                             -command {destroy .infoPopup}			
        pack .infoPopup.ex -side bottom -expand 1 -fill both
}

# help for the EPSG Location creation
proc infoEpsg args {

        toplevel .infoPopup
        wm title .infoPopup {Info}
        update idletasks
        set winWidth [winfo reqwidth .infoPopup]
        set winHeight [winfo reqheight .infoPopup]
        set scrnWidth [winfo screenwidth .infoPopup]
        set scrnHeight [winfo screenheight .infoPopup]
        set x [expr ($scrnWidth - $winWidth) / 2-230]
        set y [expr ($scrnHeight  - $winHeight) / 2]
        wm geometry .infoPopup +$x+$y
        wm deiconify .infoPopup
        
        text .infoPopup.text -width 40 -height 30\
                   -wrap word \
                   -relief raised \
                   -yscrollcommand ".infoPopup.vscroll set"
                   
        # tag configuration
        .infoPopup.text tag configure underline -underline 1
        .infoPopup.text tag configure title -relief raised -borderwidth 2 -background grey -justify center
        .infoPopup.text tag configure subtitle -relief raised -borderwidth 2 
    
        # the text to be inserted
        .infoPopup.text insert end " \nCREATION OF A NEW grass LOCATION WITH EPSG\n " title
        .infoPopup.text insert end "- needed parameters -\n\n" title
        .infoPopup.text insert end "\n" 
        .infoPopup.text insert end "\n   Name of new location:\n\n" subtitle
        .infoPopup.text insert end "\nRequires as input the name of the new location to be created\n\n"
        .infoPopup.text insert end "\n" 
        .infoPopup.text insert end "\n   Database:\n\n" subtitle
        .infoPopup.text insert end "\nThe Grass database in which the location should be created\n\n"
        .infoPopup.text insert end "\n" 
        .infoPopup.text insert end "\n   EPSG code number of projection:\n\n" subtitle
        .infoPopup.text insert end "\nEPSG code number of projection (see /usr/local/share/proj/epsg or push the 'EPSG-codes' button)\n\n"
        
        pack .infoPopup.text -side left -fill both 
        
        scrollbar .infoPopup.vscroll \
                    -relief raised \
                    -command ".infoPopup.text yview"
        pack .infoPopup.vscroll -side right -fill y
        
        button .infoPopup.ex -justify center -width 5 -text "ok" \
                             -command {destroy .infoPopup}			
        pack .infoPopup.ex -side bottom -expand 1 -fill both
}