Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for
Do you mean
Regular Contributor
Posts: 207
Registered: ‎07-27-2016 Distance Between 2 Given Points

Hi Guys,

Is there a way in Portal SDK to get the distance between 2 given points.

There reason I am asking is , I need to create a polygon from the result of the \$GP.map.draw.circle function , need to pass the polygon array to a function.

\$GP.map.draw.circle , look like it returns the center point and 1 side point to form the radius , so I want to calculate the border points that will form the circle polygon but i need the length of the radius.

Kind Regards

Jacques Technical Evangelist
Posts: 1,118
Registered: ‎09-11-2015

Re: Distance Between 2 Given Points

[ Edited ]

Hi Jacques,

I am afraid that there's no simple solution or answer to this. I am rather curious, what is the desired aim or workflow? Why is the circle drawn? What actually does the user want?

Thanks,

Jan

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Regular Contributor
Posts: 207
Registered: ‎07-27-2016

Re: Distance Between 2 Given Points

Hi Jan,

I will then go the math route.

The reason is that the wms can handle bbox and polygons.

Most pivot field are round , so I dont want the client to place a load of polygon points to form a circle.

I would like him to draw the circle , then I will generate the polygon and pass it to the service.

So , the circle function gives the center point and bounding point , so one can calculate the radius and from there the points making the circle.

Well , that is the idea then.

Kind Regards

Jacques Technical Evangelist
Posts: 1,118
Registered: ‎09-11-2015

Re: Distance Between 2 Given Points

I see. But even so, you will send a rectangle anyway and the user will see rectangular-results. It sounds simpler to convince the customer to draw a rectangle around the pivot field. It's just my thought, but drawing a rectangle around a circle is more or less same of difficulty as hitting the center of a circle. But that's just my thought.

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Highlighted
Regular Contributor
Posts: 207
Registered: ‎07-27-2016

Re: Distance Between 2 Given Points

Hi Jan,

I will use the center point and the radius to plot a point every 10 degrees for 360 degrees

The thing is , I cant use a bounding box or triangle to be drawn around the pivot , both will result in unwanted vegitation making the quantified data inacurate.

Will let you know if I succeed or crash and burn.

Kind Regards

Jacques

Regular Contributor
Posts: 207
Registered: ‎07-27-2016

Re: Distance Between 2 Given Points

Hi Jan,

So basically this is what I have done.

(See image)

I used \$GP.map.draw.circle to draw the circle.

Then I took the center x,y and the wall x,y and calculated the radius.

Then I used the center x,y radius to radian and ploted the 36 points making up the circumference of the circle.(closed polygon)

I will then send his the service and hope it works Regards

Jacques Technical Evangelist
Posts: 1,118
Registered: ‎09-11-2015

Re: Distance Between 2 Given Points

Nice, good old math Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

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

Re: Distance Between 2 Given Points

It wasn't entirely clear to me from the beginning what you were trying to achieve, Jacques. But now I understand it and it looks like a nice solution. Awesome!

Regular Contributor
Posts: 207
Registered: ‎07-27-2016 Re: Distance Between 2 Given Points

[ Edited ]

Hi Guys,

So if someone would need this some day , or would like to improve on this (just a quick solution) nothing to fancy...please feel free (needs some error handling still...etc)

/===DRAW CIRCLE FUNCTION==
\$GP.map.draw.circle({}, function(retCircle) {
var Circlegeojson = retCircle.feature.get_geoJSON();

//==Center X==
var CircleCenterX = JSON.stringify([Circlegeojson.geometry.coordinates]);
CircleCenterX = CircleCenterX.replace(/[\[\]']/g, '');

//==Center Y==
var CircleCenterY = JSON.stringify([Circlegeojson.geometry.coordinates]);
CircleCenterY = CircleCenterY.replace(/[\[\]']/g, '');

var CircleRadiusX = JSON.stringify([Circlegeojson.geometry.coordinates]);

var CircleRadiusY = JSON.stringify([Circlegeojson.geometry.coordinates]);

var FinX = CircleCenterX - CircleRadiusX;
var FinY = CircleCenterY - CircleRadiusY;

var Rlen = Math.sqrt(Math.pow(CircleCenterX - CircleRadiusX, 2) + Math.pow(CircleCenterY - CircleRadiusY, 2));

var points = 20;
var slice = parseFloat(2 * Math.PI / points);
var angle = 0;
var CrclPoly;
var FrstX;
var FrstY;

for (i = 0; i < points; i++) {
angle = slice * i;

var newX = (parseFloat(CircleCenterX) + parseFloat(Rlen) * parseFloat(Math.cos(angle)));
var newY = (parseFloat(CircleCenterY) + parseFloat(Rlen) * parseFloat(Math.sin(angle)));

if (i + 1 != points) {
if (!CrclPoly) {
FrstX = newX;
FrstY = newY;
CrclPoly = newX + ' ' + newY + ",";
} else {
CrclPoly = CrclPoly + newX + ' ' + newY + ",";
}
} else {
CrclPoly = CrclPoly + newX + ' ' + newY + "," + FrstX + ' ' + FrstY;
}
\$GP.crs.setCurrent("EPSG:3857", function() {
\$GP.map.draw.point({
x: newX,
y: newY
});
});
}
//==SHOW WINDOW==
showChartWindow();
//==CALL FUNCTION===
getNDVI_ND_ByPolygon(ChrtDateFrom, ChrtDateTo, CrclPoly);
});

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