/[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 2356 by jan, Tue Sep 28 19:31:05 2004 UTC revision 2486 by jan, Sat Dec 18 22:57:03 2004 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 32  if __name__ != '__main__': Line 32  if __name__ != '__main__':
32      from Thuban import _      from Thuban import _
33      from Thuban.Model.layer import Layer      from Thuban.Model.layer import Layer
34    
 from Thuban.UI.extensionregistry import ExtensionDesc, ext_registry  
   
35  import shapelib  import shapelib
36  import dbflib  import dbflib
37    
   
 ext_registry.add(ExtensionDesc(  
     name = 'gns2shp',  
     version = '1.0.0',  
     authors= [ 'Jan-Oliver Wagner' ],  
     copyright = '2003, 2004 Intevation GmbH',  
     desc = _("Converts GNS (Geographical Name Service\n" \  
              "of NIMA) to Shapefile format and\n" \  
              "displays the data.")))  
   
   
38  def gns2shp(src_fname, dest_fname):  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 77  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, 11, 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')
# Line 112  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,

Legend:
Removed from v.2356  
changed lines
  Added in v.2486

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26