Smart M.App discussions

Looking for answers in regards to M.Apps, M.App Exchange or M.App Studio? Smart M.App Tech Discussion board is where you can search, ask your questions and assist others by sharing your knowledge. Join the conversation, connect, contribute and share.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Frequent Contributor
Posts: 83
Registered: ‎07-17-2017
Accepted Solution

How to store or display recipe output with format table or scalar in Smart M.App?

Hi everyone,

 

I have a recipe which has a scalar as output (in this case the sum of all raster cells of an image). I need to display this result in my Smart M.App but I'm stuck just runnig the recipe on the platform because there appears no input dialog for a filename when I launch the app. So it says that there is no output specified in this job (sure it's not because I'm not asked to enter one). (See the output part of my recipe attached)

So my question is: Is it generally possible to store any output of a recipe in Chest or use this output within a Smart M.App (like displaying the number in a text field) which is neither a shapefile nore an image but a scalar or a table?

And second: How can I do this?

 

Thanks for your help!

Marisa

Highlighted
Frequent Contributor
Posts: 103
Registered: ‎01-20-2016

Re: How to store or display recipe output with format table or scalar in Smart M.App?

Hi Marisa,

 

I'm afraid this is a quite complex task.

I had a similar case where the grey values of my raster file displayed in the map should be grabbed and used for the creation of a chart.

The solution was to output the list of values, save it in a txt-file on M.App Chest, open this file again, read the values and use it for the chart creation in the app. There is an output operator for txt or json files available. Since I don't have access at the moment, I don't remember well which one I used.

The whole procedure was done by Javascript coding. Now, if I click on a pixel in my image, it takes 3 to 6 seconds to receive the values back in the app and to update the chart.

 

But maybe in the meantime, there is a more straight-forward solution available!

 

Best regards,

Ruth

Highlighted
Frequent Contributor
Posts: 83
Registered: ‎07-17-2017

Re: How to store or display recipe output with format table or scalar in Smart M.App?

Hi Ruth,

 

thanks for your fast reply!

I managed writing the result into a json file with the 'Data Output' operator and storing it on M.App Chest. But now I don't know how to get the data back into my app and display it in a textbox. Do you still have the javascript code available which you used for reading the data from M.App Chest and adding it to your chart and could share it?

 

Thanks,

Marisa

Highlighted
Frequent Contributor
Posts: 103
Registered: ‎01-20-2016

Re: How to store or display recipe output with format table or scalar in Smart M.App?

Hi Marisa,

 

I wasn't successful using json format, but txt.

I paste some code here. It will help to get an idea on how to access the api for the different steps!

var modelInputs = {
	"Method": "Asynchronous",
	"Inputs": [
	  {
		"Name": "OUTPUT TXT",
		"Data": { "Input": false, "Type": "IMAGINE.File", "Value": "fb059245120f3/24032017.txt" }
	  },
	  {
		"Name": "y (Latitude)",
		"Data": { "Input": true, "Type": "IMAGINE.Double", "Value": 6.64714476 }
	  },
	  {
		"Name": "x (Longitude)",
		"Data": { "Input": true, "Type": "IMAGINE.Double", "Value": 39.53921772 }
	  },
	  {
		"Name": "LAYERSTACK",
		"Data": { "Input": true, "Type": "IMAGINE.File", "Value": "fb0796fb7e886505" }
	  }
	]
};

