Importing a DBF containing X-Y Values into QGIS
Suppose you have a DBF (.dbf) file containing X and Y values that you want to import and save as a spatial layer.
QGIS doesn’t support direct import of a DBF file as a map layer, however, we can use some command line magic to convert it to a CSV file and then use the Delimited Text plugin to get the job done.
Your DBF file should have an id for each record and fields containing X and Y values. If it has additional fields that should be OK as well.
First convert the DBF to a comma delimited file using ogr2ogr:
ogr2ogr -f CSV my_csv my_data.dbf
If you don’t have ogr2ogr see http://www.gdal.org/index.html.
This will create my_data.csv in the my_csv directory. You are now ready to bring it into QGIS.
Here are the steps to import the CSV:
-
Start QGIS
-
If not already enabled, use the plugin manager to enable the Delimited Text plugin
-
Click on the Delimited Text icon in the Plugin toolbar or choose it from the Plugins menu
-
Browse to the location of your CSV file
-
Enter a name for the layer
-
Under Selected delimiters, check Comma
-
If your X and Y fields aren’t automatically determined, set them using the drop-down boxes
-
The sample text should show how the file is being parsed—if it looks right click OK, otherwise adjust the settings
-
The layer is added to QGIS
At this point the layer behaves pretty much like any other QGIS layer. To save it as a shapefile, right click on its name in the legend and choose Save as…