I am unable to get the same results when running the qgis:reproject tool from QGIS processing toolbox (QGIS version 2.0.1) as when running it from a Python script (console). In this example I am projecting from WGS 84 to Europe Albers Equal Area Conic.

In the toolbox, I run Geoalgorithms->Vector->General tools->Reproject layer. I choose my target projection and input/output files. I uncheck the box to load the layer after finishing. After the tool has ran, I find a .shp, .shx, .dbf, .prj and .qpj file on disk.

If I in console do the following:

layer = QgsVectorLayer("C:/path/to/input.shp", "layername", "ogr")
processing.runalg("qgis:reprojectlayer", layer, "ESPG:102013", "C:/path/to/output.shp")

the result is a .shp, .shx and .dbf file on disk, as well as an empty .prj and .qpj file. Well, the .qpj file is 1 byte, seemingly a newline. Why are these not written properly?

Using a diff tool on the output files, the .shp and .shx files are not the same as the output from the toolbox algorithm. What is the toolbox version doing that I am not? According to processing_qgis.log the same processing algorithm is ran. (Note: Turns out I overlooked a critical point here, see my answer)

This question evolved from the following question: No prj file output from qgis:reproject. Basically I am trying to reproject a layer from one CRS to another, and import that layer into QGIS, retaining distortions (no on-the-fly projection). This works fine if I run the toolbox algorithm, but if I run it from script I get some sort of on-the-fly projection, even though it is disabled in settings. Note that copying the .prj and/or .qpj files does not help.

This is how it should look after importing the layer (and indeed how it looks if I run from toolbox):

From toolbox

This is how it looks when I project using script:

From console

The way I import the layers is through the Layer->Add Vector Layer menu item.

Would really appreciate any help on this.


You know this line?

processing.runalg("qgis:reprojectlayer", layer, "ESPG:102013", "C:/path/to/output.shp")

Turns out I spelled EPSG wrong. Yup.

| improve this answer | |
  • We all do that sometimes :) – Paulo Raposo Nov 3 '15 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.