Hi esri community,
I'm trying to upload a locally saved excel file as a feature layer but I keep running into the "Job Failed" error, very similar to a post I saw regarding the same issue here.
This is the code I've written so far:
import arcgis import os import datetime as dt import pandas as pd from arcgis.gis import GIS from arcgis.features import GeoAccessor, GeoSeriesAccessor from numpy.random import rand gis = GIS() agol_gis = GIS("organization link","username","password") # Loading in the Bight data bight = pd.read_excel(r'C:\Users\GisUser\Desktop\bight18-field-clean.xlsx', sheet_name = "grab", header = 0) sdf = GeoAccessor.from_xy(bight, 'latitude','longitude') lyr = sdf.spatial.to_featurelayer('bight18grabtest', gis=agol_gis)
I am currently using VS Code and my environment seems up to date. Is there something I am missing here? Any help on this is greatly appreciated!
Best,
Mina
Solved! Go to Solution.
Publishing a layer from a dataframe has given me trouble in the past, too. What about creating an empty layer first, then using your dataframe to load features into it?
destination_layer.edit_features(adds=sdf.spatial.to_featureset())
Publishing a layer from a dataframe has given me trouble in the past, too. What about creating an empty layer first, then using your dataframe to load features into it?
destination_layer.edit_features(adds=sdf.spatial.to_featureset())
Hi @jcarlson I would have never guessed that! I appreciate the insight.
Hi @jcarlson ,
So I ended up going a different route. I transformed the data frame into a spatially enabled dataframe (sdf) and tried to simply plot the sdf using spatial.plot. The webmap shows another layer from AGOL but not the points from the sdf.
My goal is a simple point-in-polygon check to see if points fall within another layer's boundaries.
import arcgis
import os
import datetime as dt
import pandas as pd
from arcgis.gis import GIS
from arcgis.features import GeoAccessor, GeoSeriesAccessor
from numpy.random import rand
from arcgis.geometry import Geometry
from arcgis.geometry.filters import within
from arcgis.geometry.filters import contains
from arcgis.geocoding import geocode
from arcgis.geometry import lengths, areas_and_lengths, project
from arcgis.geometry import Point, Polyline, Polygon, Geometry
from arcgis.mapping import WebMap
# Loading in the Bight data
bight = pd.read_excel(r'C:\Users\GisUser\Desktop\bight2018_clean.xlsx', sheet_name = "grab", header = 0)
bight.columns = bight.columns.str.lower() # Lowercase all columns for consistency
bight
# Creating a spatially enabled dataframe from loaded data
sdf = GeoAccessor.from_xy(bight, 'latitude','longitude')
sdf
# Creating point object from the dataframe
pt = Point({"x": sdf["latitude"], "y": sdf["longitude"]})
# Calling on the Strata layer using portal item id
strata = gis.content.get('387791e1c66b4ae6bbadda60848ddecc')
strata
query1 = strata.layers[0].query()
resp1 = query1.features
resp1[0].geometry
strataLayer = Geometry(resp1[0].geometry)
strataLayer
# Create map / add layer to map
wm = gis.map("California")
wm.add_layer(strata)
wm
print(pt.within(strataLayer))
The output from both the "within" and "contains" function are "None" but I know there are points within the polygon. Any insight on how I can get this to script to work?
Hm. Can you double-check the spatial reference of each layer?
Yes. Both have the same spatial reference:
strata.spatialReference
# '102100'
p.spatialReference
#{'wkid': 102100}
Point and Geometry would both return a singular object, right? What about creating a GeoSeriesAccessor from the geometry columns of your dataframes, then using overlay operations with those?