Hello,
In Survey123 I am trying to query a DEM raster layer from map lick or coordinates with pulldata @layer but cannot find how to read the stretch.pixel value. Under the layer's service page, Fields is None so not sure what to put in for "attributes"
I have tried to use javascript to perform the action but am running in to issues with the returned json. I am connected through an Enterprise account but if I use the parent url the below script returns the error 'Token Required'. The error in Survey123 is always the same. I can use a child layer and paste the identify url in a browser but it will only return the layer attributes, never the value of the coordinates.
This script creates the following url (I have removed the url and lat/lon info)
<url>/identify?geometry=%7B"x"%3A<lon>%2C"y"%3A<lat>%2C"spatialReference"%3A%7B"wkid"%3A4326%7D%7D&geometryType=esriGeometryPoint&returnGeometry=false&returnCatalogItems=false&f=json
// rasterPixelValue.js// Call from XLSForm: pulldata("@javascript", "rasterPixelValue.js", "getRasterValue", imageServiceUrl, longitude, latitude) function getRasterValue(imageServiceUrl, longitude, latitude) {// Validate inputsif (!imageServiceUrl || !longitude || !latitude) {return "Error: Missing required parameters (imageServiceUrl, longitude, latitude)";} // Convert coordinates to numbersconst lon = parseFloat(longitude);const lat = parseFloat(latitude); if (isNaN(lon) || isNaN(lat)) {return "Error: Invalid coordinates";} try {// Build the identify request URLconst identifyUrl = imageServiceUrl.endsWith('/')? imageServiceUrl + 'identify': imageServiceUrl + '/identify'; // Create the geometry parameterconst geometry = JSON.stringify({x: lon,y: lat,spatialReference: { wkid: 4326 }}); // Build request parameters manuallyconst params = ['geometry=' + encodeURIComponent(geometry),'geometryType=esriGeometryPoint','returnGeometry=false','returnCatalogItems=false','f=json']; const requestUrl = identifyUrl + '?' + params.join('&'); // Make synchronous request (required for Survey123 pulldata functions)const xhr = new XMLHttpRequest();xhr.open('GET', requestUrl, false); // false = synchronousxhr.withCredentials = true;xhr.send(); if (xhr.status === 200) {const response = JSON.parse(xhr.responseText); // Check for errors in responseif (response.error) {return "Error: " + response.error.message + " " +requestUrl;} // Extract pixel valuelet pixelValue = null; if (response.value !== undefined && response.value !== null) {pixelValue = response.value;} else if (response.values && response.values.length > 0) {// For multi-band rasters, return first band or comma-separated valuespixelValue = response.values.length === 1 ? response.values[0] : response.values.join(',');} else if (response.properties && Object.keys(response.properties).length > 0) {// Sometimes pixel data is in propertiesconst keys = Object.keys(response.properties);pixelValue = response.properties[keys[0]]; // Return first property value} // Return the pixel value or "No Data" if null/undefinedreturn pixelValue !== null && pixelValue !== undefined ? pixelValue.toString() : "No Data"; } else {return "Error: HTTP " + xhr.status + " - Unable to query image service";} } catch (error) {return "Error: " + error.message;}}
// rasterPixelValue.js
// Call from XLSForm: pulldata("@javascript", "rasterPixelValue.js", "getRasterValue", imageServiceUrl, longitude, latitude)
function getRasterValue(imageServiceUrl, longitude, latitude) {
// Validate inputs
if (!imageServiceUrl || !longitude || !latitude) {
return "Error: Missing required parameters (imageServiceUrl, longitude, latitude)";
}
// Convert coordinates to numbers
const lon = parseFloat(longitude);
const lat = parseFloat(latitude);
if (isNaN(lon) || isNaN(lat)) {
return "Error: Invalid coordinates";
try {
// Build the identify request URL
const identifyUrl = imageServiceUrl.endsWith('/')
? imageServiceUrl + 'identify'
: imageServiceUrl + '/identify';
// Create the geometry parameter
const geometry = JSON.stringify({
x: lon,
y: lat,
spatialReference: { wkid: 4326 }
});
// Build request parameters manually
const params = [
'geometry=' + encodeURIComponent(geometry),
'geometryType=esriGeometryPoint',
'returnGeometry=false',
'returnCatalogItems=false',
'f=json'
];
const requestUrl = identifyUrl + '?' + params.join('&');
// Make synchronous request (required for Survey123 pulldata functions)
const xhr = new XMLHttpRequest();
xhr.open('GET', requestUrl, false); // false = synchronous
xhr.withCredentials = true;
xhr.send();
if (xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
// Check for errors in response
if (response.error) {
return "Error: " + response.error.message + " " +requestUrl;
// Extract pixel value
let pixelValue = null;
if (response.value !== undefined && response.value !== null) {
pixelValue = response.value;
} else if (response.values && response.values.length > 0) {
// For multi-band rasters, return first band or comma-separated values
pixelValue = response.values.length === 1 ? response.values[0] : response.values.join(',');
} else if (response.properties && Object.keys(response.properties).length > 0) {
// Sometimes pixel data is in properties
const keys = Object.keys(response.properties);
pixelValue = response.properties[keys[0]]; // Return first property value
// Return the pixel value or "No Data" if null/undefined
return pixelValue !== null && pixelValue !== undefined ? pixelValue.toString() : "No Data";
} else {
return "Error: HTTP " + xhr.status + " - Unable to query image service";
} catch (error) {
return "Error: " + error.message;
How big is your area of interest and what level of detail do you need the results? I know DEMs are large when converted to vector even larger, but if you had a small are of interest and could generalize the DEM a bit, you could convert it to a polygon layer and the use the point in polygon pulldata method.
Survey123 pulldata(@layer is for feature layers, feature tables or query enabled map services.
https://doc.arcgis.com/en/survey123/desktop/create-surveys/xlsformformulas.htm#ESRI_SECTION1_BB97985CAFB740EE8AEF99EFD6E238E3
You may be able to achieve this with JavaScript e.g. here's a starting point:
https://community.esri.com/t5/arcgis-survey123-questions/survey123-javascript-extension-identify-pixel/td-p/779967
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.