Skip to content

Commit d2c793d

Browse files
committed
new method to plug null into empty properties
1 parent 6114987 commit d2c793d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

geojson/feature_collection.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,27 @@ func FeatureCollectionFromMap(input map[string]interface{}) *FeatureCollection {
100100
}
101101
return result
102102
}
103+
104+
// FillProperties iterates through all features to ensure that all properties
105+
// are present on all features to meet the needs of some relational databases
106+
func (fc *FeatureCollection) FillProperties() {
107+
properties := make(map[string]bool)
108+
109+
// Loop 1: construct a set (actually a map)
110+
for _, feature := range fc.Features {
111+
for key := range feature.Properties {
112+
if _, ok := properties[key]; !ok {
113+
properties[key] = true
114+
}
115+
}
116+
}
117+
118+
// Loop 2: make sure each feature has each property from the set
119+
for _, feature := range fc.Features {
120+
for key := range properties {
121+
if _, ok := feature.Properties[key]; !ok {
122+
feature.Properties[key] = nil
123+
}
124+
}
125+
}
126+
}

0 commit comments

Comments
 (0)