AnsweredAssumed Answered

getCentroid() Seems to not work.

Question asked by geonetadmin on Apr 8, 2014
Original User: mmoles

I have some polygons that are drawn in the middle of the gulf of mexico, but when i do a .getCentroid() , it puts it east of Puerto Rico.    I had it draw a 1km circle from that point, and with the circle i did a .getCentroid() and it had the signs backwards.


The circle "center" attribute shows
x: -6915389.5593207795
y: 2211235.9333326435

circle.GetCentriod() shows
x: 6915389.573377605,
y: -2211235.9378281594


I had 4 polygons all within 1 KM of each other, and I ran trough a loop to draw them and with each one i added console.log(tempPoly.getCentroid());   and this is what it outputted:
x: -6915389.5593207795, y: 2211235.9333326435, ...
x: -6915241.501368446, y: 2211268.289466834, ...
x: 6914871.672864611, y: -2211054.934414348, ...
x: 6914169.460895168, y: -2210864.6600185963, ...


I tested this on 3.7 and 3.8 both ran into the same issue.  Any ideas on whats going on.   The sign changes are probably breaking things, but why is it even doing this?  Has this worked for anyone or did they release broken code?


EDIT:
So, i figured out that my polygons were technically not closed.  The polygons will close themselves, but without a duplicate start\stop point its technically not closed.  Circles still the odd issue of the signs being mixed up.

tempGraphicsCircleLayer.graphics[0].geometry.center
spatialReference: Object
type: "point"
x: -10372778.575270642
y: 3316803.914099979
__proto__: Object

tempGraphicsCircleLayer.graphics[0].geometry.getCentroid()
spatialReference: Object
type: "point"
x: 10372778.548966456
y: -3316803.9056921354
__proto__: Object

Attachments

Outcomes