How to make a new layer from selected features within a view

2168
7
01-18-2021 08:15 AM
Labels (3)
ChuckBenton
Occasional Contributor

I have a large hosted feature layer on ArcGIS Online. I can load it into a map using ArcGIS Pro, then make a Selection using Attributes, then right click on the feature layer and make a new layer from the selection. I then use the Feature Class to Shapefile tool to save it to disk.

We have multiple clients that access this layer, and we manage their access using Views, tailored to match their geographical area of interest (e.g. subscription). They need to save content to disk for selections they make.

When the process is applied to a view, the "Make Layer from Selected Features" is not offered. I've tried enabling editing and so forth in the Settings for the view, without any impact.

Is there a workflow that enables a view selection to be saved to disk as actual content, as opposed to a pointer to the content?

Thanks in advance for helping!

Chuck 

0 Kudos
7 Replies
DanPatterson
MVP Esteemed Contributor

Did you try

Feature Class To Feature Class (Conversion)—ArcGIS Pro | Documentation

I don't have data of your type to test

The location in which the output feature class will be created. This can be either a geodatabase or a folder. If the output location is a folder, the output will be a shapefile.

You will get a shapefile if the output is a folder


... sort of retired...
0 Kudos
ChuckBenton
Occasional Contributor

Thanks Dan. When I run that I get a "Failed to load a resource" error, which is common for this layer, which is 600GB (at one point the largest ever in ArcGIS Online). Esri's had a support case open on this since July and made no progress.

To work around, with a regular feature layer I do the selection and then isolate the selection into a standalone layer, which then allows me to save it to disk. It appears that a view doesn't allow the conversion to a standalone layer.

I've attached 2 screenshots, one showing the "Make Layer from selected features" option I get when accessing a feature layer, and the other the lack of that option when accessing the same feature layer via a view.

Any suggestions are most welcome!

Chuck

0 Kudos
BWang
by
New Contributor

Hi Chuck,

I'm trying to test it with my data. But I don't seem to have the same layer you are working with and don't have the drop-down menu you see without the Selection option. Can you share how you created the view out of the Hosted Feature Layer on ArcGIS Online?

In my test, I'm still having the Selection in my drop-down menu after creating the view out of the hosted layer.

0 Kudos
ChuckBenton
Occasional Contributor

Here's the Python script I use to create the view. 

Note that the source feature layer shows in my content as a "Feature Layer (hosted)", whereas the View shows as a "Feature Layer (Hosted, View)

from arcgis import GIS
from arcgis.features import FeatureLayerCollection
print("started")
import json
import os
import csv

view_name = "ParcelAtlas Features V2.4 - Example View"
firstFIPS = "18069"

# Login to the GIS
gis = GIS("https://www.arcgis.com", "chuckb", "xxxxxxxxxx")

# delete view if exists
items = ''
gis.content.search(query = view_name)
if items:
view_exists = gis.content.get(items[0].itemid)
print("view deleted: " + str(items[0].itemid))
view_exists.delete()

#This is the feature layer we are creating a view into
source_fl_id = '33518827e9e24defbacd671bfdXXXXX'
src_item = gis.content.get(source_fl_id)
source_fl = FeatureLayerCollection.fromitem(src_item)

# Create View from Source Hosted Feature Layer
new_view = source_fl.manager.create_view(name=view_name)

# Search for newly created View
view_search = gis.content.search(view_name)[0]
view_flc = FeatureLayerCollection.fromitem(view_search)

# The viewDefinitionQuery property appears under layers
view_layer = view_flc.layers[0]

#Now open a txt file that has all the counties (FIPS) we want to incljude in the view
f = open(r'C:\\PA_Work_Folder\\'+view_name+'.txt')
csv_f = csv.reader(f)

#scan all FIPS and build string
FIPS = "FIPS IN ("
for row in csv_f:
#print(row[0])
if row[0] == firstFIPS: FIPS = FIPS + firstFIPS
else: FIPS = FIPS + ", " + row[0]
FIPS = FIPS + ")"
print(FIPS)
view_def = {"viewDefinitionQuery" : str(FIPS)}
# Update the definition to include the view definition query
view_layer.manager.update_definition(view_def)

print ("done")

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

Code formatting ... the Community Version - GeoNet, The Esri Community

your indentation is wrong, unless code formatting fixes


... sort of retired...
0 Kudos
ChuckBenton
Occasional Contributor

The indents were lost in the cut and paste, its a script that's been in use for over a year. The script is provided to answer the earlier question of how I create a view, which is successfully done. The issue is more about how a view of a feature layer is hobbled in the ability to save to disk when compared to the direct feature layer. BWang, if you provide me an ArcGIS Online username I can add you to a group so you can see it firsthand.

0 Kudos
RamonWilliams
New Contributor III

good morning All,

when using the line below how do I make it put to a certain layer in the feature layer.  Feature layer hosted  xxxxxxxxxxxxxx has like twenty layers and I want it to point to a certain one like sub layer 7

source_search = gis.content.search("xxxxxxxxxxxxxx")[0]
source_flc = FeatureLayerCollection.fromitem(source_search)

 

0 Kudos