Skip to content

Commit

Permalink
Python scripts: fix all warnings/errors reported by pyflakes
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.osgeo.org/gdal/trunk@28389 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
rouault committed Jan 30, 2015
1 parent 2cb9979 commit 4b6a415
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 39 deletions.
2 changes: 0 additions & 2 deletions gdal/swig/python/scripts/epsg_tr.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def Usage():
# =============================================================================
def trHandleCode(code, gen_dict_line, report_error, output_format):

import time

try:
err = prj_srs.ImportFromEPSG( code )
except:
Expand Down
2 changes: 1 addition & 1 deletion gdal/swig/python/scripts/gcps2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def Usage():
# ----------------------------------------------------------------------------
ds = gdal.Open( in_file )
if ds is None:
print('Unable to open %s' % filename)
print('Unable to open %s' % in_file)
sys.exit(1)

gcp_srs = ds.GetGCPProjection()
Expand Down
1 change: 0 additions & 1 deletion gdal/swig/python/scripts/gcps2wld.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import gdal

import sys
import os.path

if len(sys.argv) < 2:
print("Usage: gcps2wld.py source_file")
Expand Down
7 changes: 3 additions & 4 deletions gdal/swig/python/scripts/gdal2tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@
Class is available under the open-source GDAL license (www.gdal.org).
"""

import math

MAXZOOMLEVEL = 32

class GlobalMercator(object):
Expand Down Expand Up @@ -441,7 +439,7 @@ def __init__(self, width, height, tilesize = 256, tileformat='jpg'):
self.tierImageSize = []
self.tierImageSize.append( imagesize );

while (imagesize[0] > tilesize or imageSize[1] > tilesize ):
while (imagesize[0] > tilesize or imagesize[1] > tilesize ):
imagesize = (math.floor( imagesize[0] / 2 ), math.floor( imagesize[1] / 2) )
tiles = ( math.ceil( imagesize[0] / tilesize ), math.ceil( imagesize[1] / tilesize ) )
self.tierSizeInTiles.append( tiles )
Expand Down Expand Up @@ -1055,7 +1053,8 @@ def open_input(self):

def rastertileswne(x,y,z):
pixelsizex = (2**(self.tmaxz-z) * self.out_gt[1]) # X-pixel size in level
pixelsizey = (2**(self.tmaxz-z) * self.out_gt[1]) # Y-pixel size in level (usually -1*pixelsizex)
#Comment pixelsizey as unused...
#pixelsizey = (2**(self.tmaxz-z) * self.out_gt[1]) # Y-pixel size in level (usually -1*pixelsizex)
west = self.out_gt[0] + x*self.tilesize*pixelsizex
east = west + self.tilesize*pixelsizex
south = self.ominy + y*self.tilesize*pixelsizex
Expand Down
2 changes: 0 additions & 2 deletions gdal/swig/python/scripts/gdal_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
from osgeo import gdal

import sys
import stat
import os
import time
import webbrowser

Expand Down
13 changes: 5 additions & 8 deletions gdal/swig/python/scripts/gdal_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@
# gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
################################################################

try:
from osgeo import gdal
from osgeo.gdalnumeric import *
except ImportError:
import gdal
from gdalnumeric import *
from osgeo import gdal
from osgeo import gdalnumeric
import numpy

from optparse import OptionParser
import sys
Expand Down Expand Up @@ -258,7 +255,7 @@ def doit(opts, args):
myBandNo=bandNo
else:
myBandNo=myBands[i]
myval=BandReadAsArray(myFiles[i].GetRasterBand(myBandNo),
myval=gdalnumeric.BandReadAsArray(myFiles[i].GetRasterBand(myBandNo),
xoff=myX, yoff=myY,
win_xsize=nXValid, win_ysize=nYValid)

Expand All @@ -283,7 +280,7 @@ def doit(opts, args):

# write data block to the output file
myOutB=myOut.GetRasterBand(bandNo)
BandWriteArray(myOutB, myResult, xoff=myX, yoff=myY)
gdalnumeric.BandWriteArray(myOutB, myResult, xoff=myX, yoff=myY)

print("100 - Done")
#print("Finished - Results written to %s" %opts.outF)
Expand Down
2 changes: 1 addition & 1 deletion gdal/swig/python/scripts/gdal_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def gdal_edit(argv):
if yres is not None:
gt = ds.GetGeoTransform()
# Doh ! why is gt a tuple and not an array...
gt = [ gt[i] for i in range(6) ]
gt = [ gt[j] for j in range(6) ]
gt[1] = xres
gt[5] = yres
ds.SetGeoTransform(gt)
Expand Down
4 changes: 1 addition & 3 deletions gdal/swig/python/scripts/gdal_fillnodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
#******************************************************************************

try:
from osgeo import gdal, ogr
from osgeo import gdal
except ImportError:
import gdal
import ogr

import sys
import os.path

def CopyBand( srcband, dstband ):
for line in range(srcband.YSize):
Expand Down
1 change: 0 additions & 1 deletion gdal/swig/python/scripts/gdal_polygonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import gdal, ogr, osr

import sys
import os.path

def Usage():
print("""
Expand Down
1 change: 0 additions & 1 deletion gdal/swig/python/scripts/gdal_proximity.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import gdal

