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: 49
Registered: ‎10-27-2015
Accepted Solution

Get the geometry of the selected features

Is it possible to get the geometry of the selected feature(s) and what are other selection methods other than "Rectangle"?

 

$GP.ui.toolbar.add({
categoryIndex: 0,
xtype: "tbbutton",
text: WMPSQueryConfigs[0].name,
handler: function (b) {
$GP.selectedFeatures.add({
"type": "Rectangle" // ??? other methods
}, function (r) {
createA

nalysis2(r.???.geometry);
});
}
})

 

thank you

Technical Evangelist
Posts: 927
Registered: ‎09-11-2015

Re: Get the geometry of the selected features

[ Edited ]

Hi Denis,

 

As per the SDK API.js file it should be possible to use:

switch (config.type) {
case "Point":
	selectionEvent = "selectByPoint";
	break;
case "LineString":
	selectionEvent = "selectByLine";
	break;
case "Polygon":
	selectionEvent = "selectByArea";
	break;
case "Rectangle":
	selectionEvent = "selectByBbox";
	break;
}

And according to the example below, the geometry shall be possible to get in GeoJSON format:

$GP.selectedFeatures.add({
	type : "Rectangle"
}, function (result) {
	console.log(result.features); // 2-dimensional array of features. Arrays are grouped by featureClassId
	console.log(result.features.get_geoJSON()) // GeoJSON format of the selected features
});

If the get_geoJSON will not work on the result.features, I'd try to iterate over the features collection and apply the get_geoJSON per single item (feature).

 

Jan

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Contributor
Posts: 49
Registered: ‎10-27-2015

Re: Get the geometry of the selected features

Hi Jan,

 

I could swear it didn't work but when I tried the same code again it did. I didn't even have to change my code at all! Maybe it is inconsistent and under certain circumstances doesn't return geometry but in my case everything was the same.

 

r.features[0][0].get_geoJSON().geometry

 

Thanks,

Denis

Highlighted
Super Contributor
Posts: 290
Registered: ‎02-09-2016

Re: Get the geometry of the selected features

Hi  DenisN,

 

Just be aware that if you have a redlining on top, then all select tools and selection API return nothing (it is a bug and it happens in portal 2015 EP04, haven't tested with EP05 yet).

 

Kind regards

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