postgresql - PostGIS - 创建椭圆
问题描述
我试图构建一个函数来创建一个椭圆而不通过经典编程语言。我将这些参数存储在自定义 GeoJSON 中。smallSide 和 bigSide 必须以米为单位。生成的几何图形必须使用 EPSG 4326 创建:
我的参数是:
"geography" : {"type":"Ellipse",
"smallSide":100,
"bigSide" : 110,
"rotation" : 0,
"coordinates":[8.54736328125,46.37156925087649]}
在网上搜索我发现这个解决方案非常接近解决我的问题:
ST_AsEWKT(ST_Translate( ST_Rotate( ST_Scale( ST_Buffer(ST_Point(8.54736328125,46.37156925087649)::geography, 3000)::geometry, 0.3,0.5)::geometry, 0), 8.54736328125,46.37156925087649))
此函数在挪威附近创建一个椭圆。尝试: http: //geojson.io/#map=11/69.5354/11.1216
最初的中心在瑞士。
这个函数有两个大问题: 1. 椭圆不在坐标中心;2.不知道如何转换Scale的xFactor/yFactor来匹配meters参数;
PS。这是上述函数的 WKT:
SRID=4326;POLYGON((11.123273576134 69.5574277440815,11.1230606869505 69.5547928070317,11.1224064250309 69.55225640052,11.1213360407351 69.5499159578464,11.1198907409861 69.547861360983,11.1181260946945 69.5461714955871,11.1161098932273 69.5449112303195,11.1139195487472 69.544128934906,11.1116391298573 69.5438546306632,11.1093561468668 69.5440988431489,11.1071582077927 69.5448522000687,11.1051296707337 69.5460857895281,11.1033484183676 69.5477522651534,11.1018828760511 69.5497876565102,11.100789386429 69.5521138166206,11.1001100408036 69.554641414163,11.099871051113 69.5572733570283,11.1000817266595 69.5599085170987,11.1007340973332 69.5624456140896,11.1018032006992 69.5647871095818,11.1032480248444 69.5668429613212,11.105013073265 69.5685340926073,11.107030493374 69.5697954420587,11.1092226874817 69.5705784748924,11.1115053053956 69.5708530575261,11.1137905020249 69.5706086220194,11.1159903323456 69.5698545746198,11.1180201503338 69.568619932341,11.1198018783021 69.5669522018393,11.1212670184877 69.5649155445927,11.1223592894673 69.5625883002992,11.1230367854657 69.5600599653373,11.123273576134 69.5574277440815))
解决方案
The first problem is that you use the original coordinates of the center to translate the geometry. (I mean deltax and deltay in st_translate())
As far as i understand delta should be the difference beetween coordinates you need and actually have. So the solution is to calculate preliminary (shifted) polygon:
prePoly := ST_Rotate( ST_Scale( ST_Buffer(ST_Point(8.54736328125,46.37156925087649)::geography,
3000)::geometry, 0.3,0.5)::geometry, 0);
and then translate it calculating deltas:
st_translate(prePoly, 8.54736328125 - st_x(ST_Centroid(prePoly)),46.37156925087649 - st_y(ST_Centroid(prePoly)))
I'm not sure that i got the second problem right, but if you originally have big and small sides in meters, you can take one (for example, big one) as a radius of buffer and than calculate
xFactor = smallSide/bigSide, and yFactor = 1
In this case your ellipse will be ellongated along the Y axis.
推荐阅读
- perl - 使用任何可行的方法(PERL、SED、AWK)将文件行中的信息提取到列中
- python - 如何获取两个标记之间的子字符串并在Python中重复该过程N次
- java - 是否可以从 .forEach 方法列出文件特征?
- ios - 无法生成进程“/usr/bin/touch”(执行格式错误)
- python - 如何在文件中显示时间?(Python)
- google-apps-script - 我的 GSM Gmail 插件不显示该卡
- nlp - 如何在未标记的数据上微调 BERT?
- qt - qml 动态小部件的正确架构是什么?
- spring - 如何使用 envoy-proxy 在 Grpc 中以 json 格式发送错误响应
- javascript - `program.parse(process.argv)` 在 command.js 中做了什么?