Guest User

Untitled

a guest
Mar 10th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import tarfile
  2. import os
  3.  
  4. # Direktorij u kojem su DKP podaci
  5. dkp_source = 'C:/Users/darko.boto/Desktop/DKP'
  6. # Direktori u koji se trebaju extractati podaci
  7. output_dir = 'C:/Users/darko.boto/Desktop/DKP_OUT'
  8.  
  9. # Parametri za spajanje na bazu
  10. host = 'localhost'
  11. db_name = 'GIS'
  12. user = 'postgres'
  13. passwd = 'postgres'
  14. port = '5432'
  15.  
  16. shp_code_kc = '2020' # kod za prepoznavanje shp datoteka u kojima su KAT cestice
  17.  
  18. def main():
  19. for root, dirs, files in os.walk(dkp_source):
  20. for file in files:
  21. if file.endswith('.tar.gz'):
  22. tar = tarfile.open(os.path.join(root, file), "r:gz")
  23. for tarinfo in tar:
  24. if tarinfo.isreg():
  25. shp_code = tarinfo.name[-8:-4]
  26. if shp_code == shp_code_kc:
  27. tarinfo.path = tarinfo.path.split('/')[2]
  28. print'Extracting:', tarinfo.path
  29. tar.extract(tarinfo, output_dir)
  30.  
  31. def load():
  32. for root, dirs, files in os.walk(output_dir):
  33. for file in files:
  34. if file.endswith('.shp'):
  35. shp_path = os.path.join(root, file)
  36. print 'Loading shapefile: ', file
  37. ogr2ogr_str = 'ogr2ogr -append -s_srs EPSG:3765 -t_srs EPSG:3765 -f "PostgreSQL" PG:"host=%s port=%s user=%s password=%s dbname=%s" -nln dkp_kc_load -nlt MULTIPOLYGON "%s" -progress' % (host, port, user, passwd, db_name, shp_path)
  38. os.system(ogr2ogr_str)
  39.  
  40. if __name__ == '__main__':
  41. main()
  42. #load()
Add Comment
Please, Sign In to add comment