ogrmerge

Along with the installation of GDAL comes a set of Python scripts that can be used for specialized geospatial tasks. These scripts can be run directly from a Jupyter Notebook or terminal, along with a specified dataset. You can find all of the scripts inside of the scripts directory of your local gdal file folder, which on a Windows machine might be similar to the following path:

C:UsersUsernameAnaconda3pkgsgdal-2.2.2-py36_1scripts

As you can see from the list of Python scripts in this folder, almost all of them are for GDAL rather than OGR. All of these Python scripts can be run from a Jupyter Notebook or a terminal. Using a Jupyter Notebook, you can use the magic command %run to execute your Python script, whereas using a terminal you'd use python followed by the name of the script and the input/output data files.

Magic commands are commands that extend the core Python language and can only be used in the Jupyter Notebook application. They offer useful shortcuts, for example, inserting code from an external script, and executing Python code from .py files on disc or shell commands. A full list of magic commands can be printed with the following command in an empty cell, %lsmagic. 

The following example uses ogrmerge.py, a Python script available with GDAL version 2.2.2 and higher. Running this script from a Jupyter Notebook, it takes all shapefiles in a single folder from the Earth dataset and merges them into a single GeoPackage file called merged.gpkg:

In: %run "C:UsersEricAnaconda3pkgsgdal-2.2.2-                        
py36_1Scriptsogrmerge.py" -f GPKG -o
merged.gpkg "C:datagdalNE10m_cultural*.shp"

Please note that in order to run one of the Python scripts in the GDAL directory correctly, you need to reference their file location if it's located in a different folder than the one where you're running the script, which is likely to be the case if you're working with the Jupyter Notebook application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset