1

I have a set of shapes that I produced from a spatial merge. It has 1.6 million postcode polygons, however when I save it in QGIS to .csv it only saves two thirds of the data. I'm not sure why this happens.

As an alternate plan I've been trying to open the .dbf directly in Python although I haven't been successful yet. It's too large to open in Excel.

Why would only part of my data be written to the .csv in QGIS? Is there an alternate way to extract the .dbf data and convert it to .csv?

  • You may try ogr2ogr to convert shp to cvs: "ogr2ogr -f CSV output.csv input.shp -lco GEOMETRY=AS_XYZ" -lco is optional. Which version of QGIS do you use? Were there any error messages? – Zoltan Feb 21 '17 at 16:38
  • No error message. Using QGIS 2.18.2. It writes over 1 million postcodes, but misses out about 500,000. Any ideas? I'll try the syntax now. – Thirst for Knowledge Feb 21 '17 at 17:09
  • FME would be able to do this fairly quickly. There's a 30 day trial period if it's a one-off project and you want to give it a go (see safe.com). After installation, start Workbench, hit generate, pick the source and destination formats, and click OK. Then click Run. It would convert Shape to CSV or DBF to CSV (which would probably be quicker). [disclaimer: I do work for the company that makes FME] – Mark Ireland Feb 21 '17 at 18:37
1

I've had luck using a combination of dbfread and pandas to do exactly what you're looking for. (using Python 3.5.1)

from dbfread import DBF
import pandas as pd

table = DBF('/Path/to/Shapefile.dbf')
csvPath = '/Export/path/GIS_SE.csv'

frame = pd.DataFrame(iter(table))

frame.to_csv(csvPath)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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