Skip to content

Commit

Permalink
feat: all support for geom
Browse files Browse the repository at this point in the history
  • Loading branch information
yongcai committed Dec 26, 2024
1 parent d13eb2c commit 644a248
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/pyinnodb/disk_struct/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,35 @@ def _post_parsed(self, stream, context, path):
for i in range(self.size):
self.points.append(MPoint.parse_stream(stream))
elif self.point_type == 3: # POLYGON
self.polygons = []
self.polygon = []
self.psize = cs.Int32ul.parse_stream(stream)
for i in range(self.psize):
size = cs.Int32ul.parse_stream(stream)
points = []
for j in range(size):
points.append(MPoint.parse_stream(stream))
self.polygons.append(points)
self.polygon.append(points)
elif self.point_type == 4: # MULTIPOINT
self.size = cs.Int32ul.parse_stream(stream)
self.points = []
for i in range(self.size):
self.points.append(MGPoint.parse_stream(stream))
elif self.point_type == 5:
self.size = cs.Int32ul.parse_stream(stream)
self.lines = []
for i in range(self.size):
self.lines.append(MGPoint.parse_stream(stream))
elif self.point_type == 6:
self.size = cs.Int32ul.parse_stream(stream)
self.polygons = []
for i in range(self.size):
self.polygons.append(MGPoint.parse_stream(stream))

elif self.point_type == 7:
self.size = cs.Int32ul.parse_stream(stream)
self.geos = []
for i in range(self.size):
self.geos.append(MGPoint.parse_stream(stream))


def _post_build(self, obj, stream, context, path):
Expand All @@ -117,7 +133,7 @@ def _post_build(self, obj, stream, context, path):
stream.write(p.build())
elif self.point_type == 3:
stream.write(cs.Int32ul.build(self.psize))
for polygon in self.polygons:
for polygon in self.polygon:
if len(polygon) == 0:
continue
stream.write(cs.Int32ul.build(len(polygon)))
Expand All @@ -128,6 +144,20 @@ def _post_build(self, obj, stream, context, path):
stream.write(cs.Int32ul.build(self.size))
for p in self.points:
stream.write(p.build())
elif self.point_type == 5:
stream.write(cs.Int32ul.build(self.size))
for l in self.lines:
stream.write(l.build())

elif self.point_type == 6:
stream.write(cs.Int32ul.build(self.size))
for l in self.polygons:
stream.write(l.build())

elif self.point_type == 7:
stream.write(cs.Int32ul.build(self.size))
for l in self.geos:
stream.write(l.build())

class MGeo(CC):
SRID: int = cfield(cs.Int32ub)
Expand Down

0 comments on commit 644a248

Please sign in to comment.