Ticket #68 (defect)
Opened 3 years ago
Last modified 2 years ago
PCL-Spatial geometries generated using fromWKT and fromWKB classmethods don't preserve their parent class
Status: new
| Reported by: | hobu | Assigned to: | seang |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | Spatial and Geometry | Version: | |
| Keywords: | Cc: | ||
I would like to have a subclass of Point that defines a hexagon buffer, as opposed to using GEOS' buffer function. It behaves as expected until you want to instantiate one using the fromWKT or fromWKB classmethods.
class Structure(Point):
def buffer(self, side):
radical_3 = math.sqrt(3.0)
shell = LinearRing([
Point(self.x - side*2.0/radical_3, self.y),
Point(self.x - side/radical_3, self.y + side),
Point(self.x + side/radical_3, self.y + side),
Point(self.x + side*2.0/radical_3, self.y),
Point(self.x + side/radical_3, self.y - side),
Point(self.x - side/radical_3, self.y - side),
Point(self.x - side*2.0/radical_3, self.y)
])
return Polygon(shell)
If we do set the class to the super's thisclass in the fromWKB and fromWKT classmethods, Structure is preserved as the class type when we do Structure.fromWKT(wkt)
Replace this:
g.__class__ = CLASS_TYPE[g.getTypeId()]
With this:
if super(cls):
g.__class__= super(cls).__thisclass__
else:
g.__class__ = CLASS_TYPE[g.getTypeId()]
Change History
04/23/06 08:41:24: Modified by seang
04/23/06 09:55:20: Modified by hobu
I disagree that this complicates Geometry any more so than it already is. I also disagree that this is a rare use case. In a GUI-type application, it would be handy to have subclasses of Geometries that knew how to display themselves. Implementing yet another wrapper around the factories for this one thing when all of the rest of it would be unchanged is tedious.
I don't think PCL is doing the right thing here and should preserve the superclass in the factory methods if it was given one. What is the compelling argument not to do this?
04/24/06 09:51:55: Modified by hobu
Actually, to restore the behavior of being able to do Geometry.fromWKB() and have it return the type of the GEOSGeometry in the normal case is this:
if super(cls).__thisclass__ in CLASS_TYPE or cls == Geometry:
g.__class__ = CLASS_TYPE[g.getTypeId()]
else:
g.__class__= super(cls).__thisclass__
07/17/06 13:03:06: Modified by hobu
Is this one DOA?

Howard and I debated this on IRC a bit. My take is that this is a rare use case, and unnecessarily complicates (if only by a couple lines) the Geometry factory methods. geometry.py should stay focussed on the simple features geometries. Applications that need special new geometries could easily implement their own factories.