Specklepy making keys filterable and searchable in the viewer

Hi everyone,

I have some I’ve been working on to get contours into speckle and send them as commits. I have made a key named ‘Elevation’ which has each corresponding elevation to its curve. It does show up on the speckle viewer ‘Speckle’. However, I cannot filter by the values.

speckle_contours = []
                for feature in topography_data["features"]:
                    elevation = feature['attributes']['elevation']
                    geometry = feature["geometry"]
                    for ring in geometry["paths"]:
                        points = []
                        spec_points = []
                        for coord in ring:
                            point = rh.Point3d(coord[0], coord[1], 0)
                            spec_point = point
                            spec_point = spec_point.Transform(rh.Transform.Translation(spec_translation_vector))
                            speckle_point = [spec_point.X, spec_point.Y, elevation]
                            spec_points.append(speckle_point)
                            points.append(point)
                            all_points.append(point)
                        polyline = rh.Polyline(points)
                        spec_points_flat = [point for sublist in spec_points for point in sublist]
                        speckle_polyline = Polyline(value=spec_points_flat, closed=False)
                        speckle_polyline["Elevation"] = elevation
                        speckle_contours.append(speckle_polyline)

This is how I’m sending the data.

server_transport = ServerTransport(stream_id='16a7ca997a', client=client)
    data = speckle_contours
    speckle_geometry = speckle_objects.Base(data=data)
    object_id = operations.send(
        speckle_geometry, transports=[server_transport])
    client.commit.create(stream_id='16a7ca997a', object_id=object_id, message=address)

Thanks!

Hi @Rivindu_Bandara, things are looking ok on your end, I think the problem is on our end! I suspect the viewer filtering and colouring might not work as expected with line geometries. I’m pinging @alex to see if that is the case (I remember us discussing this in the distant past and saying it’s an okay compromise until someone screams for it? - to be double checked).

Unrelated, I’m spotting a wee bit of a potential later problem: your data array is not detached, so basically the polylines live inside the object. You’d want to ideally detach them, so they exist as individual objects in the db! I don’t know enough python to show you how, but perhaps @jonathon will have some time to show you.

I spotted that too - I can pick up the python side of things with @Rivindu_Bandara :wink:

Hi @Rivindu_Bandara
Currently, numeric filters are not supported by line geometries (any kind of lines). However, we are planning to address this issue in the near future. I’ve added a task for this as well.

Meanwhile, there is a way you could theoretically color the lines differently based on an ‘Elevation’ property. If ‘Elevation’ were a string instead of a number, you could use it to apply a filter, which will color each line differently based on the ‘Elevation’ value. However, the colors would not be in a gradient fashion, and you wouldn’t have control over which elevation lines to hide/show. I’m not sure what your exact use case is, and this might not be enough, but I’m just putting this here in case it’s any help.

2 Likes