I cannot understand how to use the values in the arrays created with arcpy.FeaturesToNumPyArray.
I want to create an array and then convert them to a pandas DataFrame. So I created an array from FeaturesToNumPyArray and tried to extract "SHAPE@XY" values. But the problem is the values are stored in some kind of 2 dimensional arrays. I thought it would be easy to split them vertically with numpy.vsplit but Python tells that the array is not a 2 dimensional.
If possible I would like to covert all table values into a DataFrame, and then use for some calculations because I think that would be easy to calculate and easy to see the codes afterwards.
The codes are like this. The FeatureClass I used here are just points with X and Y coordinates plus few additional information. Points will be extracted via Python Script tool (ArcToolBox).
import arcpy import numpy as np import pandas as pd shp = inPointShape arr = arcpy.da.FeatureClassToNumPyArray(shp, ["SHAPE@XY"]) df = pd.DataFrame(arr, columns=["X","Y"])
This doesn't cause an error but no values are passed.
However, when I print the array (the SHAPE@XY) it shows as below.
[([141.20304792, 39.71085087],) ([141.03026594, 39.69363465],) ([141.7986943 , 39.29263103],) ([140.95115842, 39.23922211],)]
By avoiding "SHAPE@XY" and converting to DataFrame works fine as shown below. But I want to do this by including "SHAPE@XY" as well.
fieldNames = [f.name for f in arcpy.ListFields(shp)] df = pd.DataFrame() for i, item in enumerate(fieldNames): if item.upper() == "SHAPE": continue df[str(item)] = arr[str(item)]
Is there anyway to extract "SHAPE@XY"?