How to use Python scripting in QGIS to extract data from a shapefile and save it to a text file, as well as how to create a shapefile from a text file.
-
Download the airports shapefile: Download the airports shapefile from Natural Earth.
-
Load the shapefile in QGIS: Open QGIS and load the airports shapefile.
-
Execute the Python script: Open the Python console (Plugins -> Python Console) and execute the provided Python script
readData.py. -
Check the output file: Check the root directory for the generated
airports.txtfile containing airport data.
-
Prepare the input text file: Create a text file named
airports.txtwith each line containing airport data in the formatname,iata_code,latitude,longitude. For example: -
Execute the Python script: Open new python file in the console and run
writeData.py. This script will read data from theairports.txtfile and create a new shapefile containing airport points. -
Check the output shapefile: Check the root directory for the generated shapefile named
airports.shp.