[Thuban-commits] r2845 - in trunk/thuban/Extensions/gns2shp: . test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jun 20 07:20:04 CEST 2008


Author: elachuni
Date: 2008-06-20 07:20:03 +0200 (Fri, 20 Jun 2008)
New Revision: 2845

Added:
   trunk/thuban/Extensions/gns2shp/README
Modified:
   trunk/thuban/Extensions/gns2shp/gns2shp.py
   trunk/thuban/Extensions/gns2shp/test/README
   trunk/thuban/Extensions/gns2shp/test/test_gns2shp.py
Log:
Updating gns2shp to support the new GNS file format.



Added: trunk/thuban/Extensions/gns2shp/README
===================================================================
--- trunk/thuban/Extensions/gns2shp/README	2008-06-19 08:18:46 UTC (rev 2844)
+++ trunk/thuban/Extensions/gns2shp/README	2008-06-20 05:20:03 UTC (rev 2845)
@@ -0,0 +1,8 @@
+This extension converts Files of Geographic Names for Geopolitical Areas
+from GNS to Shapefile format.
+
+These files can be downloaded from
+http://earth-info.nga.mil/gns/html/cntry_files.html
+They are simple tab-separated value files.  A description of the meaning
+of each field can be found at
+http://earth-info.nga.mil/gns/html/gis_countryfiles.htm

Modified: trunk/thuban/Extensions/gns2shp/gns2shp.py
===================================================================
--- trunk/thuban/Extensions/gns2shp/gns2shp.py	2008-06-19 08:18:46 UTC (rev 2844)
+++ trunk/thuban/Extensions/gns2shp/gns2shp.py	2008-06-20 05:20:03 UTC (rev 2845)
@@ -58,10 +58,11 @@
 
     shp = shapelib.create(shp_filename, shapelib.SHPT_POINT)
     dbf = dbflib.create(dbf_filename)
+
     dbf.add_field('RC', dbflib.FTInteger, 1, 0)
     dbf.add_field('UFI', dbflib.FTInteger, 10, 0)
     dbf.add_field('UNI', dbflib.FTInteger, 10, 0)
-    dbf.add_field('UTM', dbflib.FTString, 4, 0)
+    dbf.add_field('MGRS', dbflib.FTString, 15, 0)
     dbf.add_field('JOG', dbflib.FTString, 7, 0)
     dbf.add_field('FC', dbflib.FTString, 1, 0)
     dbf.add_field('DSG', dbflib.FTString, 5, 0)
@@ -69,10 +70,11 @@
     dbf.add_field('CC1', dbflib.FTString, 2, 0)
     dbf.add_field('ADM1', dbflib.FTString, 2, 0)
     dbf.add_field('ADM2', dbflib.FTString, 200, 0)
-    dbf.add_field('DIM', dbflib.FTInteger, 10, 0)
+    dbf.add_field('POP', dbflib.FTInteger, 10, 0)
+    dbf.add_field('ELEV', dbflib.FTInteger, 10, 0)
     dbf.add_field('CC2', dbflib.FTString, 2, 0)
-    dbf.add_field('NT', dbflib.FTString, 1, 0)
-    dbf.add_field('LC', dbflib.FTString, 2, 0)
+    dbf.add_field('NT', dbflib.FTString, 2, 0)
+    dbf.add_field('LC', dbflib.FTString, 3, 0)
     dbf.add_field('SHORT_FORM', dbflib.FTString, 128, 0)
     dbf.add_field('GENERIC', dbflib.FTString, 128, 0)
     dbf.add_field('SORT_NAME', dbflib.FTString, 200, 0)
@@ -87,30 +89,32 @@
     i = 0
     for line in gns:
         if line[0] == '#': continue
-        RC, UFI, UNI, DD_LAT, DD_LONG, DMS_LAT, DMS_LONG, UTM, \
-            JOG, FC, DSG, PC, CC1, ADM1, ADM2, DIM, CC2, NT, LC, \
-            SHORT_FORM, GENERIC, SORT_NAME, FULL_NAME, FULL_NAME_ND, \
-            MODIFY_DATE  = line.split('\t')
-        RC = int(RC)
+        RC, UFI, UNI, LAT, LONG, DMS_LAT, DMS_LONG, MGRS, JOG, FC, DSG, PC, \
+            CC1, ADM1, ADM2, POP, ELEV, CC2, NT, LC, SHORT_FORM, GENERIC, \
+            SORT_NAME, FULL_NAME, FULL_NAME_ND, MODIFY_DATE = line.split('\t')
+        try: RC = int(RC)
+        except ValueError: RC = None
         UFI = int(UFI)
         UNI = int(UNI)
