@@ -60,29 +60,37 @@ def maps(self):
6060
6161 @property
6262 def _cimgisproject (self ):
63- if not "GISProject" in self ._cims :
64- # check what format support we have on ArcGIS Pro
65- supports_json_proj = hasattr (CIMGISProject , "FromJson" )
66- supports_xml_proj = hasattr (CIMGISProject , "FromXml" )
63+ if "GISProject" in self ._cims :
64+ return self ._cims ["GISProject" ]
6765
68- # read project based on supported file type
66+ # check what format support we have on ArcGIS Pro
67+ supports_json_proj = hasattr (CIMGISProject , "FromJson" )
68+ supports_xml_proj = hasattr (CIMGISProject , "FromXml" )
69+
70+ # attempt to read project based on supported file type
71+ gis_project = None
72+
73+ if supports_json_proj :
74+ try :
75+ gis_project = CIMGISProject .FromJson (read_file_in_zip (self ._proj_zip , "GISProject.json" ))
76+ except KeyError :
77+ # JSON file not in project, probably an XML file
78+ pass
79+
80+ if not gis_project and supports_xml_proj :
6981 try :
70- if supports_json_proj :
71- self ._cims ["GISProject" ] = CIMGISProject .FromJson (
72- read_file_in_zip (self ._proj_zip , "GISProject.json" )
73- )
74- elif supports_xml_proj :
75- self ._cims ["GISProject" ] = CIMGISProject .FromXml (read_file_in_zip (self ._proj_zip , "GISProject.xml" ))
76- else :
77- raise NotImplementedError (
78- "This version of ArcGIS Pro is unknown and supports neither XML-based or JSON-based CIM Project loading."
79- )
80- except KeyError as ke :
81- raise_from (
82- NotImplementedError (
83- "This version of ArcGIS Pro does not support the type of Project you are attempting to open."
84- ), ke
85- )
82+ gis_project = CIMGISProject .FromXml (read_file_in_zip (self ._proj_zip , "GISProject.xml" ))
83+ except KeyError :
84+ # XML file not in project, probably a JSON file but maybe we don't have support for that on
85+ # current ArcGIS Pro install
86+ pass
87+
88+ if not gis_project :
89+ raise NotImplementedError (
90+ "This ArcGIS Pro project is either an unknown format or incompatible with the currently installed version of ArcGIS Pro."
91+ )
92+
93+ self ._cims ["GISProject" ] = gis_project
8694
8795 return self ._cims ["GISProject" ]
8896
@@ -91,6 +99,7 @@ def _cimgisproject(self):
9199 #region PUBLIC FUNCTIONS
92100
93101 def close (self ):
102+ """Closes the ArcGIS Project, not required when used inside a 'with' statement."""
94103 if self ._proj_zip :
95104 self ._proj_zip .close ()
96105 self ._proj_zip = None
0 commit comments