Let's suppose you next want to use the view to show only earthquakes that occurred before the year 1988. Reviewing the Data tab of the view's Item Details, you see that you can filter by a column year_:

When you set a View Definition, that definition is defined at the service level. If you quickly set a test definition in the ArcGIS Online/Portal for ArcGIS user interface and take a look at the view service's Service Definition, you'll see the property that needs to be updated is viewDefinitionQuery:

Click on 'View' in the View's Item Details page

Next, click on the Layer:

Click on 'JSON'

Scroll all the way to the bottom to see the 'viewDefinitionQuery' property:

Note: changing the value of viewDefinitionQuery also updates the related definitionQuery property

To update the viewDefinitionQueryproperty with the ArcGIS API for Python, you do the following:

I'm trying to use API to create featurelayer views for each city based on a province feature layer, for example set the view's "viewDefinitionQuery" as " AOIname = 'Toronto' " using following code.

# Define a SQL query to filter

update_dict = {"viewDefinitionQuery" : "AOIname = 'Toronto'"}

# Update the definition to include the view definition queryservice_layer.manager.update_definition(update_dict)

Ideally, the new_created view should have a spatial extent as the city's boundary. However, After running above code, if you check the item detail > Visualization > Filter (as in following picture), you will found that the Filter in Visualization is empty. To make viewer extent zoom to city's boundary, you have to MANUALLY create a same definition query like AOIname = 'Toronto' , then click "Apply Filter and ZoomTo" .

I just want to know, does API support to set this spatial extent "Filter" definition query? It is a similar function like "Recalculate Feature Class Extent" tool in ArcGIS Pro.

Yes, Earl Medina is right: I had exactly the same challenge as you have. I had the geometry of - in my case 12 - provinces and I wanted to create 12 views using the provincial boundaries as 'Area of Interest'.

Please let us know whether you managed to create the views for Toronto and the other cities using the script in my blog: