Hexagon Geospatial
MENU

Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Contributor
Posts: 43
Registered: ‎07-12-2016
Accepted Solution

Geospatial Portal analysis WMPS query with IN clause

[ Edited ]

I need to create a query on a WMPS using the Portal API. I've been using the community portal to test how to do this. The example I'm using is titled "MPS Query":

 

var queryName = "MPS States";
$GP.crs.setCurrent("EPSG:4326", function () {
    $GP.queries.add({
        featureClassId: "USSample|States",
        url: "http://demo.hexagongeospatial.com/wmps/mapService.svc",
        definitionName: "MapPublisher",
        queryName: queryName,
        applicationId: "DEMO_USA",
        addToLegend: false,
        filters: [
            {
                operator: ">",
                operands: ["POP", 1227928]
            }, {
                type: "spatial",
                operator: "0",
                complement: false,
                operands: [
                    {
                        "type": "Point",
                        "coordinates": [-99, 38],
                        "crsId": "EPSG:4326"
                    }
                ]
            }
        ]
    },
    function (result) {
        if (result.updated) {
            $GP.ui.info("Analysis updated");
            return;
        }
        $GP.queries.find({
            analysisId: result.analysisId,
        }, function (result2) {
            result2.analysis.addToLegend(function () {
                $GP.legend.find({
                    name: queryName
                }, function (ret) { $GP.map.center({ x: -99, y: 38 }); });
            });
        });
    });
});

The query I actually want to create requires an IN clause so I've been trying to customise the above example to accept an IN clause. However, I can't work out the correct syntax. Is this even possible with a WMPS? I've tried the following (using specific POP values from the service):

 

filters: [
            {
                operator: "IN",
                operands: ["POP", (666168,638800,10847115)]
            }
         ]

and:

 

filters: [
            {
                operator: "IN",
                operands: ["POP", "666168,638800,10847115"]
            }
         ]

neither of these work.

 

If this is possible to do, what is the correct syntax?

 

Thanks,

Jason

Highlighted
Contributor
Posts: 62
Registered: ‎11-17-2015

Re: Geospatial Portal analysis WMPS query with IN clause

The best way to test this kind of behaviour is to test it first with standard interface, in this case in the left panel Analysis.

 

Although the syntax of the SDK queries is masked, we can deduce what it does with the object $analysisManager from Portal. So to test this I ran an instance of Portal in Chrome, loaded the DEMO data from WMPS, set the analysis similar to what you need (with success to show results on map) and checked the object $analysisManager in Developer Tools (F12). It retrieved something like this for $analysisManager._analyses["77bd-ecbd-c919-5bdb"]._firstWhereAttributes[0]:

["POP", "IN", "453588,562758,638800", undefined]

So your second option should work. I tested with 2016 SDK with success.

 

Regards,

Bruno Santos

Contributor
Posts: 43
Registered: ‎07-12-2016

Re: Geospatial Portal analysis WMPS query with IN clause

Thanks for that Bruno.

 

As I said though, the second option doesn't work in the community portal. You can try it yourself, it gives the error:

 

"A problem occurred while generating map: Data type mismatch in criteria expression."

 

The community portal is 2015 and this is also the version we use (Portal 2015 EP06). Could you please let me know if this is supposed to work in 2015 or if it was a bug that was fixed in 2016? 

 

Can you please share the code you successfully tested in 2016 SDK?

 

Cheers.

Staff
Posts: 294
Registered: ‎11-05-2015

Re: Geospatial Portal analysis WMPS query with IN clause

[ Edited ]
filters: [
            {
                operator: "IN",
                operands: ["POP", [666168,638800,10847115]]
            }
         ]
    },

This is the proper way to write your filter for the WMPS, Jason Smiley Happy

Note the square brackets surrounding the list of population values.

Contributor
Posts: 43
Registered: ‎07-12-2016

Re: Geospatial Portal analysis WMPS query with IN clause

Excellent, that works perfectly. Thank you.

Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.