02-08-2018 03:54 AM
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
Solved! Go to Solution.
02-08-2018 06:32 AM - edited 02-08-2018 06:34 AM
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
02-08-2018 06:44 AM
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
02-08-2018 06:53 AM
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.
02-08-2018 10:33 PM
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
02-09-2018 04:03 AM
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
02-09-2018 04:07 AM
Nice, good old math
02-09-2018 05:19 AM
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!
02-09-2018
06:09 AM
- last edited on
06-28-2018
07:49 AM
by
pszrajber
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[0][0][0]]); CircleCenterX = CircleCenterX.replace(/[\[\]']/g, ''); //==Center Y== var CircleCenterY = JSON.stringify([Circlegeojson.geometry.coordinates[0][0][1]]); CircleCenterY = CircleCenterY.replace(/[\[\]']/g, ''); //==Radius X== var CircleRadiusX = JSON.stringify([Circlegeojson.geometry.coordinates[0][1][0]]); CircleRadiusX = CircleRadiusX.replace(/[\[\]']/g, ''); //==Radius Y== var CircleRadiusY = JSON.stringify([Circlegeojson.geometry.coordinates[0][1][1]]); CircleRadiusY = CircleRadiusY.replace(/[\[\]']/g, ''); var FinX = CircleCenterX - CircleRadiusX; var FinY = CircleCenterY - CircleRadiusY; //==LEN OF RADIUS== 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); });