i want to calculate centroid (center point ) of a polygon.
Thanks rajni sharma - I see what you are trying to do. This works for me:
const ringJson = [[["172.4843305878348","-43.48191185124988"],["172.4877698503442","-43.48248171686965"],["172.48715361282302","-43.484065878559875"],["172.48428867831893","-43.48421950013839"],["172.4843305878348","-43.48191185124988"]]]
var boundaryJson = {"rings":ringJson, "spatialReference":sr};
var boundary= ArcGISRuntimeEnvironment.createObject("Polygon", {json: boundaryJson});
console.log("boundary", boundary)
console.log(JSON.stringify(boundary.json));
var centroid = GeometryEngine.labelPoint(boundary);
console.log("==========");
console.log("centroid", centroid);
console.log(JSON.stringify(centroid.json));
For reference, when you see "qml point sum hex number" you are printing the address of the Point object. To see the details of the point you need to either print property values or stringify the json:
Hi rajni sharma - you can use the GeometryEngine.labelPoint to give you a point that's within the polygon and near the center of gravity.
how to use it , is their any example i could follow, because i could not found any example for it.
Should i use it like this:
var a = Point labelPoint(Polygon ring);it gives some syntax error
We have a number of samples that cover the use of GeometryEngine on github - for example look at this one.
For the label point call you should do something like:
var centroid = GeometryEngine.labelPoint(ring);
hi Luke Smallwood
I tried it your way, but when i try to console the qml point it crashed my application everytime.
Actually i am trying to put a picture marker on centre of polygon.
So i need to get centre x and y coordinates
Suppose this is the JSON m passing in ring
[[["172.4843305878348","-43.48191185124988"],["172.4877698503442","-43.48248171686965"],["172.48715361282302","-43.484065878559875"],["172.48428867831893","-43.48421950013839"],["172.4843305878348","-43.48191185124988"]]]
function createPolygon(ring) {
// create polygon using json
const sr = { "wkid": 4326};
var boundaryJson = {"rings":ring,"spatialReference":sr};
var boundary= ArcGISRuntimeEnvironment.createObject("Polygon", {"json": boundaryJson,"id":"property"});
console.log(JSON.stringify(centroid));//Crashed my application
return boundary;
}
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.