-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.20_Attribute types and geometry types aligned with arcgis_to_DEV (#205
) * adjust field types and geometry types to be synced with DUI3 ArcGIS * add displayVal to polylines and points * support old geometry types and field types * receive new GIS classes without .geometry
- Loading branch information
1 parent
f480441
commit bdc1398
Showing
5 changed files
with
209 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from enum import Enum | ||
|
||
|
||
class GISAttributeFieldType(str, Enum): | ||
"""GIS VectorLayer geometry types""" | ||
|
||
GUID_TYPE = "Guid" | ||
OID = "Oid" | ||
STRING_TYPE = "String" | ||
FLOAT_TYPE = "Float" | ||
INTEGER_TYPE = "Integer" | ||
BIGINTEGER = "BigInteger" | ||
SMALLINTEGER = "SmallInteger" | ||
DOUBLE_TYPE = "Double" | ||
DATETIME = "DateTime" | ||
DATEONLY = "DateOnly" | ||
TIMEONLY = "TimeOnly" | ||
TIMESTAMPOFFSET = "TimeStampOffset" | ||
BOOL = "Bool" | ||
|
||
@staticmethod | ||
def assign_speckle_field_type(type_index: int) -> "GISAttributeFieldType": | ||
"""Assign Speckle representation of the Field type.""" | ||
val_dict = { | ||
1: GISAttributeFieldType.BOOL, | ||
2: GISAttributeFieldType.INTEGER_TYPE, | ||
6: GISAttributeFieldType.DOUBLE_TYPE, | ||
10: GISAttributeFieldType.STRING_TYPE, | ||
14: GISAttributeFieldType.DATEONLY, | ||
15: GISAttributeFieldType.TIMEONLY, | ||
16: GISAttributeFieldType.DATETIME, | ||
} | ||
result: GISAttributeFieldType = val_dict.get( | ||
type_index, GISAttributeFieldType.STRING_TYPE | ||
) | ||
return result | ||
|
||
@staticmethod | ||
def get_native_field_type_from_speckle(field_type: str) -> int: | ||
"""Get native Field type (not currently used).""" | ||
|
||
val_dict = { | ||
GISAttributeFieldType.BOOL: 1, | ||
GISAttributeFieldType.STRING_TYPE: 10, | ||
GISAttributeFieldType.GUID_TYPE: 10, | ||
GISAttributeFieldType.OID: 10, | ||
GISAttributeFieldType.TIMESTAMPOFFSET: 10, | ||
GISAttributeFieldType.FLOAT_TYPE: 6, | ||
GISAttributeFieldType.DOUBLE_TYPE: 6, | ||
GISAttributeFieldType.INTEGER_TYPE: 2, | ||
GISAttributeFieldType.BIGINTEGER: 2, | ||
GISAttributeFieldType.SMALLINTEGER: 2, | ||
GISAttributeFieldType.DATETIME: 16, | ||
GISAttributeFieldType.DATEONLY: 14, | ||
GISAttributeFieldType.TIMEONLY: 15, | ||
} | ||
|
||
try: | ||
speckle_field_type = GISAttributeFieldType(field_type) | ||
result: int = val_dict.get(speckle_field_type, 10) | ||
except: | ||
# for older commits | ||
try: | ||
result: int = val_dict.get(int(field_type), 10) | ||
except: | ||
pass | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from enum import Enum | ||
from typing import Optional | ||
|
||
|
||
class GISLayerGeometryType(str, Enum): | ||
"""GIS VectorLayer geometry types""" | ||
|
||
NONE = "None" | ||
POINT = "Point" | ||
POLYLINE = "Polyline" | ||
POLYGON = "Polygon" | ||
POLYGON3D = "Polygon3d" | ||
MULTIPATCH = "Multipatch" | ||
POINTCLOUD = "Pointcloud" | ||
|
||
@staticmethod | ||
def assign_speckle_layer_geometry_type( | ||
native_geom_type: int, | ||
) -> "GISLayerGeometryType": | ||
"""Get Speckle representation of the Layer Geometry Type.""" | ||
|
||
type_index: int = native_geom_type % 1000 # e.g.3004->7, 4002->4 | ||
val_dict = { | ||
1: GISLayerGeometryType.POINT, | ||
2: GISLayerGeometryType.POLYLINE, | ||
3: GISLayerGeometryType.POLYGON, | ||
4: GISLayerGeometryType.POINT, | ||
5: GISLayerGeometryType.POLYLINE, | ||
6: GISLayerGeometryType.POLYGON, | ||
7: "GeometryCollection", | ||
8: GISLayerGeometryType.POLYLINE, | ||
9: GISLayerGeometryType.POLYLINE, | ||
10: GISLayerGeometryType.POLYGON, | ||
11: GISLayerGeometryType.POLYLINE, | ||
12: "MultiSurface", | ||
17: "Triangle", | ||
} | ||
result: GISLayerGeometryType = val_dict.get( | ||
type_index, GISLayerGeometryType.NONE | ||
) | ||
|
||
# write 3d polygons as a separate type | ||
# geometry types of 1,2,3 etc (<1000) have 2 dimensions, rest: 3 | ||
if native_geom_type > 1000 and result == GISLayerGeometryType.POLYGON: | ||
result = GISLayerGeometryType.POLYGON3D | ||
|
||
return result | ||
|
||
@staticmethod | ||
def get_native_layer_geometry_type_from_speckle( | ||
geom_type: str, | ||
) -> Optional[str]: | ||
"""Get native Layer Geometry Type.""" | ||
|
||
val_dict = { | ||
GISLayerGeometryType.NONE: "None", | ||
GISLayerGeometryType.POINT: "MultiPointZ", | ||
GISLayerGeometryType.POLYLINE: "MultiLineStringZ", | ||
GISLayerGeometryType.POLYGON: "MultiPolygon", | ||
GISLayerGeometryType.POLYGON3D: "MultiPolygonZ", | ||
GISLayerGeometryType.MULTIPATCH: "MultiPolygonZ", | ||
# GISLayerGeometryType.POINTCLOUD: , | ||
} | ||
|
||
try: | ||
speckle_geom_type = GISLayerGeometryType(geom_type) | ||
result: Optional[str] = val_dict.get(speckle_geom_type) | ||
except: | ||
# for older commits | ||
if "point" in geom_type.lower(): | ||
result = "MultiPointZ" | ||
elif "line" in geom_type.lower(): | ||
result = "MultiLineStringZ" | ||
elif ( | ||
"polygon" in geom_type.lower() | ||
or "multipatch" in geom_type.lower() | ||
): | ||
result = "MultiPolygonZ" | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.