02-05-2017 07:06 PM - edited 02-05-2017 07:39 PM
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
Solved! Go to Solution.
02-06-2017 02:57 AM
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
02-06-2017 06:25 PM
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.
02-07-2017 03:05 AM - edited 02-07-2017 03:06 AM
filters: [ { operator: "IN", operands: ["POP", [666168,638800,10847115]] } ] },
This is the proper way to write your filter for the WMPS, Jason
Note the square brackets surrounding the list of population values.
02-07-2017 07:21 PM
Excellent, that works perfectly. Thank you.