Skip to content

Commit

Permalink
gis
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed May 9, 2024
1 parent bde6a2d commit 8cd3f06
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default {
{
text: '知识', items: [
{ text: "opencv", link: '/chapter/tech/opencv' },
{ text: "gis", link: '/chapter/tech/gis' },
{ text: "线性代数", link: '/chapter/math/linearAlgebra' },
]
},
Expand Down
30 changes: 30 additions & 0 deletions docs/chapter/tech/gis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# gis
## postgis
### sql
将geometry类型的字段直接转换为svg图片,以显示轮廓。
核心做法:
1. 按最小的x、y坐标负向平移,以实现初始坐标为0
2. 取宽和高中的较大值来进行放大
3. 对svg的viewBox进行平移,以实现轮廓完全接边展示

```sql
SELECT ST_Scale(ST_Translate(geom, -1 * ST_XMin(geom), -1 * ST_YMin(geom))
, CEIL(GREATEST((ST_XMax(geom)-ST_YMin(geom)),(ST_YMax(geom)-ST_XMin(geom))))
, CEIL(GREATEST((ST_XMax(geom)-ST_YMin(geom)),(ST_YMax(geom)-ST_XMin(geom))))) AS scale_geom
, CEIL(GREATEST((ST_XMax(geom)-ST_YMin(geom)),(ST_YMax(geom)-ST_XMin(geom)))) AS sc
FROM region
WHERE geom IS NOT NULL
LIMIT 10
),
p AS (
SELECT ST_AsSvg(scale_geom,0,4) AS svg
,sc,ST_XMin(scale_geom) AS x_min
, ST_YMin(scale_geom) AS y_min
, ST_XMax(scale_geom) AS x_max
, ST_YMax(scale_geom) AS y_max
FROM q
)
SELECT CONCAT('<svg width="300" height="300" version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="',
CONCAT_WS(' ', 0, CEIL(-1*y_max), CEIL(( x_max-x_min)), CEIL(( y_max-y_min)) ), '"> <path d="', svg, '"></path></svg>') AS "svg"
FROM p
```
8 changes: 0 additions & 8 deletions docs/chapter/tech/rk.md

This file was deleted.

0 comments on commit 8cd3f06

Please sign in to comment.