developmentseed/geojson-pydantic

Problem with "wkt" method.

Closed this issue · 4 comments

When inheriting from the Point class, the "wkt" method does not work as I expect. It uses the class name to build wkt. It's right?
Example:

from geojson_pydantic import geometries as geom
class PointType(geom.Point):
    ... (my custom logic)

test = PointType(coordinates=[123, 123])
print(test.wkt)

>>> POINTTYPE (123.0 123.0)

I am expecting to get POINT (123.0 123.0) for example to use this in a database.

yeah it's because of

return self.__class__.__name__.upper()

I'm not sure if we can easily fix that.

for now I would recommend to do

from geojson_pydantic import geometries as geom
class Point(geom.Point):
    ... (my custom logic)

test = Point(coordinates=[123, 123])

Yes of course, I can name the class as "Point" or write my own _wkt_type method in my "PointType" class) It's not a problem for me.

And what is the problem of implementation now? Why can't you implement your own _wkt_type for each geometry class.

And what is the problem of implementation now?

the problem right now is that the wkt method use self.__class__.__name__.upper(), so if your class is name POINTTYPE, it will using POINTTYPE.

@property
def _wkt_type(self) -> str:
"""Return the WKT name of the geometry."""
return self.__class__.__name__.upper()

Why can't you implement your own _wkt_type for each geometry class.

you can, by probably do 👇

class PointType(geom.Point):
    ... (my custom logic)

    @property
    def _wkt_type(self) -> str:
        """Return the WKT name of the geometry."""
        return self.__class__.__name__.upper()

What if you changed it to something more like:

    @property
    def _wkt_type(self) -> str:
        """Return the WKT name of the geometry."""
        return self.type.upper()

Since type MUST exist, and can't be modified.