@@ -166,6 +166,26 @@ func checkForDeletion(mr *mapResponse, m map[string]interface{}, op int) {
166166 }
167167}
168168
169+ func handleGeoType (val map [string ]interface {}, nq * api.NQuad ) (bool , error ) {
170+ _ , hasType := val ["type" ]
171+ _ , hasCoordinates := val ["coordinates" ]
172+ if len (val ) == 2 && hasType && hasCoordinates {
173+ b , err := json .Marshal (val )
174+ if err != nil {
175+ return false , x .Errorf ("Error while trying to parse " +
176+ "value: %+v as geo val" , val )
177+ }
178+ ok , err := tryParseAsGeo (b , nq )
179+ if err != nil && ok {
180+ return true , err
181+ }
182+ if ok {
183+ return true , nil
184+ }
185+ }
186+ return false , nil
187+ }
188+
169189func tryParseAsGeo (b []byte , nq * api.NQuad ) (bool , error ) {
170190 var g geom.T
171191 err := geojson .Unmarshal (b , & g )
@@ -279,23 +299,13 @@ func mapToNquads(m map[string]interface{}, idx *int, op int, parentPred string)
279299 continue
280300 }
281301
282- // Geojson geometry should have type and coordinates.
283- _ , hasType := val ["type" ]
284- _ , hasCoordinates := val ["coordinates" ]
285- if len (val ) == 2 && hasType && hasCoordinates {
286- b , err := json .Marshal (val )
287- if err != nil {
288- return mr , x .Errorf ("Error while trying to parse " +
289- "value: %+v as geo val" , val )
290- }
291- ok , err := tryParseAsGeo (b , & nq )
292- if err != nil {
293- return mr , err
294- }
295- if ok {
296- mr .nquads = append (mr .nquads , & nq )
297- continue
298- }
302+ ok , err := handleGeoType (val , & nq )
303+ if err != nil {
304+ return mr , err
305+ }
306+ if ok {
307+ mr .nquads = append (mr .nquads , & nq )
308+ continue
299309 }
300310
301311 cr , err := mapToNquads (v .(map [string ]interface {}), idx , op , pred )
@@ -323,6 +333,16 @@ func mapToNquads(m map[string]interface{}, idx *int, op int, parentPred string)
323333 }
324334 mr .nquads = append (mr .nquads , & nq )
325335 case map [string ]interface {}:
336+ // map[string]interface{} can mean geojson or a connecting entity.
337+ ok , err := handleGeoType (item .(map [string ]interface {}), & nq )
338+ if err != nil {
339+ return mr , err
340+ }
341+ if ok {
342+ mr .nquads = append (mr .nquads , & nq )
343+ continue
344+ }
345+
326346 cr , err := mapToNquads (iv , idx , op , pred )
327347 if err != nil {
328348 return mr , err
0 commit comments