def apply_field_map_if_exists(self, field_map_path, out_dataset_name): """ Check if there's a field map to go from the country specific data to global data :param field_map_path: path to the fieldmap, should be formatted: D:\path\to\field\map.ini\{ISO} :param out_dataset_name: name of the output; used to create a feature layer with a unique name :return: the source dataset to use when appending to the global layer """ # Check if there's a fieldmap to go from country to global layer if field_map_path: # Build the actual .ini path, replacing {ISO} with the country value ini_path = field_map_path.replace('{ISO}', self.add_country_value) field_map_dict = field_map.get_ini_dict(ini_path) out_dir = os.path.join(self.scratch_workspace, 'country_to_global_fms') # Apply field map, set country_src to this new FC country_src = field_map.ini_fieldmap_to_fc( self.esri_service_output, out_dataset_name, field_map_dict, out_dir) # If no field map, just use the output from the country layer that we just processed else: country_src = self.esri_service_output return country_src
def apply_field_map_if_exists(self, field_map_path, out_dataset_name): """ Check if there's a field map to go from the country specific data to global data :param field_map_path: path to the fieldmap, should be formatted: D:\path\to\field\map.ini\{ISO} :param out_dataset_name: name of the output; used to create a feature layer with a unique name :return: the source dataset to use when appending to the global layer """ # Check if there's a fieldmap to go from country to global layer if field_map_path: # Build the actual .ini path, replacing {ISO} with the country value ini_path = field_map_path.replace('{ISO}', self.add_country_value) field_map_dict = field_map.get_ini_dict(ini_path) out_dir = os.path.join(self.scratch_workspace, 'country_to_global_fms') # Apply field map, set country_src to this new FC country_src = field_map.ini_fieldmap_to_fc(self.esri_service_output, out_dataset_name, field_map_dict, out_dir) # If no field map, just use the output from the country layer that we just processed else: country_src = self.esri_service_output return country_src
def source(self, s): """ Validates source; can apply a fieldmap to an FC, also will copy locally if an external dataset :param s: :return: """ valid = True if type(s) is list: for path in s: if not arcpy.Exists(path): valid = False break else: if not arcpy.Exists(s): valid = False if not valid: logging.warning("Cannot find source {0!s}".format(s)) # If there's a field map, use it as an input to the FeatureClassToFeatureClass tool and copy the data locally if self.field_map: s = field_map.ini_fieldmap_to_fc(s, self.name, self.field_map, self.scratch_workspace) elif type(s) is list: # If we're dealing with a list (currently only GLAD and Terra-I, we can skip this validation) pass elif len(s) == 0: # a blank cell in the google config sheet is not None, for some reason pass elif r"projects/wri-datalab" in s: pass # If there's not a field map, need to figure out what type of data source it is, and if it's local or not else: # This could be a folder, a gdb/mdb, a featuredataset, or an SDE database source_dirname = os.path.dirname(s) # we want to simply determine if this is local/not local so we can copy the datasource # first determine if our source dataset is within a featuredataset desc = arcpy.Describe(source_dirname) if hasattr(desc, "datasetType") and desc.datasetType == 'FeatureDataset': source_dirname = os.path.dirname(source_dirname) # Test if it's an SDE database try: server_address = arcpy.Describe( source_dirname).connectionProperties.server # If source SDE is localhost, don't need to worry about copying anywhere if server_address == 'localhost': pass else: s = util.copy_to_scratch_workspace(self.source, self.scratch_workspace) # Otherwise, just look at the drive letter to determine if it's local or not except AttributeError: # Split the drive from the path returns (Letter and :), then take only the letter and lower it drive = os.path.splitdrive(s)[0][0].lower() if drive in util.list_network_drives(): s = util.copy_to_scratch_workspace(self.source, self.scratch_workspace) elif drive not in ['c', 'd']: logging.info( "Are you sure the source dataset is local to this machine? \ It's not on drives C or D . . .") self._source = s
def source(self, s): """ Validates source; can apply a fieldmap to an FC, also will copy locally if an external dataset :param s: :return: """ valid = True if type(s) is list: for path in s: if not arcpy.Exists(path): valid = False break else: if not arcpy.Exists(s): valid = False if not valid: logging.error("Cannot find source {0!s} Exiting".format(s)) sys.exit(1) # If there's a field map, use it as an input to the FeatureClassToFeatureClass tool and copy the data locally if self.field_map: s = field_map.ini_fieldmap_to_fc(s, self.name, self.field_map, self.scratch_workspace) elif type(s) is list: # If we're dealing with a list (currently only GLAD and Terra-I, we can skip this validation) pass # If there's not a field map, need to figure out what type of data source it is, and if it's local or not else: # This could be a folder, a gdb/mdb, a featuredataset, or an SDE database source_dirname = os.path.dirname(s) # we want to simply determine if this is local/not local so we can copy the datasource # first determine if our source dataset is within a featuredataset desc = arcpy.Describe(source_dirname) if hasattr(desc, "datasetType") and desc.datasetType == 'FeatureDataset': source_dirname = os.path.dirname(source_dirname) # Test if it's an SDE database try: server_address = arcpy.Describe(source_dirname).connectionProperties.server # If source SDE is localhost, don't need to worry about copying anywhere if server_address == 'localhost': pass else: s = util.copy_to_scratch_workspace(self.source, self.scratch_workspace) # Otherwise, just look at the drive letter to determine if it's local or not except AttributeError: # Split the drive from the path returns (Letter and :), then take only the letter and lower it drive = os.path.splitdrive(s)[0][0].lower() if drive in util.list_network_drives(): s = util.copy_to_scratch_workspace(self.source, self.scratch_workspace) elif drive not in ['c', 'd']: logging.info("Are you sure the source dataset is local to this machine? \ It's not on drives C or D . . .") self._source = s