[GRASS-SVN] r62899 - grass/trunk/scripts/v.in.gns

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 24 15:25:37 PST 2014


Author: lucadelu
Date: 2014-11-24 15:25:37 -0800 (Mon, 24 Nov 2014)
New Revision: 62899

Modified:
   grass/trunk/scripts/v.in.gns/v.in.gns.py
Log:
v.in.gns: update with new gns format

Modified: grass/trunk/scripts/v.in.gns/v.in.gns.py
===================================================================
--- grass/trunk/scripts/v.in.gns/v.in.gns.py	2014-11-24 22:40:32 UTC (rev 62898)
+++ grass/trunk/scripts/v.in.gns/v.in.gns.py	2014-11-24 23:25:37 UTC (rev 62899)
@@ -20,7 +20,7 @@
 #               for details.
 #
 # TODO:         - see below in the code
-#               - add extra columns explaining some column acronyms, 
+#               - add extra columns explaining some column acronyms,
 #                 e.g. FC (Feature Classification)
 #############################################################################
 
@@ -37,53 +37,61 @@
 #% required: no
 #%end
 
-import sys
-import os
 from grass.script.utils import try_remove, basename, parse_key_val
 from grass.script import core as grass
 from grass.script import vector as vgrass
 
+
 def main():
     fileorig = options['input']
     filevect = options['output']
-    
+
     if not filevect:
-	filevect = basename(fileorig, 'txt')
+        filevect = basename(fileorig, 'txt')
 
     #are we in LatLong location?
     s = grass.read_command("g.proj", flags='j')
     kv = parse_key_val(s)
     if kv['+proj'] != 'longlat':
-	grass.fatal(_("This module only operates in LatLong/WGS84 locations"))
+        grass.fatal(_("This module only operates in LatLong/WGS84 locations"))
 
     #### setup temporary file
     tmpfile = grass.tempfile()
 
-    coldescs = [("RC",		"rc integer"),
-		("UFI",		"uf1 integer"),
-		("UNI",		"uni integer"),
-		("LAT",		"lat double precision"),
-		("LONG",	"lon double precision"),
-		("DMS_LAT",	"dms_lat varchar(6)"),
-		("DMS_LONG",	"dms_long varchar(7)"),
-		("UTM",		"utm varchar(4)"),
-		("JOG",		"jog varchar(7)"),
-		("FC",		"fc varchar(1)"),
-		("DSG",		"dsg varchar(5)"),
-		("PC",		"pc integer"),
-		("CC1",		"cci varchar(2)"),
-		("ADM1",	"adm1 varchar(2)"),
-		("ADM2",	"adm2 varchar(200)"),
-		("DIM",		"dim integer"),
-		("CC2",		"cc2 varchar(2)"),
-		("NT",		"nt varchar(1)"),
-		("LC",		"lc varchar(3)"),
-		("SHORT_FORM",	"shortform varchar(128)"),
-		("GENERIC",	"generic varchar(128)"),
-		("SORT_NAME",	"sortname varchar(200)"),
-		("FULL_NAME",	"fullname varchar(200)"),
-		("FULL_NAME_ND","funamesd varchar(200)"),
-		("MODIFY_DATE",	"mod_date date")]
+    coldescs = [("RC", "rc integer"),
+                ("UFI", "uf1 integer"),
+                ("UNI", "uni integer"),
+                ("LAT", "lat double precision"),
+                ("LONG", "lon double precision"),
+                ("DMS_LAT", "dms_lat integer"),
+                ("DMS_LONG", "dms_long integer"),
+                ("MGRS", "mgrs varchar(15)"),
+                ("JOG", "jog varchar(7)"),
+                ("FC", "fc varchar(1)"),
+                ("DSG", "dsg varchar(6)"),
+                ("PC", "pc integer"),
+                ("CC1", "cci varchar(255)"),
+                ("ADM1", "adm1 varchar(2)"),
+                ("POP", "pop integer"),
+                ("ELEV", "elev double precision"),
+                ("CC2", "cc2 varchar(255)"),
+                ("NT", "nt varchar(2)"),
+                ("LC", "lc varchar(3)"),
+                ("SHORT_FORM", "shortform varchar(128)"),
+                ("GENERIC", "generic varchar(128)"),
+                ("SORT_NAME_RO", "sortnamero varchar(255)"),
+                ("FULL_NAME_RO", "fullnamero varchar(255)"),
+                ("FULL_NAME_ND_RO", "funamesdro varchar(255)"),
+                ("SORT_NAME_RG", "sortnamerg varchar(255)"),
+                ("FULL_NAME_RG", "fullnamerg varchar(255)"),
+                ("FULL_NAME_ND_RG", "funamesdrg varchar(255)"),
+                ("NOTE", "note varchar(4000)"),
+                ("MODIFY_DATE", "mod_date date"),
+                ("DISPLAY", "display varchar(255)"),
+                ("NAME_RANK", "namerank integer"),
+                ("NAME_LINK", "namelink integer"),
+                ("TRANSL_CD", "translcd varchar(32)"),
+                ("NM_MODIFY_DATE", "nmmodifydate varchar(10)")]
 
     colnames = [desc[0] for desc in coldescs]
     coltypes = dict([(desc[0], 'integer' in desc[1]) for desc in coldescs])
@@ -93,26 +101,26 @@
     inf = file(fileorig)
     outf = file(tmpfile, 'wb')
     for line in inf:
-	fields = line.rstrip('\r\n').split('\t')
-	if not header:
-	    header = fields
-	    continue
-	vars = dict(zip(header, fields))
-	fields2 = []
-	for col in colnames:
-	    if col in vars:
-		if coltypes[col] and vars[col] == '':
-		    fields2.append('0')
-		else:
-		    fields2.append(vars[col])
-	    else:
-		if coltypes[col]:
-		    fields2.append('0')
-		else:
-		    fields2.append('')
-	line2 = ';'.join(fields2) + '\n'
-	outf.write(line2)
-	num_places += 1
+        fields = line.rstrip('\r\n').split('\t')
+        if not header:
+            header = fields
+            continue
+        vars = dict(zip(header, fields))
+        fields2 = []
+        for col in colnames:
+            if col in vars:
+                if coltypes[col] and vars[col] == '':
+                    fields2.append('0')
+                else:
+                    fields2.append(vars[col])
+            else:
+                if coltypes[col]:
+                    fields2.append('0')
+                else:
+                    fields2.append('')
+        line2 = ';'.join(fields2) + '\n'
+        outf.write(line2)
+        num_places += 1
     outf.close()
     inf.close()
 
@@ -125,7 +133,7 @@
     # MIN=`echo $IN | cut -b3,4`
     # SEC=`echo $IN | cut -b5,6`
     # DEG_STR="$DEG:$MIN:$SEC"
-    
+
     #modifications (to match DBF 10 char column name limit):
     # short_form   -> shortform
     # sort_name    -> sortname
@@ -136,9 +144,8 @@
 
     columns = [desc[1] for desc in coldescs]
 
-    grass.run_command('v.in.ascii', cat = 0, x = 5, y = 4, sep = ';',
-		      input = tmpfile, output = filevect,
-		      columns = columns)
+    grass.run_command('v.in.ascii', cat=0, x=5, y=4, sep=';',
+                      input=tmpfile, output=filevect, columns=columns)
 
     try_remove(tmpfile)
 
@@ -148,4 +155,3 @@
 if __name__ == "__main__":
     options, flags = grass.parser()
     main()
-



More information about the grass-commit mailing list