Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

turf.centerOfMass for multiple polygons in Feature Collection #2584

Open
tj26x opened this issue Mar 4, 2024 · 2 comments
Open

turf.centerOfMass for multiple polygons in Feature Collection #2584

tj26x opened this issue Mar 4, 2024 · 2 comments

Comments

@tj26x
Copy link

tj26x commented Mar 4, 2024

I am having trouble with getting the data for turf.centerOfMass() correct.

I have a featureCollection which can have multiple polygons added to it.

var polygonlines = [];
//add lines to polygons etc..
    if (polygonlines.length >= 4) {
                    var feature =
                    {
                        "type": "Feature", "properties": {}, "geometry": { "type": "Polygon", "coordinates": [polygonlines] }
                    }
    
                    features.push(feature);
                }
            }
        });
    }
    var featCollection = {
        type: 'FeatureCollection',
        features: features
    }

I want to calculate the centroid, center and the centerOfMass.

var centroid = turf.centroid(featCollection); //WORKS CORRECTLY
var centre = turf.center(featCollection); //WORKS CORRECTLY

var centreofMass = turf.centerOfMass(featCollection);  //FAILS

The centerOfMass calculation fails and give me the error: "Uncaught TypeError TypeError: Qt is not a constructor"

The only way i can get centerOfMass to not fail is to list an individual polygon from the featcollection... but this is not what i want, i want the centerOfMass for multiple polygons. The turf documentation says centre and centerOfMass can take any Feature or a FeatureCollection, centre and centroid do and they work fine...

How do I get it to get the centerOfMass for multiple polygons?

Thank you very much
Version 5.6.0

@smallsaucepan
Copy link
Member

Hi @tj26x . Can you please attach an example geojson file that causes this error?

Version 5.6.0

Also, to double check, are you using version 5.6.0 - or 6.5.0?

@tj26x
Copy link
Author

tj26x commented May 6, 2024

Sorry version 6.5.0
centerOfMass-featCollection.txt

I can repeat the problem with lots of different polygons, the problem is not unique to just this one.

Thank you.

Error message (if it helps):
Uncaught TypeError TypeError: Qt is not a constructor
at ne (C:\Dev\xx\trunk\xx\wwwroot\js\turf.min.js:39:20359)
at ve (C:\Dev\xx\trunk\x\wwwroot\js\turf.min.js:39:24423)
at t (C:\Dev\xx\trunk\xx\wwwroot\js\turf.min.js:155:394937)
at calculateGroupCentreAndRadius (localhost?5001/?dataset=a8e60383-c8b1-4668-b00f-b6354076863a?490:9:234668:24)
at (localhost?5001/?dataset=a8e60383-c8b1-4668-b00f-b6354076863a?490:9:232642:9)
at dispatch (C:\Dev\xx\trunk\xx\wwwroot\lib\jquery\dist\jquery.min.js:2:43331)
at y.handle (C:\Dev\xx\trunk\xx\wwwroot\lib\jquery\dist\jquery.min.js:2:41315)
at trigger (C:\Dev\xx\trunk\xx\wwwroot\lib\jquery\dist\jquery.min.js:2:71937)
at triggerHandler (C:\Dev\xx\trunk\xx\wwwroot\lib\jquery\dist\jquery.min.js:2:72616)
at checkboxChange (C:\Dev\xx\trunk\xx\wwwroot\js\gijgo.min.js:1:109130)
at change (C:\Dev\xx\trunk\xx\wwwroot\js\gijgo.min.js:1:106987)
at dispatch (C:\Dev\xx\trunk\xx\wwwroot\lib\jquery\dist\jquery.min.js:2:43331)
at y.handle (C:\Dev\xx\trunk\xx\wwwroot\lib\jquery\dist\jquery.min.js:2:41315)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants