示例#1
1
文件: vsutils.py 项目: vrx/vspy
def zipextract(zipName):
    z = zipp(zipName)
    for f in z.namelist():
        if f.endswith("/"):
            os.makedirs(f)
        else:
            z.extract(f)
示例#2
0
def GetWFSLayer(u, p):
  start = time.time()
  # Separate the WFS URL & the layer name
  split_url = u.split('?')
  server_url = split_url[0]
  ows = server_url[-3:]
  print 'The OGC standard is: '+ ows
  
  spacename_wfs = split_url[1]
  tmp_chemin = p + spacename_wfs+"_.zip"
  chemin = tmp_chemin[:-5]+".zip"
  
  if not os.path.exists(chemin):
    # Get the vector layer using OGC WFS standard
    wfs = WebFeatureService(server_url ,version='1.0.0')
    getFeature = wfs.getfeature(typename = [spacename_wfs], outputFormat ="shape-zip") 
    
    print('Downloading... : '+ spacename_wfs)
    print("From: "+ server_url)
    
    # Download the zipped shapefile
    data = getFeature.read()
    f = open(tmp_chemin ,'wb')
    f.write(data)
    f.close()
    
    # Delete .txt & .cst files from the zipped file
    zin = zipp(tmp_chemin, 'r')
#    zin.extractall(p)
    zout = zipp(chemin, 'w')
    for item in zin.infolist():
      buffer = zin.read(item.filename)
      ext = item.filename[-4:]
      if (ext != '.txt' and ext != '.cst'):
          zout.writestr(item, buffer)
          
    zout.close()
    zin.close()
    os.remove(tmp_chemin)
    
#    # Unzip zipped shapefile
    os.system("unzip "+ chemin + ' -d '+ p)
  
  # Calculat time
  temps =time.time() - start
  tps = round(temps,2)
  temps_ms = str(tps)
  
  print "GetWFSLayer download time : " + temps_ms +" ms"
  
  return