문제 설명
RGeo 및 Geojson으로 면적 계산 (Calculating area with RGeo and Geojson)
geojson에 다중 다각형이 정의되어 있습니다. 면적을 계산하려고 합니다.
표면적 코드 경로를 통과할 때 매우 혼란스러운 결과를 얻습니다. 일부 요소를 잘못 사용하고 있기 때문인 것 같습니다.
boundaries = {...valid geojson...}
field_feature_collection = RGeo::GeoJSON.decode(boundaries, geo_factory: RGeo::Geographic.simple_mercator_factory)
first_feature = field_feature_collection[0]
first_feature.geometry.area
# => 1034773.6727743163
내 기능의 면적이 ~602982제곱미터라는 것을 알고 있습니다. 나는 그것을 위의 결과와 어떻게 조화시킬 수 있는지 알아낼 수 없습니다.
나는 명백한 예측을 놓치고 있는 것 같습니다.
무엇이 잘못되었는지 아는 사람이 있습니까?
참조 솔루션
방법 1:
This is most likely due to using the simple_mercator_factory
as your geo_factory
in the GeoJSON decoder. The simple_mercator_factory
parses geometries from lon/lat coordinate systems but performs all of the calculations (length, area, etc.) using the Mercator projection (EPSG:3857) of the geometry.
The Mercator projection gets more distorted the further away you get from the equator, so that's why the area you're getting is about double what you expect it to be.
Depending on the scope of your project, it may be more appropriate to use a different projection, especially if area is a key metric for you. If you choose a different projection, the rgeo‑proj4
gem has just been updated to work with newer versions of PROJ, so you can create the appropriate transformations in your app.
Another option is to use the RGeo::Geographic.spherical_factory
which uses a spherical approximation for the earth and will give you more realistic areas than the Mercator projection, but it is slower than using GEOS backed cartesian factories (which is what the simple_mercator_factory
uses).
(by earnold、Keith Doggett)