send polygons
This commit is contained in:
+9
-9
@@ -72,11 +72,6 @@ def featureToSpeckle(
|
||||
)
|
||||
return None
|
||||
|
||||
# if geomType == "None":
|
||||
# geom = GisNonGeometryElement()
|
||||
# new_report = {"obj_type": geom.speckle_type, "errors": ""}
|
||||
# else:
|
||||
# Try to extract geometry
|
||||
skipped_msg = f"'{geomType}' feature skipped due to invalid geometry"
|
||||
try:
|
||||
geom, iterations = convertToSpeckle(
|
||||
@@ -123,6 +118,11 @@ def featureToSpeckle(
|
||||
else: # geom is None
|
||||
new_report = {"obj_type": "", "errors": skipped_msg}
|
||||
logToUser(skipped_msg, level=2, func=inspect.stack()[0][3])
|
||||
|
||||
dataStorage.latestActionFeaturesReport[
|
||||
len(dataStorage.latestActionFeaturesReport) - 1
|
||||
].update(new_report)
|
||||
return
|
||||
# geom = GisNonGeometryElement()
|
||||
except Exception as error:
|
||||
new_report = {
|
||||
@@ -135,12 +135,12 @@ def featureToSpeckle(
|
||||
func=inspect.stack()[0][3],
|
||||
)
|
||||
|
||||
#print(fieldnames)
|
||||
#print(attr_list)
|
||||
# print(fieldnames)
|
||||
# print(attr_list)
|
||||
attributes = Base()
|
||||
for i, name in enumerate(fieldnames):
|
||||
corrected = validateAttributeName(name, fieldnames)
|
||||
#print(corrected)
|
||||
# print(corrected)
|
||||
f_val = attr_list[i]
|
||||
if f_val == "NULL" or f_val is None or str(f_val) == "NULL":
|
||||
f_val = None
|
||||
@@ -156,7 +156,7 @@ def featureToSpeckle(
|
||||
|
||||
# if geom is not None and geom!="None":
|
||||
geom.attributes = attributes
|
||||
#print(geom.attributes)
|
||||
# print(geom.attributes)
|
||||
|
||||
dataStorage.latestActionFeaturesReport[
|
||||
len(dataStorage.latestActionFeaturesReport) - 1
|
||||
|
||||
@@ -102,9 +102,7 @@ def convertToSpeckle(
|
||||
|
||||
elif geomType == "Multipoint":
|
||||
print("__Multipoint conversion")
|
||||
f_shape = findTransformation(
|
||||
feature, geomType, layer_sr, projectCRS, layer
|
||||
)
|
||||
f_shape = findTransformation(feature, geomType, layer_sr, projectCRS, layer)
|
||||
if f_shape is None:
|
||||
return None
|
||||
result = [
|
||||
@@ -118,90 +116,59 @@ def convertToSpeckle(
|
||||
|
||||
elif geomType == "Polyline":
|
||||
print("__Polyline conversion")
|
||||
if feature.partCount == 1:
|
||||
result = anyLineToSpeckle(
|
||||
feature, feature, layer, dataStorage, xform_vars
|
||||
)
|
||||
result = addCorrectUnits(result, dataStorage)
|
||||
result = [result]
|
||||
else:
|
||||
all_parts = []
|
||||
for part in feature.getPart():
|
||||
all_parts.append(
|
||||
arcpy.Polyline(
|
||||
part,
|
||||
arcpy.Describe(layer.dataSource).SpatialReference,
|
||||
has_z=True,
|
||||
)
|
||||
# if feature.partCount == 1:
|
||||
# result = anyLineToSpeckle(
|
||||
# feature, feature, layer, dataStorage, xform_vars
|
||||
# )
|
||||
# result = addCorrectUnits(result, dataStorage)
|
||||
# result = [result]
|
||||
# else:
|
||||
all_parts = []
|
||||
for part in feature.getPart():
|
||||
all_parts.append(
|
||||
arcpy.Polyline(
|
||||
part,
|
||||
arcpy.Describe(layer.dataSource).SpatialReference,
|
||||
has_z=True,
|
||||
)
|
||||
result = [
|
||||
anyLineToSpeckle(poly, feature, layer, dataStorage, xform_vars)
|
||||
for poly in all_parts
|
||||
]
|
||||
for r in result:
|
||||
r = addCorrectUnits(r, dataStorage)
|
||||
)
|
||||
result = [
|
||||
anyLineToSpeckle(poly, feature, layer, dataStorage, xform_vars)
|
||||
for poly in all_parts
|
||||
]
|
||||
for r in result:
|
||||
r = addCorrectUnits(r, dataStorage)
|
||||
|
||||
element = GisLineElement(units=units, geometry=result)
|
||||
|
||||
elif geomType == "Polygon":
|
||||
print("__Polygon conversion")
|
||||
if feature.partCount > 1:
|
||||
|
||||
for i, x in enumerate(feature):
|
||||
polygon, iterations = polygonToSpeckle(
|
||||
poly,
|
||||
feature,
|
||||
layer,
|
||||
height,
|
||||
translationZaxis,
|
||||
dataStorage,
|
||||
xform,
|
||||
)
|
||||
result.append(polygon)
|
||||
for r in result:
|
||||
if r is None:
|
||||
continue
|
||||
r.units = units
|
||||
r.boundary.units = units
|
||||
for v in r.voids:
|
||||
if v is not None:
|
||||
v.units = units
|
||||
for v in r.displayValue:
|
||||
if v is not None:
|
||||
v.units = units
|
||||
|
||||
element = GisPolygonElement(units=units, geometry=result)
|
||||
# if feature.partCount > 1:
|
||||
r"""
|
||||
if feature.partCount == 1:
|
||||
result = polygonToSpeckle(
|
||||
feature, feature, index, layer, dataStorage, xform_vars
|
||||
)
|
||||
result = [result]
|
||||
|
||||
else:
|
||||
# return polygonToSpeckle(geom, index, layer, geomMultiType, dataStorage)
|
||||
"""
|
||||
result = [
|
||||
polygonToSpeckle(geom, feature, index, layer, dataStorage, xform_vars)
|
||||
for geom in feature.getPart()
|
||||
]
|
||||
|
||||
result, iterations = polygonToSpeckle(
|
||||
feature,
|
||||
feature,
|
||||
layer,
|
||||
height,
|
||||
translationZaxis,
|
||||
dataStorage,
|
||||
xform,
|
||||
)
|
||||
if result is None:
|
||||
return None, None
|
||||
result.units = units
|
||||
if result.boundary is not None:
|
||||
result.boundary.units = units
|
||||
for v in result.voids:
|
||||
for r in result:
|
||||
if r is None:
|
||||
continue
|
||||
r.units = units
|
||||
r.boundary.units = units
|
||||
for v in r.voids:
|
||||
if v is not None:
|
||||
v.units = units
|
||||
for v in r.displayValue:
|
||||
if v is not None:
|
||||
v.units = units
|
||||
try: # if mesh creation failed, displayValue stays None
|
||||
for v in result.displayValue:
|
||||
if v is not None:
|
||||
v.units = units
|
||||
except:
|
||||
pass
|
||||
|
||||
if not isinstance(result, List):
|
||||
result = [result]
|
||||
|
||||
element = GisPolygonElement(units=units, geometry=result)
|
||||
|
||||
elif geomType == "MultiPatch":
|
||||
|
||||
@@ -17,6 +17,7 @@ from speckle.speckle.converter.geometry.mesh import (
|
||||
from speckle.speckle.converter.geometry.point import pointToCoord, pointToNative
|
||||
from speckle.speckle.converter.layers.symbology import featureColorfromNativeRenderer
|
||||
from speckle.speckle.converter.geometry.polyline import (
|
||||
anyLineToSpeckle,
|
||||
polylineFromVerticesToSpeckle,
|
||||
speckleArcCircleToPoints,
|
||||
curveToSpeckle,
|
||||
@@ -46,7 +47,7 @@ def polygonToSpeckleMesh(geom, index: int, layer, multitype: bool, dataStorage):
|
||||
# print("____start enumerate feature")
|
||||
# print(p) #<geoprocessing array object object at 0x0000026796C77110>
|
||||
print(p)
|
||||
boundary, voids = getPolyBoundaryVoids(p, layer, multitype, dataStorage)
|
||||
boundary, voids = getPolyBoundaryVoids(p, layer, dataStorage)
|
||||
# print(boundary)
|
||||
# print(voids)
|
||||
polyBorder = speckleBoundaryToSpecklePts(boundary)
|
||||
@@ -84,71 +85,47 @@ def polygonToSpeckleMesh(geom, index: int, layer, multitype: bool, dataStorage):
|
||||
return None
|
||||
|
||||
|
||||
def getPolyBoundaryVoids(geom, layer, multiType: bool, dataStorage):
|
||||
def getPolyBoundaryVoids(feature, layer, dataStorage, xform_vars=None):
|
||||
# print("__getPolyBoundaryVoids__")
|
||||
voids: List[Union[None, Polyline, Arc, Line, Polycurve]] = []
|
||||
# print(voids)
|
||||
boundary = None
|
||||
pointList = []
|
||||
try:
|
||||
# partsBoundaries = []
|
||||
# partsVoids = []
|
||||
if multiType is False: # Multipolygon
|
||||
try: # might be no property "has curves"
|
||||
if geom.hasCurves:
|
||||
print("has curves")
|
||||
# geometry SHAPE@ tokens: https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/reading-geometries.htm
|
||||
print(geom.JSON)
|
||||
boundary = curveToSpeckle(geom, "Polygon", geom, layer, dataStorage)
|
||||
else:
|
||||
print("no curves")
|
||||
for p in geom:
|
||||
for pt in p:
|
||||
# print(pt)
|
||||
if pt != None:
|
||||
pointList.append(pt)
|
||||
boundary = polylineFromVerticesToSpeckle(
|
||||
pointList, True, geom, layer, dataStorage
|
||||
)
|
||||
print(boundary)
|
||||
except: # for multipatches, no property "has curves"
|
||||
# print("multipatch")
|
||||
for pt in geom:
|
||||
# print(pt)
|
||||
if pt != None:
|
||||
pointList.append(pt)
|
||||
# if multiType is False: # Multipolygon
|
||||
# boundary = anyLineToSpeckle(feature, feature, layer, dataStorage, xform_vars)
|
||||
|
||||
# else:
|
||||
print("multi type")
|
||||
for i, pt in enumerate(feature):
|
||||
print(pt) # 284394.58100903 5710688.11602606 NaN NaN
|
||||
# for pt in p:
|
||||
# print(pt)
|
||||
if pt == None and boundary == None: # first break
|
||||
boundary = polylineFromVerticesToSpeckle(
|
||||
pointList, True, geom, layer, dataStorage
|
||||
pointList, True, feature, layer, dataStorage
|
||||
)
|
||||
# print(boundary)
|
||||
# partsBoundaries.append(boundary)
|
||||
# partsVoids.append([])
|
||||
print("__Boundary:")
|
||||
print(boundary) # Polyline
|
||||
pointList = []
|
||||
elif pt == None and boundary != None: # breaks btw voids
|
||||
void = polylineFromVerticesToSpeckle(
|
||||
pointList, True, feature, layer, dataStorage
|
||||
)
|
||||
voids.append(void)
|
||||
pointList = []
|
||||
elif pt != None: # add points to whatever list (boundary or void)
|
||||
pointList.append(pt)
|
||||
|
||||
else:
|
||||
print("multi type")
|
||||
for i, p in enumerate(geom):
|
||||
print(p)
|
||||
for pt in p:
|
||||
# print(pt) # 284394.58100903 5710688.11602606 NaN NaN
|
||||
if pt == None and boundary == None: # first break
|
||||
boundary = polylineFromVerticesToSpeckle(
|
||||
pointList, True, geom, layer, dataStorage
|
||||
)
|
||||
pointList = []
|
||||
elif pt == None and boundary != None: # breaks btw voids
|
||||
void = polylineFromVerticesToSpeckle(
|
||||
pointList, True, geom, layer, dataStorage
|
||||
)
|
||||
voids.append(void)
|
||||
pointList = []
|
||||
elif pt != None: # add points to whatever list (boundary or void)
|
||||
pointList.append(pt)
|
||||
if boundary != None and len(pointList) > 0: # remaining polyline
|
||||
void = polylineFromVerticesToSpeckle(
|
||||
pointList, True, feature, layer, dataStorage
|
||||
)
|
||||
voids.append(void)
|
||||
|
||||
if boundary != None and len(pointList) > 0: # remaining polyline
|
||||
void = polylineFromVerticesToSpeckle(
|
||||
pointList, True, geom, layer, dataStorage
|
||||
)
|
||||
voids.append(void)
|
||||
elif boundary is None: # no voids
|
||||
boundary = polylineFromVerticesToSpeckle(
|
||||
pointList, True, feature, layer, dataStorage
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logToUser(str(e), level=2, func=inspect.stack()[0][3])
|
||||
@@ -196,15 +173,17 @@ def multiPolygonToSpeckle(geom, index: str, layer, multiType: bool, dataStorage)
|
||||
return polygon
|
||||
|
||||
|
||||
def polygonToSpeckle(geom, index: int, layer, multitype: bool, dataStorage):
|
||||
def polygonToSpeckle(geom, feature, index: int, layer, dataStorage, xform_vars):
|
||||
"""Converts a Polygon to Speckle"""
|
||||
# polygon = Base(units="m")
|
||||
polygon = GisPolygonGeometry(units="m")
|
||||
try:
|
||||
print("___Polygon to Speckle____")
|
||||
print(geom)
|
||||
print(geom) # array
|
||||
|
||||
boundary, voids = getPolyBoundaryVoids(geom, layer, multitype, dataStorage)
|
||||
boundary, voids = getPolyBoundaryVoids(geom, layer, dataStorage, xform_vars)
|
||||
print(boundary)
|
||||
print(voids)
|
||||
|
||||
data = arcpy.Describe(layer.dataSource)
|
||||
sr = data.spatialReference
|
||||
@@ -213,30 +192,19 @@ def polygonToSpeckle(geom, index: int, layer, multitype: bool, dataStorage):
|
||||
return None
|
||||
polygon.boundary = boundary
|
||||
polygon.voids = voids
|
||||
polygon.displayValue = [boundary] + voids
|
||||
# polygon.displayValue = [boundary] + voids
|
||||
# print(boundary)
|
||||
|
||||
############# mesh
|
||||
vertices = []
|
||||
polyBorder = []
|
||||
polyBorder = boundary.as_points()
|
||||
total_vertices = 0
|
||||
if isinstance(boundary, Circle) or isinstance(boundary, Arc):
|
||||
polyBorder = speckleArcCircleToPoints(boundary)
|
||||
elif isinstance(boundary, Polycurve):
|
||||
polyBorder = specklePolycurveToPoints(boundary)
|
||||
# polygon.boundary.displayValue.closed = True
|
||||
elif isinstance(boundary, Line):
|
||||
pass
|
||||
elif isinstance(boundary, Polyline):
|
||||
try:
|
||||
polyBorder = boundary.as_points()
|
||||
except:
|
||||
pass # if Line
|
||||
# print(polyBorder)
|
||||
|
||||
if len(polyBorder) > 2: # at least 3 points
|
||||
print("make meshes from polygons")
|
||||
if len(voids) == 0: # if there is a mesh with no voids
|
||||
print("no voids")
|
||||
print(polyBorder)
|
||||
for pt in polyBorder:
|
||||
if isinstance(pt, Point):
|
||||
pt = pointToNative(pt, sr, dataStorage).getPart() # SR unknown
|
||||
@@ -252,11 +220,11 @@ def polygonToSpeckle(geom, index: int, layer, multitype: bool, dataStorage):
|
||||
# print(faces)
|
||||
# else: https://docs.panda3d.org/1.10/python/reference/panda3d.core.Triangulator
|
||||
else:
|
||||
print("voids")
|
||||
print(polyBorder)
|
||||
trianglator = Triangulator()
|
||||
faces = []
|
||||
|
||||
# add boundary points
|
||||
# polyBorder = boundary.as_points()
|
||||
pt_count = 0
|
||||
# add extra middle point for border
|
||||
for pt in polyBorder:
|
||||
@@ -323,6 +291,7 @@ def polygonToSpeckle(geom, index: int, layer, multitype: bool, dataStorage):
|
||||
colors = [col for i in ran] # apply same color for all vertices
|
||||
mesh = constructMesh(vertices, faces, colors)
|
||||
|
||||
print(mesh)
|
||||
if mesh is not None:
|
||||
polygon.displayValue = [mesh]
|
||||
else:
|
||||
|
||||
@@ -91,16 +91,21 @@ def anyLineToSpeckle(geom, feature, layer, dataStorage, xform_vars=None):
|
||||
# multiType = feature.isMultipart
|
||||
|
||||
# if multiType is False:
|
||||
if geom.hasCurves:
|
||||
print("has curves")
|
||||
# geometry SHAPE@ tokens: https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/reading-geometries.htm
|
||||
# print(geom.JSON)
|
||||
new_geom = geom.densify("GEODESIC", 0.1)
|
||||
f_shape = findTransformation(new_geom, *xform_vars)
|
||||
if f_shape is None:
|
||||
return None
|
||||
else:
|
||||
try:
|
||||
if geom.hasCurves:
|
||||
print("has curves")
|
||||
# geometry SHAPE@ tokens: https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/reading-geometries.htm
|
||||
# print(geom.JSON)
|
||||
new_geom = geom.densify("GEODESIC", 0.1)
|
||||
if xform_vars is not None:
|
||||
f_shape = findTransformation(new_geom, *xform_vars)
|
||||
if f_shape is None:
|
||||
return None
|
||||
else:
|
||||
new_geom = geom
|
||||
except: # no curves
|
||||
new_geom = geom
|
||||
|
||||
print(new_geom) # describe geometry object
|
||||
for p in new_geom:
|
||||
print(p) # array
|
||||
@@ -159,7 +164,8 @@ def polylineFromVerticesToSpeckle(
|
||||
"""Converts a Polyline to Speckle"""
|
||||
polyline = Polyline(units="m")
|
||||
try:
|
||||
|
||||
print("__polylineFromVerticesToSpeckle")
|
||||
print(vertices)
|
||||
if isinstance(vertices, list):
|
||||
if len(vertices) > 0 and isinstance(vertices[0], Point):
|
||||
specklePts = vertices
|
||||
|
||||
+6
-2
@@ -1531,7 +1531,9 @@ def addVectorMainThread(obj: Tuple):
|
||||
# if not os.path.exists(path): os.makedirs(path)
|
||||
# print(path)
|
||||
|
||||
newName = removeSpecialCharacters(nameBase + SYMBOL + layer.name) + "_Speckle"
|
||||
newName = removeSpecialCharacters(
|
||||
nameBase + SYMBOL + layer.name
|
||||
) # + "_Speckle"
|
||||
if "." in newName:
|
||||
newName = ".".join(newName.split(".")[:-1])
|
||||
|
||||
@@ -1812,7 +1814,9 @@ def addTableMainThread(obj: Tuple) -> Union[str, None]:
|
||||
# newName, layerGroup = newLayerGroupAndName(layerName, streamBranch, project)
|
||||
newFields = getLayerAttributes(layer_elements)
|
||||
|
||||
newName = removeSpecialCharacters(nameBase + SYMBOL + layer.name) + "_Speckle"
|
||||
newName = removeSpecialCharacters(
|
||||
nameBase + SYMBOL + layer.name
|
||||
) # + "_Speckle"
|
||||
|
||||
shortName = newName.split(SYMBOL)[len(newName.split(SYMBOL)) - 1][:50]
|
||||
# print(f"Final short name: {shortName}")
|
||||
|
||||
Reference in New Issue
Block a user