当前位置:网站首页>Do you really use the buffer buffer in PostGIS?
Do you really use the buffer buffer in PostGIS?
2022-06-12 23:48:00 【GIS weapon warehouse】
buffer - Graph buffer analysis ,GIS One of the most basic spatial analysis in .
Realization buffer There are many kinds of tools for , For example, the front-end truf.js、 Server side ArcGISserver、 On the desktop ArcMap、 Database side PosrGIS And so on .
But I've been using it lately PostGIS Point to point buffer When analyzing , What you get is an ellipse .

Why ellipse , Shouldn't it be a circle ?
To find out , I'm going to study buffer Principle .
buffer There are two ways to build : European method and Geodesic method .
- It's a two-dimensional method of computing on the Euclidean plane , This two-dimensional map is a map of the earth after projection , The process of projection causes the map to deform , The Euclidean method is based on the transformed map to calculate the buffer .
- Geodesic method is to calculate on three-dimensional ellipsoid , A three-dimensional ellipsoid is a sphere very close to the shape of the earth , The geodesic method is based on the surface of this sphere for buffering , Then the calculation results are transformed by projection , Show it on the map .
The difference between the two results is , In the European method , The result of the point buffer calculation is a circle at all times , But when you put the results into the real world , But there will be errors . The size of the error , It depends on how you project 、 Buffer position and buffer distance , Take Gaud map for example , It uses a Mercator projection , In this projection , The equatorial region has the smallest deformation , The more we go to the high latitudes of the north and south poles , The more deformation , The most obvious is Greenland , Its area is only the size of the Chinese mainland 1/4 about , But on the map , It's bigger than China .

There is no error in the geodesic method , But show it on a two-dimensional map , You have to project the map , Projection causes distortion .
If there is no error in the result , And show that there is no deformation , What do I do ?
With a three-dimensional map .
Three dimensional maps do not need to be projected like two-dimensional maps , No projection transformation , There will be no deformation .
The following figure , On the left is a two-dimensional map , On the right is a three-dimensional map , It's obvious that at high latitudes , The left side has been deformed , And there's no on the right .

understand buffer After the principle of , Let's go back to the problem at the beginning .
stay postGIS In my sql The code is written like this , according to postGIS Of Official documents , This should belong to the European method .

