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
Occasional Contributor
Posts: 19
Registered: ‎10-12-2015
Accepted Solution

Sending two raster outputs from recipe to map

[ Edited ]

Hello. I have a recipe that has two raster outputs, and I want to send each raster to a different map view. I am doing this via a js that gets the processOutputs and publishes them to the map. It is almost identical to the "publish catalog item and send to map", however, that code sample only works for a single output. My question is: how do I publish multiple outputs, then send them to the map? processOutputs is simply an array with 1 element, which is the first output. 

 

This is the recipe. It has two raster outputs, and I want to send both rasters to the map.

 

Thank you in advance.

Highlighted
Technical Evangelist
Posts: 1,307
Registered: ‎09-11-2015

Re: Sending two raster outputs from recipe to map

[ Edited ]

Hi Vlad,

 

  1. Are the both files actually created? (can be checked in M.App Chest)
  2. The $GP.m_app.processes.getProcessOutputs is not for some reason documented in API docs. But once you have the process jobID, you can double check the outputs array content by calling directly the REST /api/v1/geoprocesses/{jobID}/outputs.
    You can call it either by using the API Console or by $GP.m_app.utils.connection() function.

 

Regards,

Jan

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Highlighted
Occasional Contributor
Posts: 19
Registered: ‎10-12-2015

Re: Sending two raster outputs from recipe to map

Hi Jan,

 

Only one of the files is created and uploaded to the chest, sadly. As for the processOutputs, I have tried console.log(processOutputs) in the callback function of getProcessOutputs, which returns an array of one object, containing a CatalogItemId and a Name (which is, in this case, the name of the output). I'd guess that this array should contain, in my case, two objects like this one.

 

Vlad

Highlighted
Technical Evangelist
Posts: 1,307
Registered: ‎09-11-2015

Re: Sending two raster outputs from recipe to map

Then the recipe does not work. I tried a simpler form but it produces only single file too.

Untitled.png

 

I don't know whether it's possible to make image copies this way. Hopefully someone more experienced will suggest a better solution.

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Highlighted
Occasional Contributor
Posts: 19
Registered: ‎10-12-2015

Re: Sending two raster outputs from recipe to map

[ Edited ]

Then a good question would be how to make a spatial recipe that gets one raster as input and gives two copies of the same raster as output. On the other hand, here is my js code that is supposed to get these outputs and send them to the map panels:

 

$GP.m_app.events.processes.processExecutionFinish(function (ev, args) {
    var status = args.status,
        jobId = args.jobId;
        
    console.log(jobId);

    if (status === "FAILED")
        return;
        
    $GP.m_app.processes.getProcessOutputs({
        jobId: jobId
    }, function (processOutputs) {
        
        console.log(processOutputs);
        
        var firstOutput = processOutputs[0],
            firstOutputId = firstOutput.CatalogItemID,
            firstCatalogItemTitle = "Output1.img";

        $GP.m_app.platform.publications.publish({
            id: firstOutputId,
            title: firstCatalogItemTitle
        }, function (publishInfo) {
            if (publishInfo.success === false)
                return;

            $GP.m_app.platform.publications.get(firstOutputId, function (publicationProperties) {
                $GP.m_app.platform.catalog.get(firstOutputId, function (catalogItemProperties) {
                    $GP.m_app.messages.send("displayOnMap", {
                        mapComponentId: "map2",
                        publicationProperties: publicationProperties,
                        catalogItemProperties: catalogItemProperties
                    });
                });
            });
        });
        
        var secondOutput = processOutputs[1],
            secondOutputId = secondOutput.CatalogItemID,
            secondCatalogItemTitle = "Output2.img";

        $GP.m_app.platform.publications.publish({
            id: secondOutputId,
            title: secondCatalogItemTitle
        }, function (publishInfo) {
            if (publishInfo.success === false)
                return;

            $GP.m_app.platform.publications.get(secondOutputId, function (publicationProperties) {
                $GP.m_app.platform.catalog.get(secondOutputId, function (catalogItemProperties) {
                    $GP.m_app.messages.send("displayOnMap", {
                        mapComponentId: "map1",
                        publicationProperties: publicationProperties,
                        catalogItemProperties: catalogItemProperties
                    });
                });
            });
        });
        
    });
    
});

It would be good to at least know if this is the way to go when working with multiple outputs.

Highlighted
Technical Evangelist
Posts: 1,307
Registered: ‎09-11-2015

Re: Sending two raster outputs from recipe to map

Yes, this should work. However I would do that rather in an iteration cycle.

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Highlighted
Occasional Contributor
Posts: 19
Registered: ‎10-12-2015

Re: Sending two raster outputs from recipe to map

I managed to find a solution to this. The outputs aren't supposed to branch out, they have to flow one from another. So I now have Raster Input -> Raster Output (with port input) -> Raster Output (with port input), and it outputs two separate rasters.