dartclub / turf_dart

A turf.js-like geospatial analysis library working with GeoJSON, written in pure Dart.
https://pub.dev/packages/turf
MIT License
63 stars 29 forks source link

implement a getGeom() in invariants and refactor Boolean functions #105

Closed armantorkzaban closed 2 years ago

armantorkzaban commented 2 years ago

The point is to get the GeometryType out of a GeoJSONObject which can be either Feature or GeometryType. This happens in various boolean functions.

lukas-h commented 2 years ago

how should this function behave with GeometryObject, which can be a GeometryCollection or a concrete geometry type?

armantorkzaban commented 2 years ago

Suggestion:

/// Get Geometry or Geometries from [Feature] or [GeometryType]
/// Returns [List<GeometryType>] in case geojson is a [GeometryCollection] and a
/// [GeometryType] if geojson is a simple [GeometryType].
/// example:
/// ```dart
/// var feature = Feature(
///   geometry: Point(
///     coordinates: Position.of([110, 40])
///   ));
/// var geom = getGeom(feature)
/// //= Point(coordinates: Position.of([110, 40]))
getGeom(GeoJSONObject geojson) {
  if (geojson is Feature) {
    return (geojson).geometry;
  } else if (geojson is GeometryCollection) {
    return geojson.geometries;
  }
  return geojson;
}
lukas-h commented 2 years ago

This is incomplete. No return type specified, cases like FeatureCollection are not handled. Otherwise okay.

lukas-h commented 2 years ago

decided against implementation.