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

Simple geometry data structures on geobase #133

Closed
navispatial opened this issue Jul 6, 2022 · 2 comments
Closed

Simple geometry data structures on geobase #133

navispatial opened this issue Jul 6, 2022 · 2 comments
Labels
enhancement New feature or request 🌐 geobase Related to the code package "geobase"

Comments

@navispatial
Copy link
Member

geocore package has geometry classes (Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPoint, GeometryCollection). However internal data structures for these might be quite deep. When building these data structures when decoding data read from file formats, lot of object instantiation is needed.

geobase has Position (sub classes Projected and Geographic) and Box (sub classes ProjBox and GeoBox). However not yet classes for other simple geometry data structures.

Simple geometries can be written to a data format encoder or built from a data format decoder using content interfaces, for example a line string

  /// Writes a line string geometry with a position array from [coordinates].
  ///
  /// The [coordinates] iterable is an array containing `Object` items
  /// representing positions of points in a line string. Supported sub classes
  /// for items are [Position] and `Iterable<num>`.
  ///
  /// Use [name] to specify a name for a geometry (when applicable).
  ///
  /// Use [coordType] to define the type of coordinates.
  ///
  /// An optional [bbox] of [Box] or `Iterable<num>` can used set a minimum
  /// bounding box for a geometry written. A writer implementation may use it or
  /// ignore it.
  ///
  /// Known [Position] sub classes are [Projected] (projected or cartesian
  /// coordinates) and [Geographic] (geographic coordinates). Known [Box] sub
  /// classes are [ProjBox] (projected or cartesian coordinates) and [GeoBox]
  /// (geographic coordinates). Other sub classes are supported too.
  ///
  /// Allowed [coordinates] value combinations for `Iterable<num>` are:
  /// (x, y), (x, y, z) and (x, y, z, m).
  ///
  /// Allowed [bbox] coordinate value combinations for `Iterable<num>` are:
  /// - minX, minY, maxX, maxY
  /// - minX, minY, minZ, maxX, maxY, maxZ
  /// - minX, minY, minZ, minM, maxX, maxY, maxZ, maxM
  void lineString(
    Iterable<Object> coordinates, {
    String? name,
    Coords? coordType,
    Object? bbox,
  });

Actual line string data is deliver on Iterable<Object> coordinates that could be an iterable of Position objects or Iterable<num> objects (containing x, y and optionally z and m coordinate values).

The idea would be to implement a data structure class for line strings that takes and saves directly this data without object conversions and instantiations.

Other simple geometry classes in the same way.

@navispatial navispatial added enhancement New feature or request 🌐 geobase Related to the code package "geobase" labels Jul 6, 2022
@navispatial
Copy link
Member Author

First implementation in [c512dff].

For example Point:

/// A point geometry with a position.
class Point extends Geometry {
  final PositionCoords _position;

  /// A point geometry with [position].
  const Point(PositionCoords position) : _position = position;

  /// A point geometry from a [position].
  ///
  /// Use an optional [type] to explicitely specify the type of coordinates. If
  /// not provided and an iterable has 3 items, then xyz coordinates are
  /// assumed.
  ///
  /// Supported coordinate value combinations for `Iterable<double>` are:
  /// (x, y), (x, y, z), (x, y, m) and (x, y, z, m).
  ///
  /// An example to build a point geometry with 2D coordinates:
  /// ```dart
  ///    // using a coordinate value list (x, y)
  ///    Point.build([10, 20]);
  /// ```
  ///
  /// An example to build a point geometry with 3D coordinates:
  /// ```dart
  ///    // using a coordinate value list (x, y, z)
  ///    Point.build([10, 20, 30]);
  /// ```
  ///
  /// An example to build a point geometry with 2D coordinates with measurement:
  /// ```dart
  ///    // using a coordinate value list (x, y, m), need to specify type
  ///    Point.build([10, 20, 40], type: Coords.xym);
  /// ```
  ///
  /// An example to build a point geometry with 3D coordinates with measurement:
  /// ```dart
  ///    // using a coordinate value list (x, y, z, m)
  ///    Point.build([10, 20, 30, 40]);
  /// ```
  factory Point.build(
    Iterable<double> position, {
    Coords? type,
  }) {
    if (position is PositionCoords) {
      return Point(position);
    } else {
      return Point(
        PositionCoords.view(
          position is List<double>
              ? position
              : position.toList(growable: false),
          type: type ?? Coords.fromDimension(position.length),
        ),
      );
    }
  }

  @override
  Geom get type => Geom.point;

  /// The position in this point geometry.
  PositionCoords get position => _position;
}

@navispatial
Copy link
Member Author

Implemented in geobase 0.3.0-dev.2.

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

No branches or pull requests

1 participant