[postgis-users] Problem : Within() incorrectly returns 'false'

Martin Davis mbdavis at refractions.net
Mon Jan 8 09:33:11 PST 2007


I'm not sure about this one.  The test checks out fine in JTS. 

But note that you have some <CR>s in the text of the Polygon geometry 
which occur in the middle of coordinate values, and which if actually 
present in the string cause invalid geometry to be created.  If you're 
running this SQL from a script, then you should closely inspect the 
script to make sure that the cmd is either all on one line or the line 
breaks do not split numeric values.

Arnaud Lesauvage wrote:
> Hi List !
>
> I have a problem with the Within() function.
> I use it to test whether points are within polygons, in conjunction 
> with '&&' for index use.
> In some cases, Within() returns false even though the point is 
> obviously within the polygon.
> Here is an example of such a behaviour (note that I test the polygon 
> for validity, and IsValid returns 'true') :
>
> mydb=# select postgis_full_version();
>                                           postgis_full_version
> -------------------------------------------------------------------------------------------------------- 
>
>  POSTGIS="1.2.0" GEOS="2.2.3-CAPI-1.1.1" PROJ="Rel. 4.5.0, 22 Oct 
> 2006" USE_STATS (procs 1.1.0 upgrade)
> (1 row)
>
> mydb=# SELECT GeomFromText('POINT(455663 4973705)',32631) && 
> GeomFromText('POLYGON((455634.327007261 
> 4973739.18140708,455640.390824553 4973742.34545851,455649.974963534 
> 4973744.72838799,455655.302230411 4973744.81018619,455666.871609771 
> 4973741.51734043,455673.066844244 4973737.99160574,455682.857256671 
> 4973731.31013028,455696.77629443 4973721.97329467,455713.453957339 
> 4973712.16884477,455721.42334697 4973707.86016838,455737.50239802 
> 4973705.84732456,455748.289255495 4973707.80971155,455768.964516862 
> 4973713.10563678,455789.467434074 4973718.30527948,455809.877573217 
> 4973718.59365931,455816.032949075 4973711.16573985,455819.835126931 
> 4973702.44653788,455824.05944495 4973691.47543162,455824.05944495 
> 4973691.47543162,455828.610407021 4973680.12283995,455830.970634323 
> 4973674.90248145,455833.367228335 4973670.30554483,455838.223766503 
> 4973663.87857158,455853.056176824 4973662.3695754,455866.6601998 
> 4973666.33738459,455872.247284383 4973667.83016243,455891.21742699 
> 4973672.66515592,455904.87965274 4973676.20206359,455925.323306466 
> 4973681.93577574,455931.93236638 4973683.83511874,455963.188375863 
> 4973690.90230387,455986.900652308 4973690.57770489,455999.308881106 
> 4973688.08608035,456
> 006.847072463 4973685.91128035,456013.781894891 
> 4973682.68047389,456020.04917607 4973677.53977996,456028.058802994 
> 4973664.42994524,456032.395247822 4973652.08166202,456034.250253643 
> 4973645.32660031,456037.315382866 4973631.6242598,456038.518126576 
> 4973625.06483024,456039.49606989 4973618.95846064,456041.143946469 
> 4973604.12669801,456041.322480722 4973600.16812515,456041.234269879 
> 4973593.33220285,456040.255579245 4973584.79199929,456038.077220394 
> 4973576.88018093,456031.407673379 4973564.92278014,456022.584091079 
> 4973553.60498374,456015.530632601 4973545.35673604,456011.870844281 
> 4973541.1846865,456001.221309389 4973529.12192161,455991.929965679 
> 4973518.46446974,455982.111242839 4973507.13762537,455975.429739526 
> 4973499.25369943,455968.699421007 4973481.2156405,455968.569127113 
> 4973472.22440673,455968.681690362 4973469.48222644,455968.364280116 
> 4973459.20668792,455964.198441514 4973452.80965392,455957.352768727 
> 4973451.16429375,455950.970005851 4973451.05854393,455925.042572423 
> 4973453.79303565,455920.580033511 4973454.95190268,455916.338152812 
> 4973456.411639,455908.870067239 4973460.36365329,455899.377173016 
> 4973468.20421239,455892.64054911 4973473.70250239,455884.308266302 4973
> 478.59803378,455873.700962084 4973482.45761784,455861.855176683 
> 4973485.90236361,455859.696574931 4973492.55059044,455844.389439454 
> 4973492.39432963,455839.411700775 4973495.34512154,455831.33685203 
> 4973502.9194365,455825.191393046 4973512.52991105,455822.579473065 
> 4973518.00029755,455817.751828832 4973530.0745478,455812.814767254 
> 4973543.24550764,455807.105870701 4973557.06881857,455803.959640509 
> 4973563.64623146,455796.916583005 4973575.41517021,455792.972660989 
> 4973580.26754987,455786.234602819 4973585.77560012,455773.906298319 
> 4973590.19110681,455755.880529301 4973589.95244674,455741.983929337 
> 4973588.07856712,455734.473975748 4973587.00298353,455726.703007087 
> 4973585.92187192,455710.902303958 4973583.8726695,455695.630378757 
> 4973582.19016965,455688.520382506 4973581.56743626,455675.978583625 
> 4973580.92133312,455661.611205371 4973581.95574872,455651.587526438 
> 4973586.21821552,455646.738207892 4973591.31382874,455642.936132872 
> 4973598.59694555,455639.807137755 4973608.4661572,455638.377942947 
> 4973614.49593153,455636.97649546 4973621.32268911,455634.084325749 
> 4973637.51733042,455631.585960851 4973653.17474669,455630.344123986 
> 4973661.50140289,455629.696234567 4973665.93866226,455
> 629.696234567 4973665.93866226,455628.383269606 
> 4973675.5239203,455626.235378731 4973693.34686891,455624.997527166 
> 4973707.75141773,455625.052806357 4973722.19487999,455626.239816571 
> 4973728.34327406,455630.963831745 4973736.33081102,455634.327007261 
> 4973739.18140708))',32631),
> mydb-# Within(GeomFromText('POINT(455663 4973705)',32631), 
> GeomFromText('POLYGON((455634.327007261 
> 4973739.18140708,455640.390824553 4973742.34545851,455649.974963534 
> 4973744.72838799,455655.302230411 4973744.81018619,455666.871609771 
> 4973741.51734043,455673.066844244 4973737.99160574,455682.857256671 
> 4973731.31013028,455696.77629443 4973721.97329467,455713.453957339 
> 4973712.16884477,455721.42334697 4973707.86016838,455737.50239802 
> 4973705.84732456,455748.289255495 4973707.80971155,455768.964516862 
> 4973713.10563678,455789.467434074 4973718.30527948,455809.877573217 
> 4973718.59365931,455816.032949075 4973711.16573985,455819.835126931 
> 4973702.44653788,455824.05944495 4973691.47543162,455824.05944495 
> 4973691.47543162,455828.610407021 4973680.12283995,455830.970634323 
> 4973674.90248145,455833.367228335 4973670.30554483,455838.223766503 
> 4973663.87857158,455853.056176824 4973662.3695754,455866.6601998 
> 4973666.33738459,455872.247284383 4973667.83016243,455891.21742699 
> 4973672.66515592,455904.87965274 4973676.20206359,455925.323306466 
> 4973681.93577574,455931.93236638 4973683.83511874,455963.188375863 
> 4973690.90230387,455986.900652308 4973690.57770489,455999.308881106 
> 4973688.08608035,45600
> 6.847072463 4973685.91128035,456013.781894891 
> 4973682.68047389,456020.04917607 4973677.53977996,456028.058802994 
> 4973664.42994524,456032.395247822 4973652.08166202,456034.250253643 
> 4973645.32660031,456037.315382866 4973631.6242598,456038.518126576 
> 4973625.06483024,456039.49606989 4973618.95846064,456041.143946469 
> 4973604.12669801,456041.322480722 4973600.16812515,456041.234269879 
> 4973593.33220285,456040.255579245 4973584.79199929,456038.077220394 
> 4973576.88018093,456031.407673379 4973564.92278014,456022.584091079 
> 4973553.60498374,456015.530632601 4973545.35673604,456011.870844281 
> 4973541.1846865,456001.221309389 4973529.12192161,455991.929965679 
> 4973518.46446974,455982.111242839 4973507.13762537,455975.429739526 
> 4973499.25369943,455968.699421007 4973481.2156405,455968.569127113 
> 4973472.22440673,455968.681690362 4973469.48222644,455968.364280116 
> 4973459.20668792,455964.198441514 4973452.80965392,455957.352768727 
> 4973451.16429375,455950.970005851 4973451.05854393,455925.042572423 
> 4973453.79303565,455920.580033511 4973454.95190268,455916.338152812 
> 4973456.411639,455908.870067239 4973460.36365329,455899.377173016 
> 4973468.20421239,455892.64054911 4973473.70250239,455884.308266302 497347
> 8.59803378,455873.700962084 4973482.45761784,455861.855176683 
> 4973485.90236361,455859.696574931 4973492.55059044,455844.389439454 
> 4973492.39432963,455839.411700775 4973495.34512154,455831.33685203 
> 4973502.9194365,455825.191393046 4973512.52991105,455822.579473065 
> 4973518.00029755,455817.751828832 4973530.0745478,455812.814767254 
> 4973543.24550764,455807.105870701 4973557.06881857,455803.959640509 
> 4973563.64623146,455796.916583005 4973575.41517021,455792.972660989 
> 4973580.26754987,455786.234602819 4973585.77560012,455773.906298319 
> 4973590.19110681,455755.880529301 4973589.95244674,455741.983929337 
> 4973588.07856712,455734.473975748 4973587.00298353,455726.703007087 
> 4973585.92187192,455710.902303958 4973583.8726695,455695.630378757 
> 4973582.19016965,455688.520382506 4973581.56743626,455675.978583625 
> 4973580.92133312,455661.611205371 4973581.95574872,455651.587526438 
> 4973586.21821552,455646.738207892 4973591.31382874,455642.936132872 
> 4973598.59694555,455639.807137755 4973608.4661572,455638.377942947 
> 4973614.49593153,455636.97649546 4973621.32268911,455634.084325749 
> 4973637.51733042,455631.585960851 4973653.17474669,455630.344123986 
> 4973661.50140289,455629.696234567 4973665.93866226,45562
> 9.696234567 4973665.93866226,455628.383269606 
> 4973675.5239203,455626.235378731 4973693.34686891,455624.997527166 
> 4973707.75141773,455625.052806357 4973722.19487999,455626.239816571 
> 4973728.34327406,455630.963831745 4973736.33081102,455634.327007261 
> 4973739.18140708))',32631));
>  ?column? | within
> ----------+--------
>  t        | f
> (1 row)
>
>
>
> Does anyone know what's wrong with my PostIS ?
>
> Thanks !
> -- 
> Arnaud
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>

-- 
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022




More information about the postgis-users mailing list