简体   繁体   English

在postgis中存储多边形和几何

[英]store polygons and geometry in postgis

I'm hardly trying to extract data o polygons from Blender to PostGIS via Python. 我几乎没有尝试通过Python从Blender提取数据或多边形到PostGIS。 For the beginning I'm trying all this stuff with a simple cube. 首先,我尝试使用一个简单的多维数据集尝试所有这些东西。 At all I want to get a pure POLYGON - GEOMETRY-Type in PostGIS which looks like POLYGON((x1 y1 z1, x2 y2 z2,.....)) I can read information from Blender in this way: 我想在PostGIS中获得一个纯粹的POLYGON-GEOMETRY-Type,它看起来像POLYGON((x1 y1 z1,x2 y2 z2,.....))我可以用这种方式从Blender中读取信息:

The vectors: 向量:

verts=[ 
<Vector (1.0000, 1.0000, -1.0000)> ,
<Vector (1.0000, -1.0000, -1.0000)> ,
<Vector (-1.0000, -1.0000, -1.0000)> ,
<Vector (-1.0000, 1.0000, -1.0000)> ,
<Vector (1.0000, 1.0000, 1.0000)> ,
<Vector (1.0000, -1.0000, 1.0000)> ,
<Vector (-1.0000, -1.0000, 1.0000)> ,
<Vector (-1.0000, 1.0000, 1.0000)> ,
 ]

and the faces (the numbers are the vertices which form a polygon): 和面(数字是形成多边形的顶点):

faces = [
(0, 1, 2, 3)
(4, 7, 6, 5)
(0, 4, 5, 1)
(1, 5, 6, 2)
(2, 6, 7, 3)
(4, 0, 3, 7)
]

Now I don't know how to get this information into a POLYGON-GEOMETRY-structure to store it in PostgreSQL/PostGIS. 现在,我不知道如何将此信息存储到POLYGON-GEOMETRY结构中,以将其存储在PostgreSQL / PostGIS中。

In the end I want a POLYGON((...)) for each face of the cube. 最后,我要为多维数据集的每个面都添加一个POLYGON((...))。 And I want to do this for more complex 3D-models out of Blender. 我想对Blender中更复杂的3D模型执行此操作。 With POLYGON- or TIN-GEOMETRY.... But at first I need to know how to interact with the geometries with Python. 使用POLYGON-或TIN-GEOMETRY...。但是首先,我需要知道如何使用Python与几何进行交互。

I hope you can get me a little further. 我希望你能使我更进一步。 I'm thankful for any hint. 我很感谢任何提示。 Thanks! 谢谢! J Ĵ

I am not quite sure about the Blender's internal object model so I have created some dummy data for that. 我不太了解Blender的内部对象模型,因此为此创建了一些虚拟数据。 But I think the end result should be close to what you are looking for: 但我认为最终结果应该接近您想要的结果:

verts = [[1.0,-1.0,0.0]]*8
faces = [
    (0, 1, 2, 3),
    (4, 7, 6, 5),
    (0, 4, 5, 1),
    (1, 5, 6, 2),
    (2, 6, 7, 3),
    (4, 0, 3, 7),
]

# ---------------------------------------------
# PostGIS POLYGON data formatting happens next

for f in faces:
    print("POLYGON((", end="")
    for point in f:
        v = verts[point]
        print("{} {} {} ".format(v[0], v[1], v[2]), end="")
    print("))")

# Will print....

# POLYGON((1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 ))
# POLYGON((1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 ))
# POLYGON((1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 ))
# POLYGON((1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 ))
# POLYGON((1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 ))
# POLYGON((1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 ))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM