-6

I want to code in python or any other language to create a software to convert the following files to each other:

  • GeoJSON File;
  • Tiff File;
  • Shapefile;
  • KML/KMZ File;
  • Grid netCDF File;
  • ESRI Grid File; and
  • Well Known Text File.

I am new to GIS and python field I have no idea about how to proceed.

We are planning to use QGIS to implement this conversion.

  • 2
    Welcome to SE. This type of question is very open ended. Please have a look at this link for a guide as to how SE works:gis.stackexchange.com/tour . In your case, many of the questions you have can be answered by searching for similar questions on this site. – Keagan Allan Feb 14 '18 at 10:42
  • 3
    look at gdal and ogr which have python bindings – Ian Turton Feb 14 '18 at 10:44
  • 1
    QGIS comes with GDAL which can do conversions for these raster formats gdal.org/formats_list.html and these vector formats gdal.org/ogr_formats.html. I would say that you could spend your time better for developing something fancy that does not exist yet but it is your choice. At least you can study the source code of GDAL for speeding up your own work. Of the formats that you listed netCDF is most complicated and you could consider to improve the GDAL driver gdal.org/frmt_netcdf.html. – user30184 Feb 14 '18 at 10:49
5

You can use the gdal and ogr command lines utilities.

More info at:

For example, to convert between two vector layers (Shapefile to KML) you could use the following command line:

ogr2ogr -f KML output.kml input.shp

Another option is to call this same line from python in the following way:

import os
import subprocess

os.chdir(r"directory with the files")

result = subprocess.call('ogr2ogr -f KML output.kml input.shp')

In the case of raster files you can use the gdal_translate utility. For example to convert a GeoTIFF to a NetCDF file you can use:

gdal_translate -of NetCDF input.tif output.nc

or calling it form python:

import os
import subprocess

os.chdir(r"directory with the files")

result = subprocess.call('gdal_translate -of NetCDF input.tif output.nc')

Note: be aware that the are multiple creations options for each one of these utilities and that not every format support the same things. You should check out the documentation for the ogr2ogr and gdal_translate utilities.

  • os.chdir(r"directory with the files") is showing error. – bindhiya Feb 20 '18 at 11:33
  • @bindhiya can you paste here the exact line you wrote? – Marcelo Villa Feb 20 '18 at 16:40

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