Esri / data-assistant

ArcGIS Pro Add-in that assists in emergency management, local government and state government data aggregation workflows.
Apache License 2.0
22 stars 8 forks source link

Loading a subset of source data #96

Closed MikeMillerGIS closed 7 years ago

MikeMillerGIS commented 7 years ago

When selecting a layer, the path to the dataset is stored, regardless if you picked a layer in the toc, a lyrx file or a location on disk. I would like to be able to load only a subset of source data. Can we add the definition expression to the xml or point to a lyrx file file or some other alternative?

This is required for the UN work we are doing.

SteveGrise commented 7 years ago

I think the solution will be to have a 'Source Where Clause' property that is similar to the current 'Replace By' clause for the Target dataset. We could probably default that to the definition query when a map layer is selected as an input.

The tools basically support Where clauses already because the Preview functionality has a row limit parameter that constructs a where clause. This functionality would have to be updated to utilize both Where clauses for the Preview functionality.

MikeMillerGIS commented 7 years ago

Talking with @ChrisBuscaglia, we would prefer the tool utilize a lyrx file and not store the expression. The lyrx file would be used to limit the results. If the user selects a layer in the TOC, the lyrx file could be written to the same workspace as the xml

ChrisBuscaglia commented 7 years ago

@MikeMillerGIS

Derived output GP tools (similar to what DA is) works on a selection set from a map layer. I was suggesting that DA will also work this way.

Workflow:

  1. Map has multiple layers (with def. queries potentially)
  2. Operator chooses a layer in the input dropdown (source)
  3. Operator may have already selected features for that layer, or now chooses to select features
  4. Source-target file is created, DA will write a layer file representing the selected layer (lyrx) to disk
  5. DA will use the layer (lyrx) file as input.

Am I understanding the requirement correctly?

Chris

SteveGrise commented 7 years ago

@ChrisBuscaglia @MikeMillerGIS I am using the .lyrx file approach for the new joined layer approach in development. We can take a look at that and discuss how to extend to other layers for the definition query. I was only concerned about the case where a user selects a feature service etc. that is not a map layer and they still want to have a definition query.

ChrisBuscaglia commented 7 years ago

@SteveGrise

Feature services can be added to the map as a layer, the intermediate dataset created is a FGDB.

If a user selects a subset of the feature service, the intermediate dataset would be a subset of the feature service (.lyrx created from it). Subsequent runs would use the .lyrx file to select the feature service input (source) and then create the intermediate dataset again from it.

SteveGrise commented 7 years ago

Looks like I can already use .lyrx files as inputs to the tools, will need to do some testing to verify functionality and ensure Definition queries work as expected.

SteveGrise commented 7 years ago

Append will not accept a .lyrx file as input: image

MikeMillerGIS commented 7 years ago

As discussed, can we try layer = arcpy.mp.layer('path to lyrx') layer_object = layer.listLayers()[0]

SteveGrise commented 7 years ago

Seems to be working with a few changes to other code: layer = arcpy.mp.LayerFile(source) view = layer.listLayers()[0]

SteveGrise commented 7 years ago

@MikeMillerGIS @pLeBlanc93 I'm struggling to pick up a layer file as a parameter. From what I am seeing the .lyrx file is converted to a layer before it is passed to the GP tool, then I don't have a way to get the file path of the original file...

image

SteveGrise commented 7 years ago

I think I have a solution with: source = arcpy.GetParameter(0) # source dataset to analyze sourceStr = arcpy.GetParameterAsText(0) # source dataset to analyze

then I replace the source value when the sourceStr value ends with .lyrx: def checkIsLayerFile(val,valStr):

for layer file parameters the value passed in is a layer but the string version of the layer is a path to the lyrx file...

if valStr.lower().endswith('.lyrx'):
    return valStr
else:
    return val
pLeBlanc93 commented 7 years ago

Yes, GP wraps layer(x) files that are passed as parameters as a special geoprocessing object that is slightly different.

Grabbing the parameter both ways was the best way I came up with as well.

SteveGrise commented 7 years ago

@pLeBlanc93 thanks!

previnWong commented 7 years ago

verified creating new config maintains the path to the chosen lyrx file. Have not verified if only subset of data copied over due to current append data issue.

MikeMillerGIS commented 7 years ago

Verified only subset of data was copied over