xdenisx

Make_poly_shape

Mar 19th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import shapefile
  2. import sys
  3.  
  4. lon1 = float(sys.argv[1])
  5. lat1 = float(sys.argv[2])
  6. lon2 = float(sys.argv[3])
  7. lat2 = float(sys.argv[4])
  8.  
  9. pref = sys.argv[5]
  10.  
  11. # Create a polygon shapefile
  12. w = shapefile.Writer(shapefile.POLYGON)
  13. w.poly(parts=[[[lon1,lat1],[lon1,lat2],[lon2,lat2],[lon2,lat1],[lon1,lat1]]])
  14. w.field('FIRST_FLD','C','40')
  15. w.field('SECOND_FLD','C','40')
  16. w.record('First','Polygon')
  17.  
  18. w.save('%s' % pref)
  19.  
  20. # create the PRJ file
  21. prj = open("%s.prj" % pref, "w")
  22. epsg = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS    84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]'
  23. prj.write(epsg)
  24. prj.close()
Advertisement
Add Comment
Please, Sign In to add comment