How to create a hosted feature service view with different layers to parent service?

1199
6
Jump to solution
01-08-2019 09:30 PM
AnthonyCheesman1
Occasional Contributor II

Hi - I'm hoping that someone can assist me with this query. I have been unable to solve it on my own.

I have a hosted feature service in AGOL that is accessed by multiple users for feature creation. It consists of 12 different layers - point, line and polygon, across 4 different environments (development, user acceptance, training and production). The sequence is:

/0 - DEV points

/1 - DEV lines

/2 - DEV polygons

...

through to 

...

/9 PROD points

/10 PROD lines

/11 PROD polygons

For the purposes of consuming this data in another web app, I would like to create 4 different view layers, one for each of the operating environments (DEV, UAT, TRAIN, PROD). In this view layer I would like to reference the source twice to capture different time slices of the data, eg:

DEV_VIEW

/0 - points - would be a view of source layer /0, with only features created < 24 hours

/1 - points - would be a view of source layer /0, with only features created >= 24 hours

/2 - lines - would be a view of source layer /1, with only features created < 24 hours

/3 - lines - would be a view of source layer /1, with only features created >= 24 hours

/4 - polys - would be a view of source layer /2, with only features created < 24 hours

/5 - polys - would be a view of source layer /2, with only features created >= 24 hours

...

...

...

PROD_VIEW

/0 - points - would be a view of source layer /9, with only features created < 24 hours

/1 - points - would be a view of source layer /9, with only features created >= 24 hours

/2 - lines - would be a view of source layer /10, with only features created < 24 hours

/3 - lines - would be a view of source layer /10, with only features created >= 24 hours

/4 - polys - would be a view of source layer /11, with only features created < 24 hours

/5 - polys - would be a view of source layer /11, with only features created >= 24 hours

I cannot for the life of me work out how to do this - is it even possible? The capability doesn't seem to be supported from within AGOL, and I can't work out whether ArcGIS Pro has the capability to create a feature service view in such a fashion.

My only thought at present is that it may be potentially possible by directly manipulating the JSON of a view layer, although this seems overwhelming and something I'd like to avoid if possible.

Does anyone have any advice?

Thanks

Anthony

0 Kudos
1 Solution

Accepted Solutions
KhaledHassen
Esri Contributor

Yes this is doable as long as the view is created from the same parent service. The steps are:

1. Create an empty service using portal API with "isView" = true

2. Use the Feature service addToDefinition admin API to add a view layer based on the parent source feature service. You can add a definition expression in the layer metadata. The json used here can be something like:

https://..../ArcGIS/rest/admin/services/<myViewSerivceName/FeatureServer/addToDefinition

{

  "layers" : [

    {

      "adminLayerInfo" : {

          "viewLayerDefinition" :

          {

            "sourceServiceName" : "<source service name>",

            "sourceLayerId" : <source layerId>,

            "sourceLayerFields" :  "*"

          }

      },

      "name" : "<name of the view layer",  // Can be different from the source layer

      "displayField": "",   "description": "",

      "copyrightText": "",

      "defaultVisibility" : true,

  "drawingInfo":{"renderer":{"type":"simple","symbol":{"type":"esriSFS","style":"esriSFSSolid","color":[76,129,205,191],"outline":{"type":"esriSLS","style":"esriSLSSolid","color":[0,0,0,255],"width":0.75}}},"transparency":0,"labelingInfo":null},

      "allowGeometryUpdates" : true,

      "htmlPopupType" : "esriServerHTMLPopupTypeNone",

      "maxRecordCount" : 1000,  

      "maxRecordCountFactor" : 1,

      "definitionQuery" : "Status = 'some name'"  // your time definition expression. Note pl. use sql'92 date query

      }

  ]

}

 

You can add as many layers as you want to each view as long as you reference the same parent service.

Note: You can also do the above using the UX by creating a view from the source that has all source layers and then drops what you do not need using feature service deleteFromDefinition.

https://..../ArcGIS/rest/admin/services/<myViewSerivceName/FeatureServer/deleteFromToDefinition

 

{

    "layers"  : [

    {

       "id": 2  // This is the layerId that you do not want in the view

    },

   {

      "id" : 3"

   }

  ]

}

Hope that helps.

Khaled Hassen

Online feature service Lead 

View solution in original post

6 Replies
JayantaPoddar
MVP Esteemed Contributor

Hosted Feature Layer Views could be the answer to your problems. Please explore for more details.



Think Location
AnthonyCheesman1
Occasional Contributor II

Hi Jayanta - a hosted feature layer view is exactly what I'm trying to create, however I need the structure of the view to be different to the hosted feature service.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Can you elaborate on, "I need the structure of the view to be different to the hosted feature service." 

0 Kudos
ChelseaRozek
MVP Regular Contributor

Do you have editor tracking enabled so you have a field saying when the features were created? There are some examples around GeoNet of people editing the JSON to then make a dynamic date filter on the layer based on that field. https://community.esri.com/docs/DOC-8191-dynamic-date-filter  I haven't tried this myself though. Do you need views? I would just add the layers to a new webmap, filter based on datetime by editing the JSON, and disable editing on these layers if it's only for viewing in the web app. Since you said you want to avoid JSON edits, you could also use Arcade to symbolize based on age instead of making separate layers. Also, not great for your situation since you're just in AGO, but in one of my apps, we host on our own ArcGIS server, so when I published the .mxd I placed a definition query on the layer there to only show the features from the past month.

0 Kudos
KhaledHassen
Esri Contributor

Yes this is doable as long as the view is created from the same parent service. The steps are:

1. Create an empty service using portal API with "isView" = true

2. Use the Feature service addToDefinition admin API to add a view layer based on the parent source feature service. You can add a definition expression in the layer metadata. The json used here can be something like:

https://..../ArcGIS/rest/admin/services/<myViewSerivceName/FeatureServer/addToDefinition

{

  "layers" : [

    {

      "adminLayerInfo" : {

          "viewLayerDefinition" :

          {

            "sourceServiceName" : "<source service name>",

            "sourceLayerId" : <source layerId>,

            "sourceLayerFields" :  "*"

          }

      },

      "name" : "<name of the view layer",  // Can be different from the source layer

      "displayField": "",   "description": "",

      "copyrightText": "",

      "defaultVisibility" : true,

  "drawingInfo":{"renderer":{"type":"simple","symbol":{"type":"esriSFS","style":"esriSFSSolid","color":[76,129,205,191],"outline":{"type":"esriSLS","style":"esriSLSSolid","color":[0,0,0,255],"width":0.75}}},"transparency":0,"labelingInfo":null},

      "allowGeometryUpdates" : true,

      "htmlPopupType" : "esriServerHTMLPopupTypeNone",

      "maxRecordCount" : 1000,  

      "maxRecordCountFactor" : 1,

      "definitionQuery" : "Status = 'some name'"  // your time definition expression. Note pl. use sql'92 date query

      }

  ]

}

 

You can add as many layers as you want to each view as long as you reference the same parent service.

Note: You can also do the above using the UX by creating a view from the source that has all source layers and then drops what you do not need using feature service deleteFromDefinition.

https://..../ArcGIS/rest/admin/services/<myViewSerivceName/FeatureServer/deleteFromToDefinition

 

{

    "layers"  : [

    {

       "id": 2  // This is the layerId that you do not want in the view

    },

   {

      "id" : 3"

   }

  ]

}

Hope that helps.

Khaled Hassen

Online feature service Lead 

AnthonyCheesman1
Occasional Contributor II

Thanks Khaled, this is excellent information, and looks as though it may solve my issue!

0 Kudos