Turf.js生成圆形多边形出现经度坐标异常问题求助
Hey there! I see exactly what's going wrong here—this is a super common gotcha with GIS libraries that follow GeoJSON standards.
The Root Cause
Turf.js (and all GeoJSON-compliant tools) expects coordinates in the [longitude, latitude] order, but you've passed your center point as [latitude, longitude] instead.
Let's break it down clearly:
- Your original center:
[20.659698486328125, -103.349609375]→ Turf reads this aslongitude=20.66, latitude=-103.35(a spot way south near Antarctica, which explains the weird longitude values in your output) - The correct order should be:
[-103.349609375, 20.659698486328125]→longitude=-103.35, latitude=20.66(the central Mexico location you intended)
Corrected Code
Here's the fixed version of your code with the coordinate order swapped:
var center = [-103.349609375, 20.659698486328125]; // [longitude, latitude] var options = { steps: 5, units: 'kilometers', options: {} }; var radius = 1; var polygon = turf.circle(center, radius, options);
What to Expect Now
When you run this corrected code, the generated polygon coordinates will be centered around your intended location, with both longitude and latitude values matching the area near -103.35, 20.66.
A quick pro tip: Always double-check coordinate order when working with GeoJSON-based libraries—this mix-up is one of the most frequent issues folks run into when getting started with turf.js or similar tools.
内容的提问来源于stack exchange,提问作者Saurabh Sharma

