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

Add possibility to overwrite WKTWriter NumberFormat #167

Merged
merged 1 commit into from
Sep 4, 2018

Conversation

MoeweX
Copy link
Contributor

@MoeweX MoeweX commented Sep 3, 2018

Because of #140 , it can be necessary to extend a writer to customize the used NumberFormat until a more general (configuration) solution is available.

This pull requests aims to simplify the customize procedure. E.g., find below how I overwrite the WKTWriter so that it does not round the written values at all:

public class WKTWriter extends JtsWKTWriter {

	public WKTWriter(JtsSpatialContext ctx, JtsSpatialContextFactory factory) {
		super(ctx, factory);
	}

	/**
	 * Same as {@link org.locationtech.spatial4j.io.LegacyShapeWriter#makeNumberFormat(int)}, 
	 * but does not remove fraction digits
	 */
	@Override
	protected NumberFormat getNumberFormat() {
		NumberFormat nf = NumberFormat.getInstance(Locale.ROOT);//not thread-safe
		nf.setGroupingUsed(false);
		nf.setMaximumFractionDigits(20); // maximum double is ~16, so we are fine with 20
		nf.setMinimumFractionDigits(0);
		return nf;
	}
}

The new writer can be added like so:

public static final JtsSpatialContext GEO;
static {
	JtsSpatialContextFactory factory = new JtsSpatialContextFactory();
	factory.geo = true;
	factory.writers.clear();
	factory.writers.add(WKTWriter.class);
	GEO = new JtsSpatialContext(factory);
}

@codecov-io
Copy link

codecov-io commented Sep 3, 2018

Codecov Report

Merging #167 into master will increase coverage by 0.84%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #167      +/-   ##
============================================
+ Coverage     74.21%   75.05%   +0.84%     
- Complexity     1085     1093       +8     
============================================
  Files            57       57              
  Lines          3804     3805       +1     
  Branches        772      772              
============================================
+ Hits           2823     2856      +33     
+ Misses          700      671      -29     
+ Partials        281      278       -3
Impacted Files Coverage Δ Complexity Δ
.../java/org/locationtech/spatial4j/io/WKTWriter.java 100% <100%> (ø) 17 <13> (+1) ⬆️
...ationtech/spatial4j/shape/jts/JtsShapeFactory.java 87.93% <0%> (+1%) 55% <0%> (+1%) ⬆️
...ava/org/locationtech/spatial4j/io/BinaryCodec.java 77.63% <0%> (+2.63%) 29% <0%> (+1%) ⬆️
.../locationtech/spatial4j/io/jts/JtsBinaryCodec.java 79.16% <0%> (+58.33%) 12% <0%> (+5%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd860ad...443ca3a. Read the comment docs.

@dsmiley dsmiley merged commit a6173aa into locationtech:master Sep 4, 2018
@dsmiley
Copy link
Contributor

dsmiley commented Sep 4, 2018

Nice simple change; thanks!

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

Successfully merging this pull request may close these issues.

3 participants