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

Enhance methods of Point returning coordinate values as String #37

Closed
navispatial opened this issue Oct 28, 2021 · 1 comment
Closed
Labels
enhancement New feature or request 🌐 geocore Related to the code package "geocore"

Comments

@navispatial
Copy link
Member

Goal: Enhance methods of Point returning coordinate values as String
Need from entity classes with point geometries - making json element serialization easier.

Point and Bounds classes, new optional parameter fractionDigits, see method definitions updated:

  /// Writes coordinate values to [buffer] delimited by [delimiter].
  ///
  /// Use [fractionDigits] to set a number of decimals to nums with decimals.
  void writeValues(
    StringSink buffer, {
    String delimiter = ',',
    int? fractionDigits,
  });

  /// Returns coordinate values as a string delimimited by [delimiter].
  ///
  /// Use [fractionDigits] to set a number of decimals to nums with decimals.
  String valuesAsString({
    String delimiter = ',',
    int? fractionDigits,
  });

Point class, new method:

  /// Returns WKT coords (ie. "35 10" for a point with x=35 and y=10).
  /// 
  /// Use [fractionDigits] to set a number of decimals to nums with decimals.
  String toWktCoords({int? fractionDigits}) =>
      valuesAsString(delimiter: ' ', fractionDigits: fractionDigits);

Also internal utility function:

/// Uses `String.toStringAsFixed()` when [n] contains decimals.
/// 
/// For example returns '15' if a double value is 15.00, and '15.50' if a double
/// value is 15.50.
/// 
/// See: https://stackoverflow.com/questions/39958472/dart-numberformat
String toStringAsFixedWhenDecimals(num n, int fractionDigits) =>
    n.toStringAsFixed(n.truncateToDouble() == n ? 0 : fractionDigits);
@navispatial navispatial added enhancement New feature or request 🌐 geocore Related to the code package "geocore" labels Oct 28, 2021
navispatial added a commit that referenced this issue Oct 28, 2021
[Enhance methods of Point returning coordinate values as String #37](#37)
@navispatial
Copy link
Member Author

Applied on the repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 🌐 geocore Related to the code package "geocore"
Projects
None yet
Development

No branches or pull requests

1 participant