Tuesday 30 April 2019

shapefile - Join and export .csv file as .shp in QGIS?


Here's what I'm trying to achieve:



  1. Load the required GIS layer (*.shp file)

  2. Load the .csv file in QGIS

  3. Perform the join based on common attributes in the two files


  4. Export the mapped .csv file as a .shp file


This is where I'm having trouble. The error that I'm getting is


"Invalid Data Source: C:/GIS Projects/Services.shp is not a valid or recognized data source"

I am so used to doing this easily in ArcGIS and MapInfo I don't understand why I cannot get this to work on QGIS. I have write permissions and everything and I can see 3/4 files being created in the specified folder just the .shp file is missing in the output folder.



Answer



You don't want to export csv, you should Save as... the shapefile which you joined the csv to. If you export csv table (which was not loaded with points geometry), there won't be any geometry and thus no shapefile.


So it should go like this:




  1. drag and drop shapefile and csv into QGIS

  2. Double click on shapefile in layers list, switch to joins tab

  3. join csv to shapefile table through common attribute

  4. right click on shapefile and Open attribute table to make sure it is joined as expected (now actually this might cause potentionally troubles because shapefiles/respectively dbf tables have only 10 characters limitation for column names and also limit for absolute length - good idea is rename csv to some very short name - only one character or so before starting the whole operation, or use the custom field name prefix when doing join)

  5. once all look good right click and Save as... on shapefile, by default QGIS will automatically load the new file after save

    • If you want to save only features with joined information from csv - meaning your csv has IDs only of some smaller subset of features:

    • Select only the ones joined through expression: "joined_column_name" is not NULL

    • Then click on Save as... and check Save only selected features





enter image description here


(If you try to save csv it will create only dbf (and projection files proj, qpj)) but won't create shapefile because csv is only table, which can be joined to shapefile but not the other way around - thus it will come up with error because there won't be any shp to load)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...