/[thuban]/trunk/thuban/Extensions/gns2shp/gns2shp.py
ViewVC logotype

Diff of /trunk/thuban/Extensions/gns2shp/gns2shp.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2203 by jan, Tue May 11 22:34:49 2004 UTC revision 2721 by dpinte, Sat Jan 13 15:11:42 2007 UTC
# Line 1  Line 1 
1  # Copyright (C) 2003 by Intevation GmbH  # Copyright (C) 2003, 2004 by Intevation GmbH
2  # Authors:  # Authors:
3  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]> (2003, 2004)
4  #  #
5  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
6  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 23  __version__ = '$Revision$' Line 23  __version__ = '$Revision$'
23    
24  import os, sys  import os, sys
25    
26  # only import GUI 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.command import registry, Command      from Thuban.UI.command import registry, Command
31      from Thuban.UI.mainwindow import main_menu      from Thuban.UI.mainwindow import main_menu
# Line 39  def gns2shp(src_fname, dest_fname): Line 39  def gns2shp(src_fname, dest_fname):
39      """Convert a file from gns textformat into a Shapefile.      """Convert a file from gns textformat into a Shapefile.
40    
41      The GNS text format is described on      The GNS text format is described on
42      http://www.nima.mil/gns/html/cntyfile/gis.html      http://www.nima.mil/gns/html/gis.html
43    
44      src_fname  -- Filename of the GNS standard textfile (including suffix '.txt)      src_fname  -- Filename of the GNS standard textfile (including suffix '.txt)
45      dest_fname -- Filename where to write the Shapefile components (name      dest_fname -- Filename where to write the Shapefile components (name
# Line 64  def gns2shp(src_fname, dest_fname): Line 64  def gns2shp(src_fname, dest_fname):
64      dbf.add_field('JOG', dbflib.FTString, 7, 0)      dbf.add_field('JOG', dbflib.FTString, 7, 0)
65      dbf.add_field('FC', dbflib.FTString, 1, 0)      dbf.add_field('FC', dbflib.FTString, 1, 0)
66      dbf.add_field('DSG', dbflib.FTString, 5, 0)      dbf.add_field('DSG', dbflib.FTString, 5, 0)
67      dbf.add_field('PC', dbflib.FTInteger, 10, 0)      dbf.add_field('PC', dbflib.FTInteger, 1, 0)
68      dbf.add_field('CC1', dbflib.FTString, 2, 0)      dbf.add_field('CC1', dbflib.FTString, 2, 0)
69      dbf.add_field('ADM1', dbflib.FTString, 2, 0)      dbf.add_field('ADM1', dbflib.FTString, 2, 0)
70      dbf.add_field('ADM2', dbflib.FTString, 2, 0)      dbf.add_field('ADM2', dbflib.FTString, 200, 0)
71      dbf.add_field('DIM', dbflib.FTInteger, 10, 0)      dbf.add_field('DIM', dbflib.FTInteger, 10, 0)
72      dbf.add_field('CC2', dbflib.FTString, 2, 0)      dbf.add_field('CC2', dbflib.FTString, 2, 0)
73      dbf.add_field('NT', dbflib.FTString, 1, 0)      dbf.add_field('NT', dbflib.FTString, 1, 0)
74      dbf.add_field('LC', dbflib.FTString, 2, 0)      dbf.add_field('LC', dbflib.FTString, 2, 0)
75      dbf.add_field('SHORT_FORM', dbflib.FTString, 40, 0)      dbf.add_field('SHORT_FORM', dbflib.FTString, 128, 0)
76      dbf.add_field('GENERIC', dbflib.FTString, 40, 0)      dbf.add_field('GENERIC', dbflib.FTString, 128, 0)
77      dbf.add_field('SORT_NAME', dbflib.FTString, 40, 0)      dbf.add_field('SORT_NAME', dbflib.FTString, 200, 0)
78      dbf.add_field('FULL_NAME', dbflib.FTString, 40, 0)      dbf.add_field('FULL_NAME', dbflib.FTString, 200, 0)
79      dbf.add_field('FULL_ND', dbflib.FTString, 40, 0)      dbf.add_field('FULL_ND', dbflib.FTString, 200, 0) # FULL_NAME_ND
80      dbf.add_field('MODIFY_DATE', dbflib.FTString, 10, 0)      dbf.add_field('MODIFY_DATE', dbflib.FTString, 11, 0)
81      del dbf      del dbf
82      dbf = dbflib.open(dbf_filename, 'r+b')      dbf = dbflib.open(dbf_filename, 'r+b')
83    
# Line 99  def gns2shp(src_fname, dest_fname): Line 99  def gns2shp(src_fname, dest_fname):
99          except: PC = None          except: PC = None
100          try: DIM = int(DIM)          try: DIM = int(DIM)
101          except: DIM = None          except: DIM = None
102            MODIFY_DATE = MODIFY_DATE[0:10] # kill trailing "\n" or "\r\n"
103          obj = shapelib.SHPObject(shapelib.SHPT_POINT, i, [[(DD_LONG, DD_LAT)]])          obj = shapelib.SHPObject(shapelib.SHPT_POINT, i, [[(DD_LONG, DD_LAT)]])
104          shp.write_object(-1, obj)          shp.write_object(-1, obj)
105          dbf.write_record(i, { 'RC': RC, 'UFI': UFI, 'UNI': UNI, 'UTM': UTM,          dbf.write_record(i, { 'RC': RC, 'UFI': UFI, 'UNI': UNI, 'UTM': UTM,
# Line 122  def gns2shp_dialog(context): Line 123  def gns2shp_dialog(context):
123    
124      context -- The Thuban context.      context -- The Thuban context.
125      """      """
126      dlg = wxFileDialog(context.mainwindow,      dlg = wx.FileDialog(context.mainwindow,
127                         _('Select GNS file'), '.', '',                         _('Select GNS file'), '.', '',
128                         _('Generate Files (*.txt)|*.txt|') +                         _('Generate Files (*.txt)|*.txt|') +
129                         _('All Files (*.*)|*.*'),                         _('All Files (*.*)|*.*'),
130                         wxOPEN|wxOVERWRITE_PROMPT)                         wx.OPEN|wx.OVERWRITE_PROMPT)
131      if dlg.ShowModal() == wxID_OK:      if dlg.ShowModal() == wx.ID_OK:
132          gns_filename = dlg.GetPath()          gns_filename = dlg.GetPath()
133          dlg.Destroy()          dlg.Destroy()
134      else:      else:

Legend:
Removed from v.2203  
changed lines
  Added in v.2721

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26