Skip to content

Instantly share code, notes, and snippets.

@pbogden
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save pbogden/213f3335190d9b117004 to your computer and use it in GitHub Desktop.

Select an option

Save pbogden/213f3335190d9b117004 to your computer and use it in GitHub Desktop.
csv processing

Processing csv data with gdal and friends

a b c LATITUDE LONGITUDE
1 2 3 48 -120
4 5 6 30 -90
SOURCE_DATA = test.csv
CLEAN_DATA = clean.csv
GENERATED_FILES = test.json
$(GENERATED_FILES): $(CLEAN_DATA)
@topojson -x 'LONGITUDE' -y 'LATITUDE' -o $@ $^
test: $(CLEAN_DATA)
ogrinfo -ro -al $(CLEAN_DATA)
info: $(GENERATED_FILES)
@echo "Here's the info..."
ogrinfo -ro -so test.vrt
ogrinfo -dialect SQLITE -sql 'SELECT LATITUDE FROM clean LIMIT 2 OFFSET 1' -ro -al test.vrt
$(CLEAN_DATA): $(SOURCE_DATA)
@echo Making $(CLEAN_DATA)
@sed 1d $^ > $@ # remove first line = column names (possibly created by ogr2ogr conversion of xlxs
clean:
-rm $(CLEAN_DATA)
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 5 in line 1.
this is the silly line that's causing me a headache
a,b,c,LATITUDE,LONGITUDE
1,2,3,48,-120
4,5,6,30,-90
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<OGRVRTDataSource>
<OGRVRTLayer name="clean">
<SrcDataSource>clean.csv</SrcDataSource>
<GeometryType>wkbPoint</GeometryType>
<LayerSRS>WGS84</LayerSRS>
<GeometryField encoding="PointFromColumns" x="LONGITUDE" y="LATITUDE"/>
</OGRVRTLayer>
</OGRVRTDataSource>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment