I am attempting to download data from ArcGIS REST services in ArcGIS Pro using custom geometry. After some help, I’ve managed to get this to work and save the data as a shapefile. The data I’m downloading contains a “date_time” field, and only the “date” portion is being returned. After doing some reading, I’ve learned that shapefiles cannot store date_time. I tried saving to a gdb, but it was more complicated than I expected, and I’m a beginner.
Is there a simple way to save this to a gdb and retain “date_time”?
Or modify the query to calculate a “date” and “time” column separately?
Or return “date_time” as a string that I can then convert to “date” and “time” manually?
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.geometry.filters import intersects
gis = GIS("pro")
#The ESRI JSON used to subset the REST data
geometry = {
"spatialReference": {"wkid": 4326},
"rings": [
[
["-124.785944", "49.142568"],
["-125.439631", "50.001049"],
["-124.928766", "50.335311"],
["-123.735655", "49.654732"],
["-124.404157", "49.265739"],
["-124.785944", "49.142568"]
]
]
}
# The REST service URL
rest_service_url = "https://gisp.dfo-mpo.gc.ca/arcgis/rest/services/FGP/MSDI_Dynamic_Current_Layer/MapServer/0"
# Access the feature layer using the REST service URL
layer = FeatureLayer(rest_service_url)
# Query the feature layer
features = layer.query(where="1=1", geometry_filter=intersects(geometry, 4326))
print(f"Number of features found: {len(features.features)}")
# Save to local Dir
output_dir = r"C:UsersnameDocuments"
# Save features to shp
features.save(output_dir, "currents.shp")
Thanks!