1

I am building a custom web app using the ArcGIS JS 4.8 API with an ArcGIS Web service and I have run into an issue.

The root cause that I am trying to fix is to do with features not being filtered out when I perform queries, due to them having duplicate ObjectID values.

I believe this is to do with left-joining non-spatial data to the spatial data since this is a time-based app (in essence, if a road or area requires maintenance every month, this app will have one spatial segment with multiple non-spatial segments, which duplicates the spatial unique ID).

The current table in our production environment looks like this, and when I perform queries on our data I will always see 10001, and 10002, even if I filter it to only show where objectID=10003

| OBJECTID | MAINTENANCEID |  MAINTENANCENAME  | DATE |
|==========|===============|===================|======|
| 10001    | 1             | Filter Sand in pit|2017  |
| 10001    | 2             | Filter Sand in pit|2018  |
| 10002    | 3             | Filter Sand in pit|2019  |
| 10002    | 4             | Mow field grass   |2018  |
| 10003    | 5             | Mow field grass   |2019  |

To fix this, I have created an SQL view of my spatial and non-spatial data with a composite unique ID made of the spatial and non-spatial unique id's, which is published through ArcMap as a Web Service. The new column is formatted very similarly to the NEW_OBJECTID field and is not a stored field but a dynamically generated identity value.

| OBJECTID | MAINTENANCEID |  MAINTENANCENAME  | DATE | NEW_OBJECTID |
|==========|===============|===================|======|==============|
| 10001    | 1             | Filter Sand in pit|2017  | 1000101      |
| 10001    | 2             | Filter Sand in pit|2018  | 1000102      |
| 10002    | 3             | Filter Sand in pit|2019  | 1000203      |
| 10002    | 4             | Mow field grass   |2018  | 1000204      |
| 10003    | 5             | Mow field grass   |2019  | 1000305      |

Unfortunately, when I try to display this web service data on a Map and MapView, I can not see the works using a JS FeatureLayer.

Inspecting the Web Service through the ArcGIS/rest/services/ online viewer, I can see and query the data. This, however, uses an ArcGIS API 3.25 ArcGISDynamicMapServiceLayer instead of an API 4.8 FeatureLayer.

The front-end code I am using is as simple as I could make it reduce errors, and I have tested it with the current production web service, and it shows correctly.

<script type="text/javascript">
require([
    "esri/Map",
    "esri/views/MapView",
    "esri/layers/FeatureLayer",
    "dojo/domReady!"
  ],
  function(
    Map, MapView,
    FeatureLayer
  ) {

  var map = new Map({
      basemap: "streets"
    });
  var view = new MapView({
    map: map,
    container:"map",
  });

    var layer = new FeatureLayer({url: "<MY_URL>"});
    map.add(layer);
    layer.when((x) => {console.log(x)})
});
</script>

Any insights on how I could debug or fix this?

  • 1
    One-to-many which results in non-unique rowid columns is in the realm of undefined behavior. You must put a unique value in the joined table. Beware that performance could suffer. A materialized view is a better bet. – Vince Sep 11 '18 at 3:53
  • Materialized view solved it! making the new composite unique value an index seems to have allowed it select it properly and display it in a feature class. Thank you! – Byren Higgin Sep 12 '18 at 0:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.