That site seems to deliver an invalid shapefile that has duplicate field names in the attributes. The shapefile is also invalid for another reason according to the shapefile specification because the .dbf part is more than 6 GB in size while the standard allows only 2 GB. Technically the .dbf part is valid and GDAL can handle that but a workaround is needed for fixing the duplicate field names.
The error message that you got does not tell the real reason for the failure but I reused the CREATE TABLE part with spatialite-gui which prints a clear message:
SQL error: dublicate column name: date_bldg_
Next I verified that with ogrinfo:
ogrinfo -al -so geo_export_98941210-c995-4502-8ebb-93a09f29d615.shp
INFO: Open of `geo_export_98941210-c995-4502-8ebb-93a09f29d615.shp'
using driver `ESRI Shapefile' successful.
Layer name: geo_export_98941210-c995-4502-8ebb-93a09f29d615
Metadata:
DBF_DATE_LAST_UPDATE=1919-03-27
Geometry: Polygon
Feature Count: 820606
Extent: (-87.939814, 41.644595) - (-87.524208, 42.023000)
...
date_bldg_: Date (10.0) <==
time_bldg_: String (254.0)
bldg_condi: String (254.0)
date_bldg_: Date (10.0) <==
time_bldg_: String (254.0)
date_bldg_: Date (10.0) <==
time_bldg_: String (254.0)
The workaround is to let GDAL to convert all the data into some suitable format like GeoPackage or SpatiaLite. Because there seems to be some problem with GeoPackage and your workflow with current software versions you'd better use Spatialite as interim format for fixing the data.
ogr2ogr -f sqlite -dsco spatialite=yes fix.sqlite geo_export_98941210-c995-4502-8ebb-93a09f29d615.shp -nlt MULTIPOLYGON
Warning 1: Field 'date_bldg_' already exists. Renaming it as 'date_bldg_2'
Warning 1: Field 'time_bldg_' already exists. Renaming it as 'time_bldg_2'
Warning 1: Field 'date_bldg_' already exists. Renaming it as 'date_bldg_3'
Warning 1: Field 'time_bldg_' already exists. Renaming it as 'time_bldg_3'
Now your command will work with some changes:
- GDAL SQLite driver launders table names and changes dashes (SQL thinks they are minus operators!) into underscores so the new table name does not require escaping.
Test the command with a couple of features:
ogr2ogr -f csv -dialect sqlite -sql "select AsGeoJSON(geometry) AS geom, * from geo_export_98941210_c995_4502_8ebb_93a09f29d615 limit 2" chicago_building_footprints.csv fix.sqlite
Chect the result
geom,date_bldg_,time_bldg_,bldg_condi,date_bldg_2,time_bldg_2,date_bldg_3,time_bldg_3,bldg_id,bldg_name1,bldg_name2,bldg_sq_fo,bldg_statu,cdb_city_i,comments,date_condi,time_condi,create_use,date_demol,time_demol,date_edit_,time_edit_,edit_sourc,edit_useri,f_add1,footprint_,harris_str,label_hous,no_of_unit,no_stories,non_standa,orig_bldg_,pre_dir1,date_qc_da,time_qc_da,qc_source,qc_userid,shape_area,shape_len,st_name1,st_type1,stories,suf_dir1,t_add1,unit_name,vacancy_st,x_coord,y_coord,year_built,z_coord
"{""type"":""MultiPolygon"",""coordinates"":[[[[-87.6667306636366,41.70797603324222],[-87.66686799082457,41.70797682976895],[-87.66686709803042,41.70806327088081],[-87.66668398069386,41.70806358088658],[-87.66668285842598,41.70799496621002],[-87.66673046519738,41.70799524237777],[-87.6667306636366,41.70797603324222]]]]}",1998/04/01,08:00:00.000,SOUND,1998/04/01,08:00:00.000,,,729719,,,2196,ACTIVE,,,2003/03/01,08:00:00.000,,,,,,,,10203,AERIALS98,"02507416001000","10203",1,0,,729719,S,2003/06/16,07:00:00.000,PARCELS,DS06284,1506.25,164.007499438,WOOD,ST,2,,10203,,,1166255.28615297,1836900.51661469,1899,0
"{""type"":""MultiPolygon"",""coordinates"":[[[[-87.74054777420342,41.98823925861186],[-87.74054890043631,41.98831610197826],[-87.74039808424241,41.98831669519352],[-87.74039694545855,41.98824122386017],[-87.74054777420342,41.98823925861186]]]]}",1998/04/01,08:00:00.000,SOUND,1998/04/01,08:00:00.000,,,46828,,,1927,ACTIVE,,,2003/05/01,07:00:00.000,,,,,,,,5901,AERIALS98,"01303306018000","5901",1,0,,46828,N,2003/06/16,07:00:00.000,PARCELS,DS06284,1138.125,137.524250985,KILBOURN,AVE,2,,5901,,,1145426.86651843,1938878.05056531,1937,0
Looks perfect so remove limit 2 and run the command again.
Please contact the City of Chicago and ask them to stop delivering invalid shapefiles. I would recommend them to use GeoPackage format instead.
\"geo_export_98941210-c995-4502-8ebb-93a09f29d615\"– user30184 Mar 27 '19 at 05:19"select AsGeoJSON(geometry) AS geom, * from \"geo_export_98941210-c995-4502-8ebb-93a09f29d615\""and the error is the sameno such table: geo_export_98941210-c995-4502-8ebb-93a09f29d615– Rohit Namjoshi Mar 27 '19 at 18:20