spatial-k icon indicating copy to clipboard operation
spatial-k copied to clipboard

Feature Generics

Open elcolto opened this issue 9 months ago • 0 comments

This is a proposal to add a generic type parameter to Feature

These changes would lead to several questions. Which are partly already mentioned in https://github.com/dellisd/spatial-k/issues/76

  • Accessing features property in FeatureCollection and this class itself would always return a List<Feature<Geometry>>. This would lead to instances checks on each feature. (Could be handled with an exhaustive when)
  • This can cause flaws when a Geometry type in some cases of a FeatureCollection is probably known. For example you know, a function will return a FeatureCollection containing only LineStrings. This may lead to code like this:
featureCollection.forEach { feature ->
    when (feature.geometry) {
        is LineString -> { /* do something */ }
        null -> { /* nothing */ }
        else -> error("type is not applicable in this case")
    }
}

On the other hand, a generic type parameter for containing geometries within containing features on FeatureCollection is misleading. It doesn't has a direct relation to the FeatureCollection itself and it doesn't match really match the case of polymorphic FeatureCollections. This would always be FeatureCollection<Geometry> which is kind of redundant to declare this every time for the most cases.

Please share some thoughts.

elcolto avatar May 06 '24 20:05 elcolto