Skip to content

Commit ea69509

Browse files
committed
Added support for mosiac datasets
1 parent 49395d6 commit ea69509

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

arcpyext/mapping/_cim/factories.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
import json
1313

14-
from .layers import ProFeatureLayer, ProGroupLayer, ProRasterLayer
14+
from .layers import ProFeatureLayer, ProGroupLayer, ProRasterLayer, \
15+
ProMosaicLayer, ProFeatureMosaicSubLayer, ProImageMosaicSubLayer
1516

1617

1718
def create_layer(proj_zip, layer_string):
@@ -30,6 +31,12 @@ def create_layer(proj_zip, layer_string):
3031
layer_obj = ProGroupLayer(proj_zip, layer_string)
3132
elif layer_type == "CIMRasterLayer":
3233
layer_obj = ProRasterLayer(proj_zip, layer_string)
34+
elif layer_type == "CIMMosaicLayer":
35+
layer_obj = ProMosaicLayer(proj_zip, layer_string)
36+
elif layer_type == "CIMFeatureMosaicSubLayer":
37+
layer_obj = ProFeatureMosaicSubLayer(proj_zip, layer_string)
38+
elif layer_type == "CIMImageMosaicSubLayer":
39+
layer_obj = ProImageMosaicSubLayer(proj_zip, layer_string)
3340
else:
3441
# layer is probably XML, fallback to that
3542
if layer_string.startswith("<CIMFeatureLayer"):
@@ -38,5 +45,11 @@ def create_layer(proj_zip, layer_string):
3845
layer_obj = ProGroupLayer(proj_zip, layer_string)
3946
elif layer_string.startswith("<CIMRasterLayer"):
4047
layer_obj = ProRasterLayer(proj_zip, layer_string)
48+
elif layer_string.startswith("<CIMMosaicLayer"):
49+
layer_obj = ProMosaicLayer(proj_zip, layer_string)
50+
elif layer_string.startswith("<CIMFeatureMosaicSubLayer"):
51+
layer_obj = ProFeatureMosaicSubLayer(proj_zip, layer_string)
52+
elif layer_string.startswith("<CIMImageMosaicSubLayer"):
53+
layer_obj = ProImageMosaicSubLayer(proj_zip, layer_string)
4154

4255
return layer_obj

arcpyext/mapping/_cim/layers.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
from .tables import ProFeatureTable
2020

2121
# .NET Imports
22-
from ArcGIS.Core.CIM import CIMFeatureLayer, CIMGroupLayer, CIMRasterLayer
22+
from ArcGIS.Core.CIM import CIMFeatureLayer, CIMGroupLayer, CIMRasterLayer, \
23+
CIMMosaicLayer, CIMImageMosaicSubLayer,CIMFeatureMosaicSubLayer
2324

2425

2526
class ProLayerBase(with_metaclass(ABCMeta, object)):
@@ -110,3 +111,33 @@ def __init__(self, proj_zip, layer_string):
110111

111112
def _get_child_paths(self):
112113
return [cp[8:] for cp in self._cim_obj.Layers]
114+
115+
116+
class ProMosaicLayer(ProLayerBase):
117+
def __init__(self, proj_zip, layer_string):
118+
try:
119+
super().__init__(proj_zip, CIMMosaicLayer.FromXml(layer_string))
120+
except AttributeError:
121+
# probably JSON, attempt that
122+
super().__init__(proj_zip, CIMMosaicLayer.FromJson(layer_string))
123+
124+
def _get_mosaic_child_paths(self):
125+
return [self._cim_obj.BoundaryLayer[8:],self._cim_obj.FootprintLayer[8:],self._cim_obj.ImageLayer[8:]]
126+
127+
128+
class ProFeatureMosaicSubLayer(ProLayerBase):
129+
def __init__(self, proj_zip, layer_string):
130+
try:
131+
super().__init__(proj_zip, CIMFeatureMosaicSubLayer.FromXml(layer_string))
132+
except AttributeError:
133+
# probably JSON, attempt that
134+
super().__init__(proj_zip, CIMFeatureMosaicSubLayer.FromJson(layer_string))
135+
136+
137+
class ProImageMosaicSubLayer(ProLayerBase):
138+
def __init__(self, proj_zip, layer_string):
139+
try:
140+
super().__init__(proj_zip, CIMImageMosaicSubLayer.FromXml(layer_string))
141+
except AttributeError:
142+
# probably JSON, attempt that
143+
super().__init__(proj_zip, CIMImageMosaicSubLayer.FromJson(layer_string))

arcpyext/mapping/_cim/pro_map.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# pylint: enable=wildcard-import,unused-wildcard-import,wrong-import-order,wrong-import-position,import-error,no-name-in-module
1111

1212
# Third-party imports
13+
import json
1314
import arcpy
1415

1516
# Local imports
@@ -88,12 +89,26 @@ def _create_layers(self, layer_path):
8889
layer_obj = create_layer(self._proj_zip, layer_string)
8990
self._layers.append(layer_obj)
9091

91-
if layer_obj:
92-
for child_path in layer_obj._get_child_paths():
93-
child_layer = self._create_layers(child_path)
94-
95-
# build parent/child relationships
96-
child_layer._parent = layer_obj
97-
layer_obj._children.append(child_layer)
92+
if layer_obj:
93+
94+
# Mosaic imagery datasets have different internal structures and need
95+
# to be handled differently from other layers.
96+
layer_json = json.loads(layer_string)
97+
if layer_json["type"] == "CIMMosaicLayer":
98+
mosaic_children_paths = layer_obj._get_mosaic_child_paths()
99+
100+
for mosaic_child_path in mosaic_children_paths:
101+
mosaic_child_layer = self._create_layers(mosaic_child_path)
102+
103+
# build parent/child relationships
104+
mosaic_child_layer._parent = layer_obj
105+
layer_obj._children.append(mosaic_child_layer)
106+
else:
107+
for child_path in layer_obj._get_child_paths():
108+
child_layer = self._create_layers(child_path)
109+
110+
# build parent/child relationships
111+
child_layer._parent = layer_obj
112+
layer_obj._children.append(child_layer)
98113

99114
return layer_obj

0 commit comments

Comments
 (0)