0

By now I have this code:

value_literal = Column(String())
value_point = Column(Geometry('POINT'))
value_multipoint = Column(Geometry('MULTIPOINT'))
value_line = Column(Geometry('LINESTRING'))
value_multiline = Column(Geometry('MULTILINESTRING'))
value_polygon = Column(Geometry('POLYGON'))
value_multipolygon = Column(Geometry('MULTIPOLYGON'))

but I must consider all cases when dealing with an object: indeed, its geometric value can be a point, a line, and so on. It could be great if I would have only one field that would contain either a point, or a line, or a multipoint, etc...

Is it possible?

Georgy
  • 12,464
  • 7
  • 65
  • 73
lolveley
  • 1,659
  • 2
  • 18
  • 34
  • All the Shapely geometry objects share a common parent class `shapely.geometry.base.BaseGeometry`. Not sure if it can help, as I never worked with geoalchemy. – Georgy Jul 18 '19 at 08:38
  • well I tried geom = Column(BaseGeometry) but it seems not to be supported : I got "AttributeError: type object 'BaseGeometry' has no attribute '_set_parent_with_dispatch'" – lolveley Jul 18 '19 at 08:53
  • I wonder what happens if you leave it without an argument as `Column(Geometry())`. [Docs](https://geoalchemy-2.readthedocs.io/en/latest/types.html#geoalchemy2.types._GISType) say that default value is `"GEOMETRY"`, but Shapely doesn't have such a geometry object. So, could it be that it's the same as `BaseGeometry`? – Georgy Jul 18 '19 at 09:03
  • well, actually it works! to retrieve the shape, one must use "shp=geoalchemy2.shape.to_shape(city.geom)" where city is the result of the session.query request. thanks! I you make of it an answer, I will mark is as the correct answer. – lolveley Jul 18 '19 at 10:16
  • Glad it worked! I think It's better if you write the answer yourself. I really know nothing about geoalchemy and was just shooting in the dark with that "GEOMETRY" type :) – Georgy Jul 18 '19 at 10:25

0 Answers0