Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.9k stars 1.1k forks source link

Intersect method in GeoSeriesAccessor returns True for non-intersecting features as well #1575

Closed kartikeyhadiya closed 1 year ago

kartikeyhadiya commented 1 year ago

Describe the bug Intersect method in GeoSeriesAccessor returns True for non-intersecting features as well. I think intersect method is the same for both GeoSeriesAccessor as well as Geometry Classes.

To Reproduce Steps to reproduce the behavior: Please check the screenshots.

Screenshots Screenshot 2023-05-25 123355

As seen in the 1 and 2 cells, the intersection with all the items returns true. In the 3rd cell when I checked the intersection with the 1st item in my sdf is NaN so ideally GeoSeriesAccessor intersect method should return False for that item

Expected behavior GeoSeriesAccessor intersect method should return False for geometries that don't intersect.

Platform (please complete the following information):

achapkowski commented 1 year ago

Can you post a reproducible sample as text?

kartikeyhadiya commented 1 year ago
import pandas as pd
import arcgis
from arcgis.geometry.filters import intersects
from arcgis.features import FeatureLayer
grids_dict = {
    'OID': [1, 2, 3, 4, 5],
    'SHAPE': [{'rings': [[[20.57415764192833, -19.875000000171646], [20.57415764192833, -19.45203619510036], [21.023315283988094, -19.45203619510036], [21.023315283988094, -19.875000000171646], [20.57415764192833, -19.875000000171646]]], 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}},
              {'rings': [[[20.12499999986857, -19.875000000171646], [20.12499999986857, -19.45203619510036], [20.57415764192833, -19.45203619510036], [20.57415764192833, -19.875000000171646], [20.12499999986857, -19.875000000171646]]], 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}},
              {'rings': [[[21.023315283988094, -19.875000000171646], [21.023315283988094, -19.45203619510036], [21.472472926047853, -19.45203619510036], [21.472472926047853, -19.875000000171646], [21.023315283988094, -19.875000000171646]]], 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}},
              {'rings': [[[21.472472926047853, -19.875000000171646], [21.472472926047853, -19.45203619510036], [21.921630568107613, -19.45203619510036], [21.921630568107613, -19.875000000171646], [21.472472926047853, -19.875000000171646]]], 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}},
              {'rings': [[[66.83739477408368, 20.9990991757357], [66.83739477408368, 21.417834316643788], [67.28655241614345, 21.417834316643788], [67.28655241614345, 20.9990991757357], [66.83739477408368, 20.9990991757357]]], 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}}
              ],
    'SHAPE__Length': [200000.0, 200000.0, 200000.0, 200000.0, 200000.0],
    'SHAPE__Area': [2500000000.0, 2500000000.0, 2500000000.0, 2500000000.0, 2500000000.0]
}
df = pd.DataFrame(grids_dict)
df.spatial.set_geometry('SHAPE')

points_dict = {
    'OID': [1, 2, 3, 4, 5,6],
    'SHAPE': [{'x': 20.57415764192833, 'y': -19.875000000171646, 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}},
              {'x': 68.29185824000007, 'y': 20.541292260000034, 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}},
              {'x': 68.50555721000006, 'y': 21.112855730000035, 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}},
              {'x': 66.84478418000003, 'y': 21.386062750000065, 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}},
              {'x': 67.32967712000004, 'y': 20.59364787000004, 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}},
              {'x': 65.29661502000005, 'y': 20.295224950000033, 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}}
              ]
}
points_df = pd.DataFrame(points_dict)
points_df.spatial.set_geometry('SHAPE')
points_df.dtypes, df.dtypes

print(points_df.loc[points_df['SHAPE'].geom.intersect(df.loc[df['OID'] == 5].iloc[0].SHAPE)])
print(points_df['SHAPE'].geom.intersect(df.loc[df['OID'] == 5].iloc[0].SHAPE))

print(points_df.iloc[0].SHAPE.intersect(df.loc[df['OID'] == 5].SHAPE.iloc[0]))
print(points_df.iloc[3].SHAPE.intersect(df.loc[df['OID'] == 5].SHAPE.iloc[0]))
achapkowski commented 1 year ago

@kartikeyhadiya

can you please post your package list in your environment?

conda list

What version of Python are you using? With or without arcpy?

kartikeyhadiya commented 1 year ago

Name Version Build Channel

