Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.89k stars 1.1k forks source link

take layer offline devlab #177

Closed mpayson closed 6 years ago

mpayson commented 6 years ago

Creating a devlab per:

Lab Description
Take data offline using spatial dataframe Show how to query feature layers into a dataframe and then write to a shape file or fgdb. Converse of import data

A few questions:

  1. Should I skip the dataframe since the save function is on a feature_set? We could then leave it as a challenge to create the dataframe and maybe a simple operation on that dataframe?
  2. Can I save to a shape file or fgdb on a Mac, it says ArcPy is required for shape files?
  3. Should the initial service query return all features or only a subset?

Pushing here

Thanks!

@AtmaMani @jyaistMap

AtmaMani commented 6 years ago

@mpayson

  1. yes, showing save functionality is appropriate and I like the idea of saving to other formats in the challenge section
  2. You can save on OSX, Linux. We need pyshp for IO with shape files and fiona for fgdb. The fiona part is still under dev, not available in production at 1.3. So you might want to show saving to shape file now and update it to fgdb later
  3. I think it is save to query a subset, this way we don't run out of memory and is generally a good pattern to show case. Additionally, the sample teaches how to specify queries.
rohitgeo commented 6 years ago

There are multiple ways to export feature data to shp or fgdb:

I think we should promote the first two approaches for exporting to shp and fgdb as they don't need pyshp or arcpy on the client. The third approach is mainly to get data into a SpatialDataFrame. Saving the spatial dataframe to a file could be a separate lab.

I find getting a dataframe out of a layer the most valuable for analysis.

The simplified code could be:

from arcgis.gis import GIS
from arcgis.features import SpatialDataFrame

gis = GIS(username="<USERNAME>")

items = gis.content.search(query='Griffith', 'Feature Layer')
feature_layer_item = items[0]
feature_layer = feature_layer_item.layers[0]

sdf = SpatialDataFrame.from_layer(layer)
sdf.head()
mpayson commented 6 years ago

appreciate the feedback @rohitgeo @AtmaMani ! Should I change this lab to just get a dataframe per Rohit's snippet?

rohitgeo commented 6 years ago

Yes, let's do that. We can then write the SpatialDataFrame to disk using the to_featureclass() method.