2

I have a very large JSON file made up vector polygons, I want to use GDAL ogr2ogr to clip the JSON polygons and convert the AOI into a shapefile.

I see this can be done by ogr2ogr -f "ESRI Shapefile" <output>.shp <input>.json -clipsrc llx lly urx ury

However I do not know how to use GDAL commands... is it done via CMD or python terminal?

I have QGIS 3.0.3 installed, and GDAL downloaded as a .zip (extracted now) on my desktop.

can someone explain to process to execute this command?

2 Answers 2

4

You need to use the CMD to use ogr2ogr. Normally, if you have QGIS, you should already have ogr2ogr (you can assess this typing ogr2ogr in CMD terminal)

You can also use "Clip vector by extent" within QGIS Processing Toolbox if you prefer to not use command line (or are a bit afraid of it)

4
  • 5
    You may need to use the osgeo cmd window
    – Ian Turton
    Commented Jul 3, 2018 at 7:14
  • Yes, some GDAL directories must ne added to%PATH% before running the utility. In osgeo cmd they are set for you.
    – user30184
    Commented Jul 3, 2018 at 9:12
  • got an error saying no driver available......
    – NULL.Dude
    Commented Jul 3, 2018 at 11:33
  • Please add your command line and the full error message to your question.
    – AndreJ
    Commented Mar 6, 2019 at 6:55
3

Create a .bat like this - change the paths to suit your install. If at all changes will be in the OSGEO root and python path.

@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass-7.4.0\etc\env.bat

path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-7.4.0\lib
path %PATH%;C:\OSGeo4W64\apps\Qt5\bin
path %PATH%;C:\OSGeo4W64\apps\Python37\Scripts

set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37

Cmd.exe

When you run this you can now type in ogr2ogr and get it's usage rather than unrecognised command.

2
  • Couldn't apply it. After creating the .bat file and running it, I open the CMD and just type "ogr2ogr", doesn't work. Am I missing something?
    – Eric Lino
    Commented Nov 3, 2023 at 20:53
  • Have you changed the paths to match your install?
    – GeorgeC
    Commented Nov 20, 2023 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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