and so on. The only difference between each is how the "coordinates" are defined.
Nim will allow me to combine these into one seq (defined as seq[Feature]) without problems, and I can set the "featureType" and "properties" fields without issue. However, I can't set the "coordinates".
If I leave the code as-is, I get the error "undeclared field: 'coordinates'", However, if I try to defined it in Feature first, I get the error "redefinition of 'coordinates'".
Is there any way to allow redefinitions? I'm not much experienced with OOP in Nim, so apologies if this is a stupid question.
If Feature type by itself is not used (is abstract), you can just make it generic.
type
Feature*[T] = ref object of RootObj
featureType* : string
properties* : seq[tuple[key: string, val: string]]
coordinates*: T
Point* = Feature[seq[float]]
MultiPoint* = Feature[seq[seq[float]]]
# testing
import typetraits
proc test(f: Feature) =
echo f.type.name, ": ", f.featureType, " at ", f.coordinates
test(Point(
featureType: "xxx",
properties: @[("x","y")],
coordinates: @[1.0,2.0,3.0]))
var m = MultiPoint(
featureType: "yyy",
properties: @[("a","b"), ("c","d")],
coordinates: @[@[1.0,2.0,3.0], @[4.0,5.0,6.0]])
test(m)