xdenisx

line_shp

Jul 27th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import shapefile as sf
  2. import sys, glob
  3.  
  4. #in_file = sys.argv[1]
  5. ffiles = glob.glob('00*.txt')
  6.  
  7. #Shapefile creation
  8. shp_filename = 'shp//aari_ibgfrc_120_%s.shp' % ffiles[0].split('.')[0].split('_')[-1]
  9. # create the shapefile
  10. w = sf.Writer(sf.POLYLINE)
  11. w.field('Ice_Object_Num','C','40')
  12.  
  13.  
  14. for ifile in ffiles:
  15.     ff = open(ifile,'r')
  16.     lines = ff.readlines()
  17.  
  18.     ll = []
  19.  
  20.     for line in lines:
  21.         x0 = float(line.split()[0])
  22.         y0 = float(line.split()[1])
  23.         ll.append([y0,x0])
  24.    
  25.     w.line(parts=[ll])
  26.     id = ifile.split('.')[0].split('_')[0]
  27.     w.record(id)
  28.    
  29. w.save(shp_filename)
  30.  
  31. ff.close()
  32.  
  33. # create the PRJ file
  34. prjfn = shp_filename[:-4]
  35. prj = open("%s.prj" % prjfn, "w")
  36. epsg = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]'
  37. prj.write(epsg)
  38. prj.close()
Advertisement
Add Comment
Please, Sign In to add comment