lunedì 19 gennaio 2015

How to reproject shapefile to import in GRASS

Here's a simple tutorial to make a CRS transformation of a shapefile before importing, to match the CRS of the location you have in GRASS.

Step 1 - See if you need coordinates conversion

Start GRASS 7, enter your location. In the Layer Manager, go to File -> Import vector data -> Common import formats.
Select Source type - Directory.
Browse the directory where the vector file you want to import is located.
A list of vector layers will load (can be one single vector). Under "Projection" you can see either "Yes" or "No". If you see "Yes", it means that the vector you want to import matches with the location projection, and you can proceed importing it immediately. Otherwise follow the steps listed below.

Step 2 - Export CRS information from GRASS location


Very easy. In GRASS, run the command

g.proj -wef > target.prj

This will export a text file called target.prj into your home folder.

Step 3 - Reproject shapefile and import in GRASS

The reprojection can be done using GDAL. The vector_source is the vector file that you want to reproject. The vector_target is the reprojected one. Pay attention to the order you put them in. When you are ready, shoot this command in the terminal:

ogr2ogr -t_srs target.prj -s_srs vector_source.prj  vector_target.shp vector_source.shp

Voila. You're done. You can now import your vector_target.shp file in the GRASS location.

Nessun commento:

Posta un commento