Hello!
Here is yet another request for hand-holding with GRASS GIS. This time it’s a question on pygrass API, version 7.8.5. I want to create a new vector map from a Python script. The steps I’m following are:
-
Create a VectorTopo object with.
-
Define attribute columns: cols = [(column name, type), …]
-
Open the VectorTopo object in write mode: write(“w”, tab_cols=cols, …).
-
Add geometry objects, in my case it’s Area objects, one by one using write() interface.
-
Commit changes and close the VectorTopo.
Step 4, however, is causing “AttributeError” in a pygrass module. Stack trace:
Traceback (most recent call last):
File “stream_features.py”, line 404, in
generateWatersheds(ssegs, dwsmapname)
File “stream_features.py”, line 359, in generateWatersheds
dwsvector.write(
File “/Applications/GRASS-7.8.app/Contents/Resources/etc/python/grass/pygrass/errors.py”, line 15, in wrapper
return method(self, *args, **kargs)
File “/Applications/GRASS-7.8.app/Contents/Resources/etc/python/grass/pygrass/vector/init.py”, line 217, in write
result = self._write_area(geo_obj)
AttributeError: ‘VectorTopo’ object has no attribute ‘_write_area’
Can someone shed light on where my understanding is going wrong? Is this a bug in vector/init.py? The code snippet for reference:
dwsvector = vector.VectorTopo(“differential_watersheds”)
dwscols = [(“cat”, “INTEGER PRIMARY KEY”),
(“stream1”, “INTEGER”),
(“stream2”, “INTEGER”)]
dwsvector.open(“w”, tab_name=dwsmapname, tab_cols=dwscols, overwrite=True)
cat = 1
“boundary” is a vector.geometry.Boundary object, obtained
from an existing vector map that is opened previously.
areageom = vector.geometry.Area(v_id=boundary.id, c_mapinfo=boundary.c_mapinfo)
dwsvector.write(
areageom,
cat,
attrs=(boundary.attrs[“s1”], boundary.attrs[“s2”]))
The AttributeError thrown when the write() method above is invoked.
Hope the problem description is clear, if it isn’t, please let me know.
Asim