I have a 2MB shapefile that when converted to GeoJSON becomes 10MB:
$ ogr2ogr -f "GeoJSON" -t_srs EPSG:900913
landfill.geojson Authorised_Landfill_Sites_010k.shp
I can reduce the size of the GeoJSON a bit by adding -lco COORDINATE_PRECISION=4
to the command.
However, I've noticed that there are an awful lot of properties in the GeoJSON that I don't need, so I'd like to remove them completely:
{ "type": "Feature", "properties": { "LIC_ADMIN": null, "LIC_NMBR": null, "LIC_IPPCR": "HP3532LV", "LIC_WML": 0.000000, "CUST_NMBR": 0.000000, "STATUS": "Ef fective", "LIC_LTYPE": "5.2 A(1) a)", "LIC_NAME": "Yorwaste Limited", "LIC_SITE": "HAREWOOD WHIN LANDFILL", "SITE_NAME": "HAREWOOD WHIN LANDFILL", "SITE_BUI LD": null, "SITE_STRT": "Harewood Whin Landfill", "SITE_AREA": "Tinker Lane", "SITE_TOWN": null, "SITE_CNTY": "Rufforth", "SITE_PCODE": "YO23 3RR", "TYPE_DE SC": "WASTE LANDFILLING; >10 T\/D WITH CAPACITY >25,000T EXCLUDING INERT WASTE", "NGR": null, "T_REF": "NE4731", "CTROID_X": 453600.000000, "CTROID_Y": 4513 00.000000, "REGION": "North East", "AREA": "Yorkshire", "DATE_ISSUE": "2007\/06\/21", "LIC_EPR": "EA\\EPR\\BK0507IB" }, "geometry": { "type": "Polygon", "co ordinates": [ [ [ -131830.27, 7161699.84 ]
Can I use ogr2ogr to remove these properties at the time of conversion, and just keep the coordinates, or should I post-process the GeoJSON to do this?
Best Answer
There are couple of alternatives. First one it to use the -select option that is documented on the manual page http://www.gdal.org/ogr2ogr.html
Another way which gives more freedom because you can also rename the fields and much more is to use the -sql parameter. GDAL supports two dialects: OGR SQL http://www.gdal.org/ogr_sql.html and SQLite SQL http://www.gdal.org/ogr_sql_sqlite.html. SQLite dialect has more features but for your need OGR SQL works as well. The syntax is like: