spatial-k
spatial-k copied to clipboard
Feature Generics
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 inFeatureCollection
and this class itself would always return aList<Feature<Geometry>>
. This would lead to instances checks on each feature. (Could be handled with an exhaustivewhen
) - This can cause flaws when a
Geometry
type in some cases of aFeatureCollection
is probably known. For example you know, a function will return a FeatureCollection containing onlyLineString
s. 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.