Sunday 9 April 2017

coordinate system - Is there any way to reproject multiple layers in QGIS?


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?



Answer



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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...