VIKTOR Polyline / Polygon Input for Dynamo

Hello @mslootweg

I hope you are well.
The Dynamo workflow I am trying to upload to VIKTOR depends on an input closed polyline/polygon to determine the site boundary. Is it possible to link VIKTOR’s polyline future as an input to Dynamo?

Hi Bayo, could you provide me with an example Dynamo graph of what you would like to achieve from the input? You only have to provide a graph with the input as example, to keep it simple.

1 Like

Hello Marcel

Thanks for the response, and find the Dynamo file attached.
The group on top shows the ideal workflow. I essentially want the VIKTOR polyline to come into Dynamo as a polycurve.
The group below shows the intended result. A Dynamo surface is created from the polycurve. Please let me know if you have other questions.
Polycurve.dyn (31.5 KB)

Thanks Bayo,

Looking at your case, the easiest way I can see you can achieve this is by creating a string input node, and then sending the polygon from VIKTOR to Dynamo as a JSON string. The JSON string can then be converted with a node within Dynamo to a list of points, and the list of points can then be converted to a PolyCurve.

To summarise:

  1. Create an input node that accepts a string. In this example, let us call it “Polygon GeoJSON string”
  2. Within your VIKTOR project, convert your GeoPolygonField input (which gives you a GeoPolygon object) to a json string of list of coordinates. Here is a snippet:
file_path = Path(__file__).parent / "dynamo_model_sample_app.dyn"
_file = File.from_path(file_path)
dyn_file = DynamoFile(_file)

# convert the geopolygon to a MapPolygon
polygon = MapPolygon.from_geo_polygon(params.geopolygon)
# extract the geojson using the MapResult, and the dump it to a json string
polygon_json_string = json.dumps(MapResult([polygon]).geojson['features'][0]['geometry']['coordinates'][0])

# update the input field of the input node "Polygon GeoJSON string"
dyn_file.update("Polygon GeoJSON string", polygon_json_string)

  1. Again, within your Dynamo graph, add some blocks that convert the json string from the list of coordinates to a PolyCurve object. The steps are:
    3.1. Node 1: JSON string to List of Lists (e.g. [[-64.9, 32.5], [-79.9, 25.9], [-66.1, 18.3], [-64.9, 32.5]])
    3.2. Node 2: List of Lists to List of Points
    3.3. Node 3: List of Points to PolyCurve

Hopefully, if someone within the VIKTOR community with Dynamo experience has better alternatives, they will add to this conversation.

Let me know if this will work for you. If it is not clear, or if you have more questions, also let me know.

1 Like

Thanks Marcel. The idea makes sense in principle.
I will let you know if I run into any snags.

This worked. Thanks, Marcel. I, however, had to do other operations with Geopandas and Shapely to convert the coordinates into meters.

1 Like