// LAUNCH MODEL "GET GREY VALUE" TO PICK INTEGER VALUES AT MOUSE POSITION
gsp.m_app.utils.connection({
	path : 'api/v1/geoprocesses/fb0593d80158aaaefdfb5666/execute',
	method : 'POST',
	entity : modelInputs
}).then(function (response) { 
	// response of model process
	jobID = response.entity.ID; 
	
	var modelInputs2 = { "IDList" : ["8c3596afa994"] };
	var catalogID = "TEST";                            

	var isCallingStatus = false;

	var timer = setInterval(function () {
		if (isCallingStatus)
			return;
		isCallingStatus = true;

		var modelInputs2 = { "IDList" : [jobID] };

		// check status
		gsp.m_app.utils.connection({
			path : 'api/v1/geoprocesses/status',
			method : 'POST',
			entity : modelInputs2
		}).then(function (response2) {
			if (response2.entity[0].Outcome == "CANCELLED") {
				clearInterval(timer);
			} else if (response2.entity[0].Outcome == "FAILED") {
				clearInterval(timer);
			} else if (response2.entity[0].Outcome == "Success") {  
				clearInterval(timer);
				
				// DERIVE CATALOG ITEM ID
				gsp.m_app.utils.connection({
					path: 'api/v1/geoprocesses/' + jobID + '/outputs',
					method: 'GET'
				}).then(function (response3) {
					catalogID = response3.entity.Items[0].CatalogItemID;
					
					// READ CONTENT OF TEXT FILE
					gsp.m_app.utils.connection({
						path : 'api/v1/items/' + catalogID + '/attachments/default',
						method : 'GET'
					}).then(function (response4) { 
						console.log(response4.entity);
					}).catch(function(err) {
						console.log(err);
					});
				}).catch(function(err) {
					console.log(err);
				});
			}
			isCallingStatus = false;
		}, function (error) {
			console.log(error);
		});	
	},1500);
}).catch(function(err) {
	console.log(err);
});

Good luck!

Ruth

Highlighted
Frequent Contributor
Posts: 83
Registered: ‎07-17-2017

Re: How to store or display recipe output with format table or scalar in Smart M.App?

[ Edited ]

Ruth, you made my day! Thank you so much! :-) This is a great example!

 

The part of the code where you run the spatial recipe and set the input values I managed by using the recipe panel itself and finally sending the catalogItemID to the bi_panel with the gsp.m_app.messages functions  ( http://community.hexagongeospatial.com/t5/Shared-Samples/Exercise-Application-with-two-synchronized-... ) The "// READ CONTENT OF TEXT FILE" part of your code answered the second part of the initial question: how to get the data back into Smart M.App.

Great!

 

Marisa

 

Highlighted
Frequent Contributor
Posts: 83
Registered: ‎07-17-2017

Re: How to store or display recipe output with format table or scalar in Smart M.App?

Hi Ruth,

 

another question: where did you get the parameters for the modelInputs variable from? I coulnd't find it in any API documentation. Maybe I somehow missed it...

 

best regards

Marisa

Highlighted
Frequent Contributor
Posts: 103
Registered: ‎01-20-2016

Re: How to store or display recipe output with format table or scalar in Smart M.App?

Hi Marisa,

 

those are the input ports of your model.

You can test your model inputs in the API console https://mapp.hexagongeospatial.com/developer/api-console/#!/geoprocessingservice/ExecuteModelUsingPO...

 

 

Ruth

Highlighted
Frequent Contributor
Posts: 83
Registered: ‎07-17-2017

Re: How to store or display recipe output with format table or scalar in Smart M.App?

Hi Ruth,

Yes, but I only knew how the inputs need to look like after you gave me your code sample. So I was wondering where I can find the API documentation for this structure:

"Inputs": [{
				"Data": {   "Input": true, 
							"Type": "IMAGINE.File",
							"Value": 03553f4d-d8be-4cad-b20e-68f368fef0de_2c9180825efefde10161c98ec9af320f
				},
				"Name": "POI_layer"
}],
"Method": "Asynchronous"

I already used the API console to test the input of this code http://community.hexagongeospatial.com/t5/Smart-M-App-Tech-Discussions/no-output-generated-after-run... but in this case I already knew how the required input needs to look like from your code.

 

Marisa

Highlighted
Frequent Contributor
Posts: 103
Registered: ‎01-20-2016

Re: How to store or display recipe output with format table or scalar in Smart M.App?

Hi Marisa,

 

I don't know where this kind of structure is documented, I got it from Jan once.....

 

Ruth

Highlighted
Frequent Contributor
Posts: 83
Registered: ‎07-17-2017

Re: How to store or display recipe output with format table or scalar in Smart M.App?

Hi Ruth,

thanks for your reply.

I will ask this in another post. I guess more people could have the same question.

Marisa