anyio 3.5.0 py39haa95532_0 appdirs 1.4.4 pyhd3eb1b0_0 arcgis 2.1.0.2 py39_14 esri arcgispro 3.1 0 esri arcpy 3.1 py39_arcgispro_41759 [arcgispro] esri arcpy-base 3.1 py39_41759 esri argon2-cffi 21.3.0 pyhd3eb1b0_0 argon2-cffi-bindings 21.2.0 py39h2bbff1b_0 arrow-cpp 1.0.1 17 esri asttokens 2.0.5 pyhd3eb1b0_0 attrs 21.4.0 pyhd3eb1b0_0 azure-core 1.12.0 py_0 esri azure-storage-blob 12.8.0 py_0 esri babel 2.11.0 py39_1 esri backcall 0.2.0 pyhd3eb1b0_0 beautifulsoup4 4.11.1 py39haa95532_0 black 22.1.0 py39_3 esri blas 1.0 mkl bleach 4.1.0 pyhd3eb1b0_0 blinker 1.4 py39haa95532_0 bottleneck 1.3.5 py39h080aedc_0 brotli 1.0.9 pypi_0 pypi brotli-bin 1.0.9 h2bbff1b_7 brotlipy 0.7.0 py39h2bbff1b_1003 cachetools 4.2.2 pyhd3eb1b0_0 certifi 2022.9.24 py39haa95532_0 cffi 1.15.1 py39h2bbff1b_0 cftime 1.6.2 py39_0 esri chardet 3.0.4 pypi_0 pypi charset-normalizer 2.0.4 pyhd3eb1b0_0 click 8.0.4 py39haa95532_0 cloudpickle 2.0.0 pyhd3eb1b0_0 colorama 0.4.5 py39haa95532_0 contourpy 1.0.5 py39h59b6b97_0 cppzmq 4.4.1 4 esri cryptography 38.0.4 py39_0 esri cssselect2 0.7.0 pypi_0 pypi cycler 0.11.0 pyhd3eb1b0_0 cython 0.29.34 pypi_0 pypi cytoolz 0.11.0 py39h2bbff1b_0 dask 2022.7.0 py_0 esri dask-core 2022.7.0 py39haa95532_0 debugpy 1.5.1 py39hd77b12b_0 decorator 5.1.1 pyhd3eb1b0_0 defusedxml 0.7.1 pyhd3eb1b0_0 despatch 0.2.0 py39_0 esri distributed 2022.7.0 py39haa95532_0 entrypoints 0.4 py39haa95532_0 et_xmlfile 1.1.0 py39haa95532_0 exceptiongroup 1.0.0rc9 pyhd8ed1ab_0 esri executing 0.8.3 pyhd3eb1b0_0 flake8 4.0.1 pyhd3eb1b0_1 fonttools 4.25.0 pyhd3eb1b0_0 freetype 2.12.1 4 esri fsspec 2022.7.1 py39haa95532_0 future 0.18.2 py39_2 esri gdal 3.4.0 arcgispro_py39_17150 [arcgispro] esri geomet 1.0.0 py_0 esri googletrans 3.1.0a0 pypi_0 pypi greenlet 1.1.1 py39hd77b12b_0 h11 0.9.0 pypi_0 pypi h2 3.2.0 pypi_0 pypi h5py 3.7.0 arcgispro_py39_0 [arcgispro] esri heapdict 1.0.1 pyhd3eb1b0_0 hpack 3.0.0 pypi_0 pypi hstspreload 2023.1.1 pypi_0 pypi html5lib 1.1 pypi_0 pypi httpcore 0.9.1 pypi_0 pypi httpx 0.13.3 pypi_0 pypi hyperframe 5.2.0 pypi_0 pypi icc_rt 2019.0.5 arcgispro_0 [arcgispro] esri idna 2.10 pypi_0 pypi importlib-metadata 4.11.3 py39haa95532_0 importlib_metadata 4.11.3 hd3eb1b0_0 iniconfig 1.1.1 pyhd3eb1b0_0 intel-openmp 2020.0 arcgispro_166 [arcgispro] esri ipykernel 6.16.0 py_1 esri ipython 7.34.0 pyhbfea036_1 esri ipython_genutils 0.2.0 pyhd3eb1b0_1 ipywidgets 7.7.2 py_0 esri isodate 0.6.0 py_0 esri jdcal 1.4.1 pyhd3eb1b0_0 jedi 0.18.2 py39_0 esri jinja2 3.0.3 pyhd3eb1b0_0 jpeg 9e 0 esri json5 0.9.5 py_0 esri jsonschema 4.16.0 py39haa95532_0 jupyter_client 6.1.12 py_0 esri jupyter_console 6.4.2 py_0 esri jupyter_contrib_core 0.4.0 py_0 esri jupyter_contrib_nbextensions 0.6.0 py_2 esri jupyter_core 4.11.2 py39_0 esri jupyter_highlight_selected_word 0.2.0 py_4 esri jupyter_latex_envs 1.4.6 py_5 esri jupyter_nbextensions_configurator 0.4.1 py_3 esri jupyter_server 1.21.0 py_0 esri jupyterlab 3.4.8 py_0 esri jupyterlab_pygments 0.2.2 py_0 esri jupyterlab_server 2.16.0 py_1 esri jupyterlab_widgets 3.0.3 py_1 esri keyring 23.4.0 py39_0 esri kiwisolver 1.4.2 py39hd77b12b_0 krb5 1.19.2 h5b6d351_0 lerc 4.0 pyh39e3cac_0 esri libbrotlicommon 1.0.9 h2bbff1b_7 libbrotlidec 1.0.9 h2bbff1b_7 libbrotlienc 1.0.9 h2bbff1b_7 libdeflate 1.8 h2bbff1b_5 libpng 1.6.37 h2a8f88b_0 libprotobuf 3.19.4 0 esri libsodium 1.0.18 4 esri libtiff 4.5.0 2 esri libxml2 2.10.3 arcgispro_0 [arcgispro] esri libxslt 1.1.37 3 esri locket 1.0.0 py39haa95532_0 lxml 4.9.1 py39_1 esri lz4 3.1.3 py39h2bbff1b_0 lz4-c 1.9.3 h2bbff1b_1 markupsafe 2.1.1 py39h2bbff1b_0 matplotlib 3.6.0 py39_arcgispro_3 [arcgispro] esri matplotlib-base 3.6.0 py39_arcgispro_4 [arcgispro] esri matplotlib-inline 0.1.6 py39haa95532_0 mccabe 0.7.0 pyhd3eb1b0_0 mistune 2.0.4 py39haa95532_0 mkl 2020.0 arcgispro_167 [arcgispro] esri mkl-service 2.3.0 py39_2 esri mkl_fft 1.3.0 py39_0 esri mkl_random 1.2.2 py39_0 esri mpmath 1.2.1 py39haa95532_0 msgpack-python 1.0.3 py39h59b6b97_0 msrest 0.6.21 py_0 esri munkres 1.1.4 py_0 mypy_extensions 0.4.3 py39haa95532_1 nbclassic 0.4.8 py_0 esri nbclient 0.7.0 py_3 esri nbconvert 7.2.1 py_2 esri nbformat 5.6.1 py_0 esri nest-asyncio 1.5.5 py39haa95532_0 netcdf4 1.6.1 py39_arcgispro_1 [arcgispro] esri networkx 2.8.4 py39haa95532_0 nlohmann_json 3.7.0 2 esri nose 1.3.7 pyhd3eb1b0_1008 notebook 6.4.12 py_0 esri notebook-shim 0.1.0 py_0 esri ntlm-auth 1.4.0 py_0 esri numexpr 2.8.1 py39_0 esri numpy 1.20.1 py39_0 esri numpy-base 1.20.1 py39_0 esri oauthlib 3.2.0 py39_0 esri olefile 0.46 pyhd3eb1b0_0 openpyxl 3.0.10 py39h2bbff1b_0 openssl 3.0.7 0 esri packaging 21.3 pyhd3eb1b0_0 pandas 1.4.4 py39hd77b12b_0 pandocfilters 1.5.0 pyhd3eb1b0_0 parso 0.8.3 pyhd3eb1b0_0 partd 1.2.0 pyhd3eb1b0_1 pathspec 0.9.0 py_0 esri pefile 2022.5.30 pyhd8ed1ab_0 esri pickleshare 0.7.5 pyhd3eb1b0_1003 pillow 9.1.0 pypi_0 pypi pip 22.2.2 py39haa95532_0 platformdirs 2.5.2 py39haa95532_0 pluggy 0.13.1 py39haa95532_0 pro_notebook_integration 3.1 py39_12 esri prometheus_client 0.8.0 py_0 esri prompt_toolkit 3.0.5 py_0 esri protobuf 3.19.4 py39_1 esri psutil 5.9.0 py39h2bbff1b_0 pure_eval 0.2.2 pyhd3eb1b0_0 pyarrow 1.0.1 py39_3 esri pybind11 2.7.1 1 esri pybind11_json 0.2.6 3 esri pycodestyle 2.8.0 pyhd3eb1b0_0 pycparser 2.21 pyhd3eb1b0_0 pydyf 0.6.0 pypi_0 pypi pyflakes 2.4.0 pyhd3eb1b0_0 pygments 2.9.0 py_0 esri pyjwt 2.4.0 py_1 esri pyminizip 0.2.6 pypi_0 pypi pyodbc 4.0.34 py39hd77b12b_0 pyopenssl 22.0.0 pyhd3eb1b0_0 pyparsing 3.0.9 py39haa95532_0 pypdf2 1.26.0 py_4 esri pyphen 0.14.0 pypi_0 pypi pyqt5 5.15.9 pypi_0 pypi pyqt5-qt5 5.15.2 pypi_0 pypi pyqt5-sip 12.12.1 pypi_0 pypi pyqtwebengine 5.15.6 pypi_0 pypi pyqtwebengine-qt5 5.15.2 pypi_0 pypi pyrsistent 0.18.0 py39h196d8e1_0 pyshp 2.1.3 pyhd3eb1b0_0 pyside6 6.5.0 pypi_0 pypi pyside6-addons 6.5.0 pypi_0 pypi pyside6-essentials 6.5.0 pypi_0 pypi pysocks 1.7.1 py39haa95532_0 pytest 7.2.0 py39_0 esri python 3.9.16 0 esri python-certifi-win32 1.6 py_0 esri python-dateutil 2.8.2 pyhd3eb1b0_0 python-fastjsonschema 2.16.2 py39haa95532_0 python-gssapi 1.8.1 py39_1 esri python_abi 3.9 1_cp39 esri pytz 2022.6 py39_0 esri pywin32-ctypes 0.2.0 py39_0 esri pywin32-security 302 py39_1 esri pywinpty 2.0.1 py39_0 esri pyyaml 6.0 py39h2bbff1b_1 pyzmq 24.0.1 py39_1 esri qrcode 7.3.1 pypi_0 pypi regex 2022.7.9 py39h2bbff1b_0 requests 2.28.1 py39haa95532_0 requests-gssapi 1.2.3 py_2 esri requests-kerberos 0.12.0 0 esri requests-negotiate-sspi 0.5.3 py39_0 esri requests-oauthlib 1.3.0 py_0 requests-toolbelt 0.9.1 pyhd3eb1b0_0 rfc3986 1.5.0 pypi_0 pypi saspy 4.3.2 py_1 esri scipy 1.6.2 py39_0 esri seaborn 0.12.1 py39haa95532_0 selenium 3.141.0 pypi_0 pypi send2trash 1.8.0 pyhd3eb1b0_1 setuptools 65.5.1 py39_0 esri shiboken6 6.5.0 pypi_0 pypi six 1.16.0 py_0 esri sniffio 1.2.0 py39haa95532_1 sortedcontainers 2.4.0 pyhd3eb1b0_0 soupsieve 2.3.2.post1 py39haa95532_0 sqlalchemy 1.4.39 py39h2bbff1b_0 sqlite 3.40.1 0 esri stack_data 0.5.1 py_0 esri swat 1.12.0 py39_0 esri sympy 1.9 py39_1 esri tblib 1.7.0 pyhd3eb1b0_0 terminado 0.13.1 py39haa95532_0 testpath 0.5.0 py_0 esri tinycss2 1.1.1 py_0 esri toml 0.10.2 pyhd3eb1b0_0 tomli 2.0.1 py39haa95532_0 toolz 0.11.2 pyhd3eb1b0_0 tornado 6.1 py39h2bbff1b_0 tqdm 4.64.1 py39haa95532_0 traitlets 5.5.0 py_0 esri typed-ast 1.4.3 py39h2bbff1b_1 typing-extensions 4.3.0 py39haa95532_0 typing_extensions 4.3.0 py39haa95532_0 tzdata 2022e h04d1e81_0 ujson 5.4.0 py39hd77b12b_0 urllib3 1.26.12 py39haa95532_0 vc 14.2 h21ff451_1 vs2015_runtime 14.27.29016 h5e58377_2 esri wcwidth 0.2.5 pyhd3eb1b0_0 webencodings 0.5.1 py39haa95532_1 websocket-client 0.58.0 py39haa95532_4 wheel 0.37.1 pyhd3eb1b0_0 widgetsnbextension 3.6.1 py_0 esri win_inet_pton 1.1.0 py39_0 esri wincertstore 0.2 py39haa95532_2 winkerberos 0.8.0 py39_0 esri winpty 0.4.3 4 wrapt 1.14.1 py39h2bbff1b_0 x86cpu 0.4 py39_1 esri xarray 0.20.1 pyhd3eb1b0_1 xeus 0.24.1 8 esri xeus-python 0.8.2 10 esri xlrd 2.0.1 pyhd3eb1b0_0 xlwt 1.3.0 py39haa95532_0 xtl 0.6.15 1 esri xz 5.2.8 h8cc25b3_0 yaml 0.2.5 0 esri zeromq 4.3.4 0 esri zict 2.1.0 py39haa95532_0 zipp 3.8.0 py39haa95532_0 zlib 1.2.13 0 esri zlib-ng 2.0.6 1 esri zopfli 0.2.2 pypi_0 pypi zstd 1.5.2 h19a0ad4_0

yes i am using arcpy

nanaeaubry commented 1 year ago

This issue has been addressed and will be fixed in 2.2.0 release (September)

If things are still not working feel free to re-open