emedina
Regular Contributor

Hi,

I broke up the chain so you can better see what needs to happen:

  1. In your case, you start with an item.
  2. You access a layer in that item and query it with your predefined sql.
  3. The result is a FeatureSet object.
  4. Create an SEDF from the FeatureSet object.
  5. Use spatial.tofeatureclass() to save to a shapefile/Feature Class.

 

As you noted, you could actually stop at #3 and use FeatureSet's save method. In my experience, this method is not as reliable as working through a SEDF.

 

 

from arcgis.gis import GIS
gis = GIS(url, user_name, password)
sql = "CreationDate > date'2019-01-01 00:00:00 AM' AND CreationDate < date'2020-01-01 00:00:00 AM'"
item = gis.content.get(itemid)
fs = item.layers[0].query(sql)
sdf = fs.sdf
sdf.spatial.to_featureclass(location=r"c:\output_examples\your.gdb\test")

 

 

Can you tell us what happens when you try the above? It seems this is what you actually want? What I got out of your explanation is that you both want to download the data locally and publish the result as a Feature Layer.

0 Kudos