Skip to content

Commit

Permalink
Support both POINT and LINESTRING in one column
Browse files Browse the repository at this point in the history
  • Loading branch information
Erutis committed Jul 1, 2024
1 parent 5ea1d5a commit 0e1dcff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/db_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Trajectory(Base):
id = Column(Integer, primary_key=True)
create_time = Column(TIMESTAMP, default=datetime.now(timezone.utc))
updated_time = Column(TIMESTAMP, default=datetime.now(timezone.utc))
geom = Column(Geometry("LINESTRINGZM"))
geom = Column(Geometry("GEOMETRYZM"))
feed_item_id = Column(UUID)

def to_dict(self):
Expand Down
12 changes: 8 additions & 4 deletions app/generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ def main():
for _ in range(5):
try:
# Create rows from sample data
linestring, geom_type = create_sample_linestring(central_park)

sample_data = [
Trajectory(
geom=f"SRID=4326;LINESTRINGZM({create_sample_linestring(central_park)})",
geom=f"SRID=4326;{geom_type}({linestring})",
feed_item_id=uuid.uuid4(),
)
]
Expand All @@ -59,13 +61,15 @@ def create_sample_linestring(area):
time = time + int(random.uniform(0, 5)) # time
linestring += f"{lon} {lat} {alt} {time},"

# Linestring hates being alone and I don't wanna deal with POINTs
# If only one item in linestring, geom_type is a POINT, else LINESTRING
if num_of_entries <= 1:
linestring += linestring
geom_type = "POINTZM"
else:
geom_type = "LINESTRINGZM"

linestring = linestring[:-1]
print(f"HERE'S MY LINESTRING BETCH: {linestring}")
return linestring
return linestring, geom_type


if __name__ == "__main__":
Expand Down

0 comments on commit 0e1dcff

Please sign in to comment.