Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'd like to be able to consolidate not only the layers of a QGIS project (using QConsolidate) but also the projections used by each layer. On-the-fly projection reduces performance in QGIS, and this is particularly problematic when working on a slow platform such as an Android tablet; ideally I'd like to be able to quickly recreate a project with all its layers in a single CRS and turn off on-the-fly projection.

Is there a plugin that could take a selected set of vector or raster layers and reproject them, renaming appropriately? Is this perhaps something that could be done directly from the Python console, iterating over selected layers?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Using QGIS/OGR under Ubuntu 12.04.

One way of batch transforming all of the shapefiles in a directory from one CRS to a different one would be to use a shell script. For example, this script would transform all of the shapefiles in a directory from EPSG:27700 to EPSG:32630, renaming the output shapefiles.

for f in *.shp
do
  echo "Processing $f"
ogr2ogr -s_srs "EPSG:27700" -t_srs "EPSG:32630" $f-32630.shp $f
done

You could save the above to a text file called (say) ogr_transform.sh and run it with the command "sh ogr_transform.sh". The EPSG codes for source and target CRSs would need editing to meet your needs. In the "$f-32630.shp" statement the "-32630" specifies the text that will be added to the original file name when renaming, you'll probably want to change this too.

The script assumes that all of the files to be transformed have a single CRS. It is possible that dropping the source CRS definition (-s_srs "EPSG:27700") might make ogr read the CRSs of the input shapefiles from their *.prj files, so it might be possible to use the script to transform input shapefiles having differing CRSs to a new CRS. Please note that I have not tested this.

An afterthought: The shell script doesn't have to be run from a terminal. If in the file manager you right-click on the *.sh file and go "Properties" then click the "Permissions" tab you can enable "Allow this file to run as a program". Doing this will allow the script to be run by double-clicking on it in the file manager. Just for your 'regular' users :)

Nick.

enter image description here

share|improve this answer
    
Nice script idea. I used something similar the other day to upload a whole bunch of .GPX tracks to a spatialite file. I will test the idea of dropping the input CRS and see if OGR deals with the transform anyway! –  Simbamangu Oct 24 '13 at 13:55

For rasters use the "warp" tool in the raster menu, it works also in batch mode. For vectors just use the "save as..." Dialog.

share|improve this answer
1  
For vector layers, ogr2ogr can transform from one crs to another using -t_srs. Batch processing should be possible on operating system level. –  Andre Joost Aug 24 '12 at 12:56
    
@Giovanni Manghi - nice, hadn't realised that the 'warp' tool worked on whole directories; this will, however, not help when there are a mix of source SRSs. I have tried the 'save as' dialogue but it seems to only work for a single vector at a time? –  Simbamangu Aug 24 '12 at 13:05
1  
If you need it should not be hard to make a plugin to do this task (convert a set of set of vectors and rasters with mixed crs to copies with the same crs and add them to the qgis project). If you want drop me a line privately. –  Giovanni Manghi Aug 24 '12 at 15:53
1  
Wouldn't it be good to add this feature to the Qconsolidate plugin? –  Andre Joost Aug 25 '12 at 5:06

I wouldnt worry about creating a plugin for this task - I agree with Andree.

This is a good time to get familiar with OGR - specifically ogr2ogr. You can re-project, rename, migrate and a whole lot more with a simple command line.

http://www.gdal.org/ogr2ogr.html

Here is an example: ogr2ogr -t_srs EPSG:(code) (output).shp (input).shp

share|improve this answer
1  
I'm familiar with it - and tend to do a lot of my work in R or the command line - but am always looking for solutions that will make things convenient for 'regular' users (writing a manual on using QGIS for field science work). –  Simbamangu Aug 25 '12 at 5:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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