I have to check if a specified coordinate is contained in a polygon made out of coordinates. I have this function:
bool inside = false;
foreach (ZonaAsignacion za in lstz)
{
Coordinate[] q4 = (from p in _context.Zonas.Include("lstPoligonos").Where(x =>
((x.idEmpresa == 1) || (x.idEmpresa == geoloc.idEmpresa)) && x.ID == za.idZona)
from p2 in p.lstPoligonos.OrderBy(it=> it.ID)
select new Coordinate { X = (double)p2.longitude, Y = (double)p2.latitude })
.ToArray<Coordinate>();
Polygon poly = geometryFactory.CreatePolygon(q4);
Point point = geometryFactory.CreatePoint(new Coordinate((double)geoloc.longitud,(double)geoloc.latitud));
if (poly.Contains(point))
{
inside = true;
}
}
I was testing with this coordinates new Coordinate(-76.122099,-13.405453) and this polygon:
POLYGON ((-76.124454 -13.40312, -76.124467 -13.403144, -76.124643 -13.403651, -76.124777 -13.404029, -76.124876 -13.404305, -76.12502 -13.40471, -76.123886 -13.40501, -76.123986 -13.405274, -76.12425 -13.405188, -76.124344 -13.405474, -76.124593 -13.405388, -76.1246 -13.405406, -76.124839 -13.405329, -76.124848 -13.405355, -76.125206 -13.405234, -76.125252 -13.405373, -76.125312 -13.405582, -76.125404 -13.405905, -76.124304 -13.406243, -76.123861 -13.406384, -76.12395 -13.406673, -76.123732 -13.406755, -76.123769 -13.406873, -76.123542 -13.407092, -76.12354 -13.407093, -76.122673 -13.407548, -76.12257 -13.407519, -76.122569 -13.407518, -76.12196 -13.407876, -76.121959 -13.407877, -76.120314 -13.408875, -76.119776 -13.407937, -76.119761 -13.407948, -76.119129 -13.406949, -76.119127 -13.406945, -76.118939 -13.405765, -76.119018 -13.405696, -76.11902 -13.405694, -76.119385 -13.405139, -76.120203 -13.403866, -76.120233 -13.403883, -76.120233 -13.403883, -76.120398 -13.404355, -76.120402 -13.404354, -76.120403 -13.404353, -76.120644 -13.404265, -76.120604 -13.404155, -76.120858 -13.404067, -76.120858 -13.404067, -76.120865 -13.40408, -76.12107 -13.404007, -76.121081 -13.404037, -76.121305 -13.403959, -76.12134 -13.403972, -76.121522 -13.404483, -76.12177 -13.404412, -76.121598 -13.403912, -76.122101 -13.403731, -76.122113 -13.403763, -76.12231 -13.403695, -76.122331 -13.403685, -76.122305 -13.403615, -76.122588 -13.403511, -76.122628 -13.403626, -76.123078 -13.403488, -76.123088 -13.403514, -76.12326 -13.403454, -76.12326 -13.403454, -76.123351 -13.403426, -76.123358 -13.403424, -76.123584 -13.403349, -76.123593 -13.403374, -76.123851 -13.403286, -76.123854 -13.403292, -76.124063 -13.403224, -76.124069 -13.403243, -76.124454 -13.40312, -76.124454 -13.40312, -76.124467 -13.403144, -76.124643 -13.403651, -76.124777 -13.404029, -76.124876 -13.404305, -76.12502 -13.40471, -76.123886 -13.40501, -76.123986 -13.405274, -76.12425 -13.405188, -76.124344 -13.405474, -76.124593 -13.405388, -76.1246 -13.405406, -76.124839 -13.405329, -76.124848 -13.405355, -76.125206 -13.405234, -76.125252 -13.405373, -76.125312 -13.405582, -76.125404 -13.405905, -76.124304 -13.406243, -76.123861 -13.406384, -76.12395 -13.406673, -76.123732 -13.406755, -76.123769 -13.406873, -76.123542 -13.407092, -76.12354 -13.407093, -76.122673 -13.407548, -76.12257 -13.407519, -76.122569 -13.407518, -76.12196 -13.407876, -76.121959 -13.407877, -76.120314 -13.408875, -76.119776 -13.407937, -76.119761 -13.407948, -76.119129 -13.406949, -76.119127 -13.406945, -76.118939 -13.405765, -76.119018 -13.405696, -76.11902 -13.405694, -76.119385 -13.405139, -76.120203 -13.403866, -76.120233 -13.403883, -76.120233 -13.403883, -76.120398 -13.404355, -76.120402 -13.404354, -76.120403 -13.404353, -76.120644 -13.404265, -76.120604 -13.404155, -76.120858 -13.404067, -76.120858 -13.404067, -76.120865 -13.40408, -76.12107 -13.404007, -76.121081 -13.404037, -76.121305 -13.403959, -76.12134 -13.403972, -76.121522 -13.404483, -76.12177 -13.404412, -76.121598 -13.403912, -76.122101 -13.403731, -76.122113 -13.403763, -76.12231 -13.403695, -76.122331 -13.403685, -76.122305 -13.403615, -76.122588 -13.403511, -76.122628 -13.403626, -76.123078 -13.403488, -76.123088 -13.403514, -76.12326 -13.403454, -76.12326 -13.403454, -76.123351 -13.403426, -76.123358 -13.403424, -76.123584 -13.403349, -76.123593 -13.403374, -76.123851 -13.403286, -76.123854 -13.403292, -76.124063 -13.403224, -76.124069 -13.403243, -76.124454 -13.40312, -76.124454 -13.40312, -76.124467 -13.403144, -76.124643 -13.403651, -76.124777 -13.404029, -76.124876 -13.404305, -76.12502 -13.40471, -76.123886 -13.40501, -76.123986 -13.405274, -76.12425 -13.405188, -76.124344 -13.405474, -76.124593 -13.405388, -76.1246 -13.405406, -76.124839 -13.405329, -76.124848 -13.405355, -76.125206 -13.405234, -76.125252 -13.405373, -76.125312 -13.405582, -76.125404 -13.405905, -76.124304 -13.406243, -76.123861 -13.406384, -76.12395 -13.406673, -76.123732 -13.406755, -76.123769 -13.406873, -76.123542 -13.407092, -76.12354 -13.407093, -76.122673 -13.407548, -76.12257 -13.407519, -76.122569 -13.407518, -76.12196 -13.407876, -76.121959 -13.407877, -76.120314 -13.408875, -76.119776 -13.407937, -76.119761 -13.407948, -76.119129 -13.406949, -76.119127 -13.406945, -76.118939 -13.405765, -76.119018 -13.405696, -76.11902 -13.405694, -76.119385 -13.405139, -76.120203 -13.403866, -76.120233 -13.403883, -76.120233 -13.403883, -76.120398 -13.404355, -76.120402 -13.404354, -76.120403 -13.404353, -76.120644 -13.404265, -76.120604 -13.404155, -76.120858 -13.404067, -76.120858 -13.404067, -76.120865 -13.40408, -76.12107 -13.404007, -76.121081 -13.404037, -76.121305 -13.403959, -76.12134 -13.403972, -76.121522 -13.404483, -76.12177 -13.404412, -76.121598 -13.403912, -76.122101 -13.403731, -76.122113 -13.403763, -76.12231 -13.403695, -76.122331 -13.403685, -76.122305 -13.403615, -76.122588 -13.403511, -76.122628 -13.403626, -76.123078 -13.403488, -76.123088 -13.403514, -76.12326 -13.403454, -76.12326 -13.403454, -76.123351 -13.403426, -76.123358 -13.403424, -76.123584 -13.403349, -76.123593 -13.403374, -76.123851 -13.403286, -76.123854 -13.403292, -76.124063 -13.403224, -76.124069 -13.403243, -76.124454 -13.40312, -76.124454 -13.40312, -76.124467 -13.403144, -76.124643 -13.403651, -76.124777 -13.404029, -76.124876 -13.404305, -76.12502 -13.40471, -76.123886 -13.40501, -76.123986 -13.405274, -76.12425 -13.405188, -76.124344 -13.405474, -76.124593 -13.405388, -76.1246 -13.405406, -76.124839 -13.405329, -76.124848 -13.405355, -76.125206 -13.405234, -76.125252 -13.405373, -76.125312 -13.405582, -76.125404 -13.405905, -76.124304 -13.406243, -76.123861 -13.406384, -76.12395 -13.406673, -76.123732 -13.406755, -76.123769 -13.406873, -76.123542 -13.407092, -76.12354 -13.407093, -76.122673 -13.407548, -76.12257 -13.407519, -76.122569 -13.407518, -76.12196 -13.407876, -76.121959 -13.407877, -76.120314 -13.408875, -76.119776 -13.407937, -76.119761 -13.407948, -76.119129 -13.406949, -76.119127 -13.406945, -76.118939 -13.405765, -76.119018 -13.405696, -76.11902 -13.405694, -76.119385 -13.405139, -76.120203 -13.403866, -76.120233 -13.403883, -76.120233 -13.403883, -76.120398 -13.404355, -76.120402 -13.404354, -76.120403 -13.404353, -76.120644 -13.404265, -76.120604 -13.404155, -76.120858 -13.404067, -76.120858 -13.404067, -76.120865 -13.40408, -76.12107 -13.404007, -76.121081 -13.404037, -76.121305 -13.403959, -76.12134 -13.403972, -76.121522 -13.404483, -76.12177 -13.404412, -76.121598 -13.403912, -76.122101 -13.403731, -76.122113 -13.403763, -76.12231 -13.403695, -76.122331 -13.403685, -76.122305 -13.403615, -76.122588 -13.403511, -76.122628 -13.403626, -76.123078 -13.403488, -76.123088 -13.403514, -76.12326 -13.403454, -76.12326 -13.403454, -76.123351 -13.403426, -76.123358 -13.403424, -76.123584 -13.403349, -76.123593 -13.403374, -76.123851 -13.403286, -76.123854 -13.403292, -76.124063 -13.403224, -76.124069 -13.403243, -76.124454 -13.40312))
It should have returned true, because that Coordinates are inside the polygon, as i could check in google maps, but it always returns false. I have already tried with other algorythms and libraries and all return the same, why is that? Thanks for your help