6

I am trying to run a GDAL 300 command line command to convert a file to GeoJSONSeq, projecting output using ESRI:102008 (Albers North America), using a SQL query to choose and rename some columns, and applying the following Layer Creation Options:

COORDINATE_PRECISION=4
ID_FIELD=ZCTA5CE10
ID_TYPE=String

(I'm not sure if this is necessary - I added it because ID_FIELD wasn't working)

It just seems to be ignoring all of the -lco settings. Here's the full command:

ogr2ogr -a_srs ESRI:102008 -f GeoJSONseq -sql "SELECT ZCTA5CE10 as zip, INTPTLAT10 as lat, INTPTLON10 as lon FROM tl_2018_us_zcta510" -lco "COORDINATE_PRECISION=4" -lco "ID_FIELD=ZCTA5CE10" -lco "ID_TYPE=String" albers_gjs4.geojson albers.shp

What is the correct syntax?

I've tried it with and without the double-quotes (single-quotes definitely don't work in my environment - Windows), I've moved the -lco statements from before the -sql to after. I've poured over all the documentation (https://gdal.org/programs/ogr2ogr.html) for both ogr2ogr and the GeoJSONSeq driver and I haven't been able to figure out what is the right way to specify these options.

Edit - And to clarify the Coordinate Precision option, I am hoping to limit the number of decimals it outputs for the coordinates in order to try to reduce the file size somewhat. Is there any other way to do that? The other utilities I'm trying to use to manipulate this down the line are choking because some string length exceeds the max that node.js will handle.

2
  • Hi, have u tried using ID_FIELD=zip ?
    – vagvaf
    Jul 10, 2019 at 4:50
  • I have run into this exact problem with ID_FIELD. I can't make it work either. Jan 16, 2020 at 20:01

1 Answer 1

1

I made a test with GDAL 3.6.2 and the syntax that you used works for me. I used this GeoJSON as source data:

{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "ZCTA5CE10":"foo", "INTPTLAT10":40.0001, "INTPTLon10":60.00002 }, "geometry": {"type":"Point","coordinates":[60.00000001,40]} }
]

}

I edited your command a bit by changing -a_srs into -t_srs. This GDAL version warns that GeoJSONseq driver does not support other coordinate systems than WGS84 lon-lat.

ogr2ogr -t_srs ESRI:102008 -f GeoJSONseq -sql "SELECT ZCTA5CE10 as zip, INTPTLAT10 as lat, INTPTLON10 as lon FROM sql" -lco "COORDINATE_PRECISION=4" -lco "ID_FIELD=zip" -lco "ID_TYPE=String" out.json sql.json
Warning 1: Target SRS North_America_Albers_Equal_Area_Conic not taken into account as target driver likely implements on-the-fly reprojection to WGS 84

This is the result

{ "type": "Feature", "id": "foo", "properties": { "lat": 40.0001, "lon": 60.00002 }, "geometry": { "type": "Point", "coordinates": [ 60.0, 40.0 ] } }

So, the "ZCTA5CE10" field is used as a string type id in the JSON, and the coordinates in the geometry are rounded. All the layer creation options had the desired effect. The "lat" and "lon" in the properties were not rounded, but if needed, they can be rounded as well with anothet option, -lco SIGNIFICANT_FIGURES=.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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