Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit GeoJSON to coordinate precision of 7 (not 15) #7

Open
nvkelso opened this issue Aug 9, 2017 · 0 comments
Open

Limit GeoJSON to coordinate precision of 7 (not 15) #7

nvkelso opened this issue Aug 9, 2017 · 0 comments

Comments

@nvkelso
Copy link
Member

nvkelso commented Aug 9, 2017

From a Twitter support request we're currently exporting too much precision in our GeoJSON files for Metro Extracts.

Reviewing the support request it looks like we export default of 15 coordinate precision now when 7 is plenty. This will result in smaller file sizes, a win for everyone – and the original OSM data is accurate to 7 decimal places so we're not loosing precision.

The 15 precision is coming from OGR's GeoJSON driver defaulting to 15. But it's possible to set that to 7 two different ways:

COORDINATE_PRECISION = int_number: (OGR >= 1.9.0) Maximum number of figures after decimal separator to write in coordinates. Default to 15 for GeoJSON 2008, and 7 for RFC 7946. "Smart" truncation will occur to remove trailing zeros.
SIGNIFICANT_FIGURES = int_number: (OGR >= 2.1) Maximum number of significant figures when writing floating-point numbers. Default to 17. If explicitly specified, and > COORDINATE_PRECISION is not, this will also apply to coordinates.
RFC7946=YES/NO. (OGR >= 2.2) Whether to use RFC 7946 standard. Otherwise GeoJSON 2008 initial version will be used. Default is NO (thus GeoJSON 2008)

If we're using a newer OGR >= 2.2 then we should just say RFC7946=YES. If not then set one of the other flags (I think COORDINATE_PRECISION=7 but verify).

The code would need to be changed here for OSM2PGSQL:

# generate geojson from shp files
#
if [ ${geojson} == 'true' ]; then
ogr2ogr -lco ENCODING="UTF-8" -f GeoJSON -t_srs epsg:4326 shp/${slug}_osm_line.geojson shp/${slug}_osm_line.shp
ogr2ogr -lco ENCODING="UTF-8" -f GeoJSON -t_srs epsg:4326 shp/${slug}_osm_point.geojson shp/${slug}_osm_point.shp
ogr2ogr -lco ENCODING="UTF-8" -f GeoJSON -t_srs epsg:4326 shp/${slug}_osm_polygon.geojson shp/${slug}_osm_polygon.shp
zip -j shp/${slug}.osm2pgsql-geojson.zip shp/${slug}_osm_*.geojson
fi

And here for IMPOSM:

if [ ${geojson} == 'true' ]; then
for i in ${arr[@]}; do
ogr2ogr -lco ENCODING="UTF-8" -f GeoJSON -s_srs epsg:4326 -t_srs epsg:4326 ${tmpdir}/${slug}_${i}.geojson ${tmpdir}/${slug}_osm_${i}.shp
done
zip -j shp/${slug}.imposm-geojson.zip ${tmpdir}/${slug}_*.geojson
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant