0

I'm trying to get all the points within a distance of 10 meter for example. the Withindistance() doesn't work and it doesn't give me any error so i don't know what is the issue.

Here is my controller :

public IActionResult GetWeather()
        {

            IList<WeatherViewModel> Tags = new List<WeatherViewModel>();

       
            var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
            var searchAreaCoordinate = new NetTopologySuite.Geometries.Coordinate(-1.88049067645237,52.486034913778894);
            var searchArea = geometryFactory.CreatePoint(searchAreaCoordinate);
    
            Root weather = JsonConvert.DeserializeObject<Root>(System.IO.File.ReadAllText(@"C:\local\weather.json"));
            var features = (from c in  weather.features select c)
            .Select(x=> new {x.id,x.type,x.geometry.coordinates,Coor= new Point(x.geometry.coordinates[0],x.geometry.coordinates[1]){ SRID = 4326 }, 
            
            
            })
            .Where(x=>x.Coor.IsWithinDistance(searchArea, 10))
            
            .ToList();
            ;

            foreach (var item in features)
            {
                Tags.Add(new WeatherViewModel()
                
                {
                            id = item.id,
                            type = item.type,
                            Long = item.coordinates[0],
                            Lat = item.coordinates[1],
                            test = item.Coor.ToString(),
                            Distance = item.Coor.Distance(searchArea)
                        
                            // WKT = item.z
                            // WKT = new NetTopologySuite.Geometries.Coordinate( item.coordinates[0] , item.coordinates[1])
                           
                }
                );
            }
            
            return View(Tags);
        }
    }

Note that I'm getting all the records . The Where() doesn't work so if i comment it out ill still get all the results:

Json Class

public class Root
   {
       public string type { get; set; }
       public ParameterDescription parameter_description { get; set; }
       public List<double> bbox { get; set; }
       public List<Feature> features { get; set; }
   }
public class Geometry
   {
       public string type { get; set; }
       public List<double> coordinates { get; set; }
   }

   public class Feature
   {
       public string id { get; set; }
       public string type { get; set; }
       public Properties properties { get; set; }
       public Geometry geometry { get; set; }
       public Geometry Coor {get;set;}
   }

Json sample

{
   "type": "FeatureCollection",
  
   "features": [
       {
           "id": "1",
           "type": "Feature",
           "properties": {
               "t": [
                   1,
     
               ],
               "s": [
                   1,
         
               ],
               "Time": [
                   "2021-11-01",

               ]
           },
           "geometry": {
               "type": "Point",
               "coordinates": [
                   -1.881,
                   52.486
               ]
           }
       },
       
   ]
}

Any idea?

Fadi
  • 585
  • 4
  • 22
  • 1
    that you get all the records suggests that you are asking for a 10 **degree** buffer not a 10 **metre** one. You may need to reproject to a better crs (in metres) before you try the dwithin operation – Ian Turton Jan 25 '22 at 14:30
  • @IanTurton tried buffer but it doesn't work. I thought the result I'm getting is in meter ? how can i do that? – Fadi Jan 25 '22 at 14:51
  • does https://stackoverflow.com/questions/54991193/what-sort-of-unit-does-nettopologysuite-return-distances-in-and-how-can-i-conve help? – Ian Turton Jan 25 '22 at 15:07
  • @IanTurton I'll give it a shot, but do you think that the problem is because the coordinate system ? – Fadi Jan 25 '22 at 15:17
  • I don't use the topologysuite so I can't be sure but that is what it looks like to me – Ian Turton Jan 25 '22 at 16:23
  • @IanTurton Hi Ian, I would like to confirm that after converting to another coordinate system (27700), the method works well!! and I'm getting the result in meter. Thanks! – Fadi Jan 26 '22 at 09:27

0 Answers0