1

I'm trying to join attribute values from a geojson polygon to a geojson point geometry. I'm using Terraformer.js to create a geojson from a pair of coordinates and Turf.js to do the join. The current result is a point without the targeted attribute value.

Note: I've shortened my huge json file for this showcase, I've made sure the point lies within the json area.

 var jsondata = {  
"type":"FeatureCollection",
"bbox":[  
  10.77658211779599,
  52.03335512396914,
  10.783948303125767,
  52.038218143583215
],
"features":[  
  {  
     "type":"Feature",
     "geometry":{  
        "type":"Polygon",
        "coordinates":[  
           [  
              [  
                 10.781028778452377,
                 52.03807999691732
              ],
              [  
                 10.780983862688172,
                 52.03807999691732
              ],
              [  
                 10.780983862688172,
                 52.03810762628465
              ],
              [  
                 10.781028778452377,
                 52.03810762628465
              ],
              [  
                 10.781028778452377,
                 52.03807999691732
              ]
           ],
           [  
              [  
                 10.776627033560192,
                 52.03343802078045
              ],
              [  
                 10.77658211779599,
                 52.03343802078045
              ],
              [  
                 10.77658211779599,
                 52.03346565301674
              ],
              [  
                 10.776627033560192,
                 52.03346565301674
              ],
              [  
                 10.776627033560192,
                 52.03343802078045
              ]
           ]
        ]
     },

     "properties":{  
        "N2":"130",
        "Besch":"130 kg/ha",
        "speed":"5.1"
        }
    }
  ]
 }

and the code itself:

 var point = new Terraformer.Point({
            type:"Point",
            coordinates: [10.779996514320375,52.035835073466195]

 });

var point2=turf.featureCollection([point]);

var ptsWithin = turf.tag(point2, jsondata, 'speed', 'speed');
  • please edit your question to show the code you have tried already – Ian Turton Jun 22 '17 at 10:55
  • when you scroll down in the code frame, theres the code that returns no result – Revo Jun 22 '17 at 11:02
  • 1
    Try your geojson here. Your point sits mid way between your two polygons, so is not within either. – RoperMaps Jun 22 '17 at 13:45
  • If you want to merge Point with FeatureCollection, you can try to use geojson-merge provided by MapBox: github.com/mapbox/geojson-merge – Kyros Koh Oct 24 '18 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.