1

I want to insert records from an API to my database postGIS. The api geometry respond with a mix of linestring and mulitlinestring with Z value.

How can i mix both types into the same geometry column?

As soon as i hit a record that is a linestring I get an data type error. If i use geometry type Geometry then I Geometry has Z dimension but column does not.

Here is my table definition. How can I define a table which can mix simple/multilinestring with Z value?

class Item(Base):
    __tablename__ = 'test'

    id = Column(Integer, primary_key=True)
    kategori = Column(String)
    geom = Column(Geometry('MultiLineStringZ', dimension=3))
geogrow
  • 485
  • 2
  • 9
  • 26

1 Answers1

0

You can force your LineString to be MultiLineString => ST_Multi() (https://postgis.net/docs/ST_Multi.html)

And, you can also force the geom to be 3D => ST_Force3D()(https://postgis.net/docs/ST_Force_3D.html)

By combining both functions :

ST_Force3D(ST_Multi(my_linestring))

you will achieve what your looking for.

boris_atw
  • 233
  • 1
  • 2
  • 10