I am trying to implement a custom script through the Sverchok addon, but am having some trouble.
Here is my script:
"""
in number s
out list v
out new_vertices v
"""
import geopandas as gpd
import pandas as pd
import fiona
from shapely.geometry import shape
import numpy as np
# read in gpkg layer as geopandas data frame
gpd1 = gpd.read_file("D:/0_RMaps/Testing/PythonPackagesInBlender/PythonPackagesInBlender.gpkg", layer = "shape1")
# read in geometry of gpkg layer as geoseries
gs = gpd.GeoSeries(gpd1["geometry"])
# call geo interface method on geoseries
gi = gs.__geo_interface__
# get coordinates from geo interface, returns coordinates as tuple
coords = gi['features'][0]['geometry']['coordinates']
# convert coordinates from tuple to list
coords_list = list(coords)
new_vertices = []
for x in range(5):
new_x = coords_list[0][x][0]
new_y = coords_list[0][x][1]
new_z = 0
new_vector = [new_x, new_y, new_z]
new_vertices.append(new_vector)
print(new_vertices)
The goals of this script are to:
- read in a layer from a gpkg
- convert this layer into a format usable in Sverchok
- starting with the geometry
So far I've been able to read in the layer and extract the geometry as a tuple. Now I am trying to convert the tuple into an array that Sverchok can use. When I implement this script and connect the output of the 'new_vertices' socket to a viewer node, I get a 'no data passed into socket' error:
Additionally, when I make this connection, I get the following message in the blender system console:
ERROR:sverchok.core.socket_data:116 :52:No data passed into socket 'data1'
INFO:sverchok.nodes.script.script1_lite 482 (SN: geopandas3.py):334:Unexpected error: <class 'TypeError'>
INFO:sverchok.nodes.script.script1_lite 485 (SN: geopandas3.py):334:on line: 26
Traceback (most recent call last):
File "C:\Users\davis_000\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\sverchok-master\nodes\script\script1_lite.py", line 470, in process_script
exec(self.script_str, locals(), locals())
File "<string>", line 26, in <module>
TypeError: 'list' object is not callable
Not sure what the 'list' object is not callable
error is about, I tried googling this but couldn't find anything.
And, when I run the script from the blender text editor, I get the expected output in the blender system console:
[[-3.68836355049336, -1.3570760357535328, 0], [1.7759814269738783, 0.14000477999091565, 0], [1.2894301618569308, 4.361772680390262, 0], [-7.273872104201315, 2.385626003607589, 0], [-3.68836355049336, -1.3570760357535328, 0]]
I'm confused as to why running the script from the text editor works (or at least produces an output), but why this output is not being recognized in Sverchok. Am I formatting the output of the for loop incorrectly? Any help or guidance on this would be great, feels like this is very close to working, but I can't figure out this last part.
Here is the output of the gs.__geo_interface__
line for reference:
{'type': 'FeatureCollection',
'features': [{'id': '0',
'type': 'Feature',
'properties': {},
'geometry': {'type': 'Polygon',
'coordinates': (((-3.68836355049336, -1.3570760357535328),
(1.7759814269738783, 0.14000477999091565),
(1.2894301618569308, 4.361772680390262),
(-7.273872104201315, 2.385626003607589),
(-3.68836355049336, -1.3570760357535328)),)},
'bbox': (-7.273872104201315,
-1.3570760357535328,
1.7759814269738783,
4.361772680390262)}],
'bbox': (-7.273872104201315,
-1.3570760357535328,
1.7759814269738783,
4.361772680390262)}
zip file with blend file, gpkg, script, jupyter notebook, and qgis map files: https://drive.google.com/file/d/1YGvzuPAhKAXhPsfV4FXDr0nOHNc_TFEE/view?usp=sharing
Thanks in advance,