I am trying to reproject some ascii files and convert them into shapefiles. I am new to python but looking at some code online and help files I was able to write the following code to run on Python console in QGIS.
import processing
for i in xrange(1, 191):
filename1= "C:\\nsdbg\\GIS data\\watersheds\\ascii\\{}.asc".format(i)
filename2= "C:\\nsdbg\\GIS data\\watersheds\\tifs\\basin_{}.tif".format(i)
filename3= "C:\\nsdbg\\GIS data\\watersheds\\shapefiles\\basin_{}.shp".format(i)
#reproject raster
processing.runalg("gdalogr:warpreproject",filename1,
"+proj=laea +lat_0=55 +lon_0=20 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs",
"EPSG:3035",0,0,"",5,filename2)
#raster into shapefile
processing.runalg("gdalogr:polygonize", filename1,"DN",filename3)
As far as I can tell the reprojection is OK but when creating the shapefile I get 2 per ascii in different parts of the map. The one on the left (in the image below) with the right shape but on the wrong part of the map, and the one on the right in the right place but with a square around it (they are actually quite far apart in the map, I just collated the images).

If I use "polygonize" in the GUI instead of the python console this duplication does not happen and the location is correct. If I use it directly with the ascii file I get the right shape, however if I use it with the tiff file created by this code I do get the square around it (but not the duplication and it is in the right location).