twpayne / go-geom

Package geom implements efficient geometry types for geospatial applications.
BSD 2-Clause "Simplified" License
839 stars 104 forks source link

Unified Encoding Interface #243

Closed TuSKan closed 6 months ago

TuSKan commented 6 months ago

I have a suggestion of an unified encoding interface to deal with many different file formats.

type Decoder interface {
    Decode() (*FeatureCollection, error)
}

type Encoder interface {
    Encode(*FeatureCollection) error
}

type NewDecoder func(r io.reader, opts Opts) Decoder

type NewEncoder func(r io.writer, opts Opts) Encoder

The FeatureCollection is a new struct to handle geo properties as go map[string] any.

This new encoding interface will allow to work with many file formats in a very dynamic way using a clean code.

What do you think about that?

I already have a wrapper code with this concept using existing encoding. I'll happy to submit a PR.

twpayne commented 6 months ago

For me, this would be a separate layer on top of go-geom. go-geom deliberately avoids such an interface because different formats contain very different data. For example, EWKB only contains a geometry (not a feature), an IGC file contains a single geometry with complex properties, a KML file contains multiple features and a lot of extra structure, GeoJSON can be either a geometry, a single feature, or multiple features, and so on.

Note that the only use of features in go-geom is in the GeoJSON library. go-geom focuses on geometries, not features.

Therefore I do not think this should be part of go-geom.

TuSKan commented 6 months ago

Ok. I understand. No problem, tks