import sys
import os.path

def Usage():
print("""
Expand Down
20 changes: 10 additions & 10 deletions gdal/swig/python/scripts/gdal_retile.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@
from osgeo import gdal
from osgeo import ogr
from osgeo import osr
from osgeo.gdalconst import *
except:
import gdal
import ogr
import osr
from gdalconst import *

import sys
import os
Expand Down Expand Up @@ -497,6 +495,7 @@ def createPyramidTile(levelMosaicInfo, offsetX, offsetY, width, height,tileName,

if MemDriver is not None:
tt_fh = Driver.CreateCopy( tileName, t_fh, 0, CreateOptions )
tt_fh.FlushCache()

if Verbose:
print(tileName + " : " + str(offsetX)+"|"+str(offsetY)+"-->"+str(width)+"-"+str(height))
Expand Down Expand Up @@ -569,6 +568,7 @@ def createTile( minfo, offsetX,offsetY,width,height, tilename,OGRDS):

if MemDriver is not None:
tt_fh = Driver.CreateCopy( tilename, t_fh, 0, CreateOptions )
tt_fh.FlushCache()

if Verbose:
print(tilename + " : " + str(offsetX)+"|"+str(offsetY)+"-->"+str(width)+"-"+str(height))
Expand Down Expand Up @@ -818,15 +818,15 @@ def main(args = None):
i+=1
ResamplingMethodString=argv[i]
if ResamplingMethodString=="near":
ResamplingMethod=GRA_NearestNeighbour
ResamplingMethod=gdal.GRA_NearestNeighbour
elif ResamplingMethodString=="bilinear":
ResamplingMethod=GRA_Bilinear
ResamplingMethod=gdal.GRA_Bilinear
elif ResamplingMethodString=="cubic":
ResamplingMethod=GRA_Cubic
ResamplingMethod=gdal.GRA_Cubic
elif ResamplingMethodString=="cubicspline":
ResamplingMethod=GRA_CubicSpline
ResamplingMethod=gdal.GRA_CubicSpline
elif ResamplingMethodString=="lanczos":
ResamplingMethod=GRA_Lanczos
ResamplingMethod=gdal.GRA_Lanczos
else:
print("Unknown resampling method: %s" % ResamplingMethodString)
return 1
Expand Down Expand Up @@ -919,7 +919,7 @@ def main(args = None):


DriverMD = Driver.GetMetadata()
Extension=DriverMD.get(DMD_EXTENSION);
Extension=DriverMD.get(gdal.DMD_EXTENSION);
if 'DCAP_CREATE' not in DriverMD:
MemDriver=gdal.GetDriverByName("MEM")

Expand Down Expand Up @@ -999,7 +999,7 @@ def initGlobals():

Source_SRS=None
TargetDir=None
ResamplingMethod=GRA_NearestNeighbour
ResamplingMethod=gdal.GRA_NearestNeighbour
Levels=0
PyramidOnly=False
LastRowIndx=-1
Expand All @@ -1026,7 +1026,7 @@ def initGlobals():
CsvFileName=None
Source_SRS=None
TargetDir=None
ResamplingMethod=GRA_NearestNeighbour
ResamplingMethod=gdal.GRA_NearestNeighbour
Levels=0
PyramidOnly=False
LastRowIndx=-1
Expand Down
4 changes: 1 addition & 3 deletions gdal/swig/python/scripts/gdal_sieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
#******************************************************************************

try:
from osgeo import gdal, ogr
from osgeo import gdal
except ImportError:
import gdal
import ogr

import sys
import os.path

def Usage():
print("""
Expand Down
1 change: 0 additions & 1 deletion gdal/swig/python/scripts/mkgraticule.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import osr
import ogr

import string
import sys

#############################################################################
Expand Down
1 change: 0 additions & 1 deletion gdal/swig/python/scripts/pct2rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@


import sys
import os.path

def Usage():
print('Usage: pct2rgb.py [-of format] [-b <band>] [-rgba] source_file dest_file')
Expand Down

0 comments on commit 4b6a415

Please sign in to comment.