ogr2ogr – A simple command line tool to transform your GIS data.

ogr2ogr by GDAL project is a command line tool for GIS data processing to “Convert simple features data between different file formats”. It can performs various operations like

  1. Converting data between different formats like shapefiles to GeoJSON, GeoJSON to shapefiles etc.
  2. Transforming data from one projection to another projection
  3. Doing spatial selection on data
  4. Exporting shapefiles, geojson etc. to SQL and vice versa

Lets start using ogr2ogr tool to transform our data. First, we will simply type ogr2ogr in command prompt to see what it displays. It will show various parameters that can be used to process our data.

For starters, we will use ogr2ogr –long-usage to get extra information. This command will display information on how to use this tool, what are various supported formats and information on arguments that can be used with ogr2ogr

We will start with basic commands like to convert Shapefile to GeoJSON. We will use follwing command to do this. Argument -f is used to specify format_name for our output data. In our case, it is GeoJSON. output.geojson is output file and input.shp is input file. Please kep in mind the order of file name. First is your output file name and second is your input file name

To tranform the data from one projection to another projection system, use following command. Arguments -s_srs is the current projection of your input data and -t_srs is the target projection system to which you want to transform your data. output_3857.shp is outpu file name and input.shp is input file name

To clip you data use following command is used. Argument -spat is used to specify spatial extent which will clip your data. It will return those features which intersects with extent.

To import your shape file to postgis, use following command. Argument -f PosgreSQL specify the output data format, in our case it is postgis table. Argument -nln specify the schem and table name where shape file will be imported. PG:”host=localhost user=postgres dbname=postgres password=admin” is used to specify the database details

To know more about ogr2ogr tool, click on following link.

Leave a ReplyCancel reply