Grouping Large Quantity of Unique Values

821
7
Jump to solution
08-08-2022 01:04 PM
MollyWhitener
New Contributor

I'm trying to create a map of our company's sales territories. The territories are organized by zip codes, so I'm using a feature layer that shows all zip codes, but I'm trying to use unique values to color each zip code according to which territory it belongs to. We have some 27K zip codes that we cover. Just sending in the whole array of all 27K zip codes seems to crash it 😅

I've had some luck if I create a separate renderer and feature layer for each territory, but I've only tried it with 3 of the 15 territories (attached pic). When I tried to create a renderer and feature layer for each territory using a forEach loop, this also crashed the map.

Does anyone have any idea of how I could accomplish this client-side? I considered making my own hosted layer, but since we use Azure SQL to manage our data, this is not ideal, nor do we have the zip code polygon coordinates. 

 

 

symbolList: [
{
   symbol: {
      color:"crimson",
      type:"simple-fill"
   },
   value: "65564"
},
{
   symbol: {
      color:"crimson",
      type:"simple-fill"
   },
   value:"72644"
},
etc x 27,000...
]

 const zipRenderer = {
            type: "unique-value",
            field: "ZIP_CODE",
            uniqueValueInfos: this.symbolList
        }

const featureLayer = new FeatureLayer({
          url: "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Boundaries_2021/FeatureServer/3",
          renderer: zipRenderer,
          opacity: 0.4,
        });

map.add(featureLayer);

 

 

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

Ok...I was assuming you already had it set up with each territory layer only having the expected features.  In this case, for each layer, you'd also need to filter only the features you want.  You can accomplish this by setting the definitionExpression and (possibly) the fullExtent properties.  If using only the definitionExpression, the smallest possible value could still become quite large.  Therefore, a possible alternative would be using the fullExtent to define the MBR for the features you want, and then using definitionExpression to remove the "extras", which could dramatically reduce the size of the definitionExpression.

View solution in original post

0 Kudos
7 Replies
JoelBennett
MVP Regular Contributor

It seems to me that if you broke the territories out into individual layers (like you already mentioned), but used a SimpleRenderer instead, you would get much better performance, since that would result in 15 symbols rather than 27,000.

0 Kudos
MollyWhitener
New Contributor

I'm not sure that will work since the zip codes don't always go in order 😟 but it does load much more quickly.

0 Kudos
JoelBennett
MVP Regular Contributor

Ok...I was assuming you already had it set up with each territory layer only having the expected features.  In this case, for each layer, you'd also need to filter only the features you want.  You can accomplish this by setting the definitionExpression and (possibly) the fullExtent properties.  If using only the definitionExpression, the smallest possible value could still become quite large.  Therefore, a possible alternative would be using the fullExtent to define the MBR for the features you want, and then using definitionExpression to remove the "extras", which could dramatically reduce the size of the definitionExpression.

0 Kudos
MollyWhitener
New Contributor

I tried a lot of different things, but I finally ended up creating a layer with a definitionExpression and its own simpleRenderer for each territory. It's less ideal than I'd like, but all territories do load on the map now, and I tried to somewhat encapsulate the repetition of making a layer and renderer and adding it to the map. 

Thanks!

0 Kudos
KristianEkenes
Esri Regular Contributor

Are you able to add a new field to the table to indicate which sales area the zip code belongs to? How are you managing the data for which zip codes belong to each sales area? If you had a separate field for the area, you would only need to define 3 unique value infos and I would expect performance to work just fine. 

If you are unable to add a new field to the underlying data, you can also write an Arcade expression to return the sales area name/id based on the zip code value. This would be a large expression, but I imagine you could use the same logic you're currently using in JavaScript to set the colors as you do in the Arcade... This would also only require you setting up one symbol per sales area. This sample demonstrates how you could set up the classification with Arcade: https://developers.arcgis.com/javascript/latest/sample-code/visualization-arcade/ 

Hopefully that helps.

0 Kudos
MollyWhitener
New Contributor

I tried to use Arcade expressions, but since some of the territories cover 1,000+ zip codes, it was too difficult to use those. I also tried to host my territory info so I could do a dynamic layer, but I could not figure out how to upload a table with no geometry in it. Thanks for your help!

0 Kudos
KristianEkenes
Esri Regular Contributor

I just re-read your post and now see how the data is managed 😅. You should be able to use Arcade in this scenario.

0 Kudos