GeoJSON – Troubleshooting Turf.js Point Never Found Inside or Within Features Loop

geojsonjqueryloopturf

I have a GeoJSON http://radikal.com.mx/distrito.json and all I am trying to do is find if a turf point that has a longitude and latitude is inside or within that GeoJSON. No matter what point I use I always get false.

This is based on the work from: Bill Chappell

Here is my Javascript:

// FILE: js/get-data.js
$(function() {
  var cluster = [];
  var features = [];
  var point = turf.point([-98.768159, 20.098287]); // Hgo | This should return one TRUE at least
  // var point = turf.point([-79.601038, 43.6565353]); // Toronto | This should always be FALSE
  var url = 'http://radikal.com.mx/distrito.json';

  $.getJSON(url, function(data)
  {
    features = data.features;

    for (var i = 0, len = features.length; i < len; i++)
    {
      // Get coordinates
      var is_inside = turf.inside(point, features[i]);
      console.log(is_inside);

      if (is_inside) {
        console.log('Found it inside');
      }
    }

    console.log(cluster);
  });
});

Here is my HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
</head>
<body>
  <div class="container">
    <div class="row">
      <div class="col-md-12 content">
      </div>
    </div>
  </div>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src='https://npmcdn.com/@turf/turf/turf.min.js'></script>
  <script src="js/get-data.js"></script>
</body>

Best Answer

GeoJSON requires the coordinates to be in WGS-84 (4326) however your coordinates are not in Lat, Long. I'm guessing your using some projection that used meters. You need to re-project your data to WGS-84 then make your GeoJSON file.

You can check your file in http://geojsonlint.com/ or http://geojson.io.

Lat coordinates are never greater then 90, long never greater then 180.

What you have: {"type":"Polygon","coordinates":[[[548716.5712466406,2291522.454105338],[548709.6603264149,2291623.0293460153],[548707.9638823455,2291833.4553844943],