1

I am using OL3 and I try to inspect whether two lines are intersecting or not using turf. I used GeoJSON in OL3 and fed the lines into the intersect() in turf but I get Unknown GeoJSON type. here is my code:

lineStringdraw.on('drawend', function(e2) {
var featureEnd = e2.feature;
checkIntersection(featureEnd);
});

function checkIntersection(currentFeature){
var features = vectorLayer.getSource().getFeatures();
var geoJSON = new ol.format.GeoJSON();
geoJSON = geoJSON.writeFeature(currentFeature);
for (i=0; (features.length)>i;i++){
var feature = features[i];
geoJSON_i = geoJSON.writeFeature(feature);
var intersectionStatus = turf.intersect(geoJSON,geoJSON_i);
$('#infoList').append(intersectionStatus);
}
}

here is piece of the OL3 GeoJSON:

{"type":"Feature","geometry":{"type":"LineString","coordinates":[[-8236104.129670544,4977029.890789877],[-8236634.411554272,4974407.145256842]]},"properties":null}

Does anyone know why it is not working or what I am missing?

2

Turf follows the GeoJSON specification. One aspect of this specification is that geometries should use WGS 84 coordinates. Each coordinate should look like: [longitude, latitude]. Your sample data is not valid WGS 84 lon/lat.

A trick I use with sample datasets is to copy and paste them into http://geojson.io . If the feature does not render normally (it does not with your sample data), there is likely a data problem.

1

turf.intersect Takes two polygons and finds their intersection. (not linestrings) If they share a border, returns the border; if they don't intersect, returns undefined. here is the doc turf.intersect

  • 1
    It does check lineString and I have already implement it. the problem was that the GeoJSON produced by OL3 is not compatible with the GeoJSON in turf, which is weird. I worked around this problem by extracting the coordinates by OL3 and creating GeoJSON using turf. Now it is working. I will add my solution soon. but the question remains: why GeoJSONs are not compatible? – msc87 Nov 3 '15 at 12:13

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.