-        DD_LAT = float(DD_LAT)
-        DD_LONG = float(DD_LONG)
+        LAT = float(LAT)
+        LONG = float(LONG)
         try: PC = int(PC)
-        except: PC = None
-        try: DIM = int(DIM)
-        except: DIM = None
+        except ValueError: PC = None
+        try: POP = int(POP)
+        except ValueError: POP = None
+        try: ELEV = int(ELEV)
+        except ValueError: ELEV = None
         MODIFY_DATE = MODIFY_DATE[0:10] # kill trailing "\n" or "\r\n"
-        obj = shapelib.SHPObject(shapelib.SHPT_POINT, i, [[(DD_LONG, DD_LAT)]])
+        obj = shapelib.SHPObject(shapelib.SHPT_POINT, i, [[(LONG, LAT)]])
         shp.write_object(-1, obj)
-        dbf.write_record(i, { 'RC': RC, 'UFI': UFI, 'UNI': UNI, 'UTM': UTM,
-                              'JOG': JOG, 'FC': FC, 'DSG': DSG, 'PC': PC,
-                              'CC1': CC1, 'ADM1': ADM1, 'ADM2': ADM2,
-                              'DIM': DIM, 'CC2': CC2, 'NT': NT, 'LC': LC,
-                              'SHORT_FORM': SHORT_FORM, 'GENERIC': GENERIC,
-                              'SORT_NAME': SORT_NAME, 'FULL_NAME': FULL_NAME,
-                              'FULL_ND': FULL_NAME_ND,
-                              'MODIFY_DAT': MODIFY_DATE})
+
+        vals = {'RC': RC, 'UFI': UFI, 'UNI': UNI, 'MGRS':MGRS, 'JOG': JOG,
+                'FC': FC, 'DSG': DSG, 'PC': PC, 'CC1': CC1, 'ADM1': ADM1,
+                'ADM2': ADM2, 'POP': POP, 'ELEV': ELEV, 'CC2': CC2, 'NT': NT,
+                'LC': LC, 'SHORT_FORM': SHORT_FORM, 'GENERIC': GENERIC,
+                'SORT_NAME': SORT_NAME, 'FULL_NAME': FULL_NAME,
+                'FULL_ND': FULL_NAME_ND, 'MODIFY_DAT': MODIFY_DATE}
+        dbf.write_record(i, vals)
         i += 1
 
     del shp

Modified: trunk/thuban/Extensions/gns2shp/test/README
===================================================================
--- trunk/thuban/Extensions/gns2shp/test/README	2008-06-19 08:18:46 UTC (rev 2844)
+++ trunk/thuban/Extensions/gns2shp/test/README	2008-06-20 05:20:03 UTC (rev 2845)
@@ -1,4 +1,4 @@
-This directory contains tests of the gns2shl extension.
+This directory contains tests of the gns2shp extension.
 
 About file "ls.txt":
 

Modified: trunk/thuban/Extensions/gns2shp/test/test_gns2shp.py
===================================================================
--- trunk/thuban/Extensions/gns2shp/test/test_gns2shp.py	2008-06-19 08:18:46 UTC (rev 2844)
+++ trunk/thuban/Extensions/gns2shp/test/test_gns2shp.py	2008-06-20 05:20:03 UTC (rev 2845)
@@ -48,7 +48,7 @@
         n = gns2shp(filename, dest_filename)
 
         # is the number of shapes correct?
-        eq(n, 88) # what gns2shp reports
+        eq(n, 109) # what gns2shp reports
         # and now the actually written ones
         shp = shapelib.ShapeFile(dest_filename)
         numshapes, shapetype, mins, maxs = shp.info()
@@ -61,7 +61,7 @@
         field_types = { 'RC': FTInteger,
                         'UFI': FTInteger,
                         'UNI': FTInteger,
-                        'UTM': FTString,
+                        'MGRS': FTString,
                         'JOG': FTString,
                         'FC': FTString,
                         'DSG': FTString,
@@ -69,7 +69,8 @@
                         'CC1': FTString,
                         'ADM1': FTString,
                         'ADM2': FTString,
-                        'DIM': FTInteger,
+                        'POP': FTInteger,
+                        'ELEV': FTInteger,
                         'CC2': FTString,
                         'NT': FTString,
                         'LC': FTString,



More information about the Thuban-commits mailing list