1

I have a point SHP in WGS84 (EPSG 4326) and I am trying to tabulate the distances to the nearest point in meters. I need to do the analysis using ArcPy, but I want to get the results in a Pandas dataframe to do other things.

I'm stuck on getting the GenerateNearTable_analysis() in an in-memory format (throws the error below). And then from there, I actually don't know how to pass it into a dataframe.

import arcpy
import pandas as pd

filein = [
    r'D:\mypath\test1.shp',
    r'D:\mypath\test2.shp',
]

for f in filein:
    fout = f.replace(".shp", "")
    TempTab = 'in_memory\\{}_Table'.format(fout)
    arcpy.GenerateNearTable_analysis(f, f, TempTab, method='GEODESIC')

Above throws this error:

arcgisscripting.ExecuteError: ERROR 000210: Cannot create output in_memory\D:\mypath\test_Table
Failed to execute (GenerateNearTable).

I also tried arcpy.GenerateNearTable_analysis(f, TempTab, "memory", method='GEODESIC') as suggested in this answer, and got the following error: arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Near Features: Dataset 'in_memory\D:\mypath\test_Table' does not exist or is not supported Failed to execute (GenerateNearTable).

Using ArcMap 10.7

1
  • 1
    At the moment you’re stuck on the ArcPy step that precedes what you’re trying to do with pandas. I think you should look at that 000210 error message and the invalid path it reports.
    – PolyGeo
    Jul 28 '20 at 20:50
3

You need to get rid of the directory as well as the file extension.

import os

import arcpy
import pandas as pd

filein = [
    r'D:\mypath\test1.shp',
    r'D:\mypath\test2.shp',
]

for f in filein:
    fout = os.path.splitext(os.path.basename(f))[0]  #<=== strip file extension and path
    TempTab = 'in_memory\\{}_Table'.format(fout)
    arcpy.GenerateNearTable_analysis(f, f, TempTab, method='GEODESIC')
1
  • Solved the issue, thank you. I added cols = [field.name for field in arcpy.ListFields(temp)] ... mydf = pd.DataFrame(arcpy.da.FeatureClassToNumPyArray(in_table=temp, field_names=cols, skip_nulls=False, null_value=-99999)) to get it into a Pandas dataframe
    – a11
    Jul 29 '20 at 0:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.