buffer 500 The effect of rice is like this
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-0nv5XIg8-1605169096527)(http://blogimage.gisarmory.xyz/20201112122638.png)]
And then I wrote a geodesic method , Notice the difference between the red box and the above , Input v_inGeom Variable , The default is geometry type , Force it to geography after ,postGIS You'll use the geodesic method .

buffer 500 The rice effect is like this

Two at the same time

The problem is obvious , Why is the result of geodesic method round , The result of the European method is elliptic ? This is not in line with the principle of the previous study ,
It's not supposed to be that the European method is circular , Is the geodesic method elliptical ?
I use it again truf.js do 500 The buffer of rice , The buffered result is superimposed on the graph above , The effect is this ( The little circle inside is truf.js Buffered results )

I fell into deep thinking .
see truf.js Of Official documents , There's only one buffer , There is no specific description of what kind of .
Feeling truf.js This , That's the right European approach , What the hell is the ellipse on it ?
It seems that we need to find an authoritative one to calibrate , Use arcgis server Of buffer Interface try , See what the effect is .
Code

The effect is as follows , The big circle is the geodesic method , The small circle is the European method

So it seems ,truf.js Chinese is the European way ,postGIS The geodesic method in is correct , But the European approach is problematic .
Then study again postGIS The European method in .
Calling arcgis server Of buffer Interface , Notice that 3 Coordinate dependent parameters ,inSR Enter the coordinates of the graph ,outSR Output the coordinates of the graph ,bufferSR The coordinates used when buffering .

Mark up postGIS
The same goes for the incoming and returning wgs84 Coordinates of , What coordinates are used for buffering ?
Oh ~ Oh ~ got it
The reason why ellipses appear is because , stay geojson When you turn Geometry ( Look at the picture below ),St_geomfromgeojson function The return is geometry type , When buffering ST_Buffer function Received geometry The type will choose to use the European method for buffering , but geojson The data in is the latitude and longitude data of spherical coordinates , The radius of the buffer also passes in radians , In spherical coordinates and radian distance units , In the plane map algorithm of Euclidean method , No wonder it turns out to be an ellipse .

Um. ~ with reason .
Turn the coordinates and try , In the red box below is the process of coordinate transformation , meanwhile , Because the projection coordinates are used to calculate ,buffer The distance parameter can be used directly in meters , There's no need to turn it into an arc .

Try again , The big circle is the geodesic method , Small circles are European methods , ha-ha , perfect !

Finally, to verify the accuracy , Measure the distance , Which one is right .
Obviously , The following figure ,500 The distance of meters is consistent with the boundary of the big circle in the picture above , That is, geodesic method is more accurate .

Little question :
Why is the circle buffered by the geodesic method still a regular circle , Isn't it deformed ?
answer : The main reason is , The buffer distance in the example is only 500 rice , The range is too small . It's also Beijing , If it's a buffer 1000 Km above , You can see the obvious deformation .
summary :
- buffer There are two ways to build , European method and geodesic method
- The Euclidean method is to carry out buffer calculation on the plane map after projection deformation , The advantage is that the algorithm is simple , Efficient , The disadvantage is that the result is not correct , The size of the error depends on the projection method 、 Buffer position and buffer distance .
- Geodesic method is a buffer calculation on a three-dimensional ellipsoid , The advantage is that the results are accurate , Not affected by projection distortion , The disadvantage is that the algorithm is complex , Large amounts of data may affect efficiency .
- truf.js Only European methods are supported .
- arcgis server Support two ways to build .
- postGIS Support two ways to build , The default is the European method , In the European method , If the parameter is longitude and latitude coordinates , It is necessary to convert the longitude and latitude coordinates into projection coordinates and then calculate , Otherwise, the result of the buffer will be an ellipse . Change the type of the parameter from
geometryCast togeographyafter ,postGIS Will use geodesic method for buffer calculation .
Example 、 Source code
This example is used in the article , It can be accessed online , Use the browser developer tool to see the code .
This function script , Including the European method and geodesic method mentioned in the paper , Both incoming and returning are geojson Format , The buffer radius is in meters , Control buffering by type . Direct execution creates functions .
postGIS in buffer Function script
Reference documents
http://www.postgis.net/docs/ST_Buffer.html
https://postgis.net/docs/using_postgis_dbmanagement.html#Geography_Basics
http://turfjs.org/docs/#buffer
https://desktop.arcgis.com/zh-cn/arcmap/10.3/tools/analysis-toolbox/how-buffer-analysis-works.htm
http://server.arcgisonline.com/arcgis/sdk/rest/index.html#//02ss000000nq000000
http://server.arcgisonline.com/arcgis/sdk/rest/index.html#/Buffer/02ss0000003z000000/
https://developers.arcgis.com/javascript/latest/sample-code/ge-geodesicbuffer/index.html
Original address :http://gisarmory.xyz/blog/index.html?blog=postGISbuffer
Focus on 《GIS Zeughaus 》 official account , The first time to get more high quality GIS article .

This article adopts Creative Commons signature - Noncommercial use - Share in the same way 4.0 International licensing agreement Licensing . Welcome to reprint 、 Use 、 Re release , But be sure to keep the signature of the article 《GIS Zeughaus 》( Include links : http://gisarmory.xyz/blog/), Not for commercial purposes , Based on this revised work must be released with the same license .
边栏推荐
- Actual combat | inductance element positioning -- detailed explanation of Halcon and opencv implementation (with source code)
- It is meaningful to define genus, and D can use it to explain semantics
- 21 Chundong University blasting safety online peacetime operation 123 [standard answer]
- Deep feature synthesis and genetic feature generation, comparison of two automatic feature generation strategies
- Novice must see! How rust beginners write gear smart contracts (1)
- Enterprise wechat H5_ Authentication, H5 application web page authorization login to obtain identity
- 【Matlab】三维曲线与三维曲面
- 支持Canvas的Leaflet.Path.DashFlow动态流向线
- Redis实现短信验证码登录
- 1111111111111111111111111111111111111111111111111111111
猜你喜欢

2022起重机械指挥上岗证题目模拟考试平台操作

基于Three.js海上风电数字孪生三维效果

Test platform series (97) perfect the case part

2022 electrician (elementary) operation certificate examination question bank and online simulation examination

SAP QM qp03 displays an inspection plan with multiple specs inspection features

CST learning: four element array design of circular patch antenna (III) array formation and parallel excitation

dict和set的基本操作

Leetcode 2164. Sort odd and even subscripts separately (yes, once)

OSM map local publishing - how to generate vector maps of provinces and cities

H5时代leaflet中还在用DivIcon?
随机推荐
Start blogging
SAP 业务技术平台(BTP) 上的 Business Rules Service 使用介绍
Zhengzhou University of light industry -- development and sharing of harmonyos pet health system
Summary of the lowest level error types in PHP
Case sharing of online real queuing system reconfiguration -- practical part
M_8:设计消息队列存储消息数据的 MySQL 表格
Xi'an Jiaotong 22nd autumn e-commerce technology online expansion resources (IV) [standard answer]
36 krypton's debut | "osogena" won nearly ten million angel rounds of financing. The original DLR scientists of German Aerospace Research and development system modeling and simulation CAE software PA
The most complete preview! Huawei cloud wonderful agenda collection
SAP 业务技术平台(BTP) Workflow(工作流)功能介绍
Tableau
Divicon est toujours utilisé dans le leaflet de l'ère H5?
如何实现OSM地图本地发布并自定义配图
How SAP ui5 uses manifest JSON file defines third-party library dependencies
Talent Weekly - 5
测试平台系列(97) 完善执行case部分
Leetcode 2164. Sort odd and even subscripts separately (yes, once)
Introduction to message oriented middleware (message queue)
Sequence maximum return
利率降低导致债券价格上涨