25 |
|
|
26 |
# only import GUI and register when not called as command line tool |
# only import GUI and register when not called as command line tool |
27 |
if __name__ != '__main__': |
if __name__ != '__main__': |
28 |
from wxPython.wx import * |
import wx |
29 |
|
|
30 |
|
from Thuban.UI import internal_from_wxstring |
31 |
from Thuban.UI.command import registry, Command |
from Thuban.UI.command import registry, Command |
32 |
from Thuban.UI.mainwindow import main_menu |
from Thuban.UI.mainwindow import main_menu |
33 |
from Thuban import _ |
from Thuban import _ |
40 |
"""Convert a file from gns textformat into a Shapefile. |
"""Convert a file from gns textformat into a Shapefile. |
41 |
|
|
42 |
The GNS text format is described on |
The GNS text format is described on |
43 |
http://www.nima.mil/gns/html/cntyfile/gis.html |
http://www.nima.mil/gns/html/gis.html |
44 |
|
|
45 |
src_fname -- Filename of the GNS standard textfile (including suffix '.txt) |
src_fname -- Filename of the GNS standard textfile (including suffix '.txt) |
46 |
dest_fname -- Filename where to write the Shapefile components (name |
dest_fname -- Filename where to write the Shapefile components (name |
65 |
dbf.add_field('JOG', dbflib.FTString, 7, 0) |
dbf.add_field('JOG', dbflib.FTString, 7, 0) |
66 |
dbf.add_field('FC', dbflib.FTString, 1, 0) |
dbf.add_field('FC', dbflib.FTString, 1, 0) |
67 |
dbf.add_field('DSG', dbflib.FTString, 5, 0) |
dbf.add_field('DSG', dbflib.FTString, 5, 0) |
68 |
dbf.add_field('PC', dbflib.FTInteger, 10, 0) |
dbf.add_field('PC', dbflib.FTInteger, 1, 0) |
69 |
dbf.add_field('CC1', dbflib.FTString, 2, 0) |
dbf.add_field('CC1', dbflib.FTString, 2, 0) |
70 |
dbf.add_field('ADM1', dbflib.FTString, 2, 0) |
dbf.add_field('ADM1', dbflib.FTString, 2, 0) |
71 |
dbf.add_field('ADM2', dbflib.FTString, 2, 0) |
dbf.add_field('ADM2', dbflib.FTString, 200, 0) |
72 |
dbf.add_field('DIM', dbflib.FTInteger, 10, 0) |
dbf.add_field('DIM', dbflib.FTInteger, 10, 0) |
73 |
dbf.add_field('CC2', dbflib.FTString, 2, 0) |
dbf.add_field('CC2', dbflib.FTString, 2, 0) |
74 |
dbf.add_field('NT', dbflib.FTString, 1, 0) |
dbf.add_field('NT', dbflib.FTString, 1, 0) |
75 |
dbf.add_field('LC', dbflib.FTString, 2, 0) |
dbf.add_field('LC', dbflib.FTString, 2, 0) |
76 |
dbf.add_field('SHORT_FORM', dbflib.FTString, 40, 0) |
dbf.add_field('SHORT_FORM', dbflib.FTString, 128, 0) |
77 |
dbf.add_field('GENERIC', dbflib.FTString, 40, 0) |
dbf.add_field('GENERIC', dbflib.FTString, 128, 0) |
78 |
dbf.add_field('SORT_NAME', dbflib.FTString, 40, 0) |
dbf.add_field('SORT_NAME', dbflib.FTString, 200, 0) |
79 |
dbf.add_field('FULL_NAME', dbflib.FTString, 40, 0) |
dbf.add_field('FULL_NAME', dbflib.FTString, 200, 0) |
80 |
dbf.add_field('FULL_ND', dbflib.FTString, 40, 0) |
dbf.add_field('FULL_ND', dbflib.FTString, 200, 0) # FULL_NAME_ND |
81 |
dbf.add_field('MODIFY_DATE', dbflib.FTString, 11, 0) |
dbf.add_field('MODIFY_DATE', dbflib.FTString, 11, 0) |
82 |
del dbf |
del dbf |
83 |
dbf = dbflib.open(dbf_filename, 'r+b') |
dbf = dbflib.open(dbf_filename, 'r+b') |
100 |
except: PC = None |
except: PC = None |
101 |
try: DIM = int(DIM) |
try: DIM = int(DIM) |
102 |
except: DIM = None |
except: DIM = None |
103 |
|
MODIFY_DATE = MODIFY_DATE[0:10] # kill trailing "\n" or "\r\n" |
104 |
obj = shapelib.SHPObject(shapelib.SHPT_POINT, i, [[(DD_LONG, DD_LAT)]]) |
obj = shapelib.SHPObject(shapelib.SHPT_POINT, i, [[(DD_LONG, DD_LAT)]]) |
105 |
shp.write_object(-1, obj) |
shp.write_object(-1, obj) |
106 |
dbf.write_record(i, { 'RC': RC, 'UFI': UFI, 'UNI': UNI, 'UTM': UTM, |
dbf.write_record(i, { 'RC': RC, 'UFI': UFI, 'UNI': UNI, 'UTM': UTM, |
124 |
|
|
125 |
context -- The Thuban context. |
context -- The Thuban context. |
126 |
""" |
""" |
127 |
dlg = wxFileDialog(context.mainwindow, |
dlg = wx.FileDialog(context.mainwindow, |
128 |
_('Select GNS file'), '.', '', |
_('Select GNS file'), '.', '', |
129 |
_('Generate Files (*.txt)|*.txt|') + |
_('Generate Files (*.txt)|*.txt|') + |
130 |
_('All Files (*.*)|*.*'), |
_('All Files (*.*)|*.*'), |
131 |
wxOPEN|wxOVERWRITE_PROMPT) |
wx.OPEN|wx.OVERWRITE_PROMPT) |
132 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wx.ID_OK: |
133 |
gns_filename = dlg.GetPath() |
gns_filename = internal_from_wxstring(dlg.GetPath()) |
134 |
dlg.Destroy() |
dlg.Destroy() |
135 |
else: |
else: |
136 |
return |
return |