10-11-2021
02:40 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
Hi,
I broke up the chain so you can better see what needs to happen:
- In your case, you start with an item.
- You access a layer in that item and query it with your predefined sql.
- The result is a FeatureSet object.
- Create an SEDF from the FeatureSet object.
- 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.