ngageoint / elasticgeo

ElasticGeo provides a GeoTools data store that allows geospatial features from an Elasticsearch index to be published via OGC services using GeoServer.
GNU General Public License v3.0
168 stars 85 forks source link

geojson is being rounded #96

Closed albertwgchu closed 5 years ago

albertwgchu commented 5 years ago

Found an issue where geojson being sent to ElasticSearch is being rounded to 4 digits.

After taking a look at the code the issue is that GeometryJSON defaults to 4 decimal places if there's no value passed to the constructor.

This line is the issue:
FilterToElastic.java final String geoJson = new GeometryJSON().toString(currentGeometry);

// this will give 8 decimal places FilterToElastic.java final String geoJson = new GeometryJSON(8).toString(currentGeometry);

Geoserver has a setting for "Maximum number of decimals", does it make sense to use this value?

sjudeng commented 5 years ago

Thank you for reporting this issue and taking the time to track down the cause. Definitely a bug.

It looks like "max number of decimals" refers to precision in GML output? Here it's the precision of the serialized geometry that's used when making queries, so it's a little different. How about instead we use the JTS PecisionModel for floats (e.g. 16)? It's what JTS uses when serializing to WKT so it seems reasonable here.

final PrecisionModel precisionModel = new PrecisionModel(PrecisionModel.FLOATING);
final int decimalPlaces = precisionModel.getMaximumSignificantDigits();
final String geoJson = new GeometryJSON(decimalPlaces).toString(currentGeometry);
albertwgchu commented 5 years ago

That sounds great to me. We noticed this bug when making wfs requests at low zooms. Will it be included in the next release?

sjudeng commented 5 years ago

Yes we'll make sure to get this fixed in the next release. Thanks again for reporting.

sjudeng commented 5 years ago

This fix is included in the new release candidate 2.14.2-RC1.