def get_ugid(polygons=None, geom=None): """ returns geometry id of given polygon in a given shapefile. :param polygons: string or list of the region polygons :param geom: available shapefile. Possible entries: '50m_country', 'NUTS2' :returns list: ugids used by ocgis """ from ocgis import env, ShpCabinetIterator # from ocgis import env if polygons is None: result = None else: if type(polygons) != list: polygons = list([polygons]) env.DIR_SHPCABINET = DIR_SHP sc_iter = ShpCabinetIterator(geom) result = [] if geom == 'countries': for row in sc_iter: for polygon in polygons: if row['properties']['ADM0_A3'] == polygon: result.append(row['properties']['UGID']) elif geom == 'extremoscope': for row in sc_iter: for polygon in polygons: if row['properties']['HASC_1'] == polygon: result.append(row['properties']['UGID']) elif geom == 'continents': for row in sc_iter: for polygon in polygons: if row['properties']['CONTINENT'] == polygon: result.append(row['properties']['UGID']) else: from ocgis import ShpCabinet sc = ShpCabinet(DIR_SHP) logger.debug( 'geom: %s not found in shape cabinet. Available geoms are: %s ', geom, sc) return result
def get_shp_column_values(geom, columnname): """ returns a list of all entries the shapefile column name :param geom: name of the shapefile :param columnname: Column name to be intepreted returns list: column names """ from ocgis import env, ShpCabinetIterator # import ocgis env.DIR_SHPCABINET = config.shapefiles_path() sci = ShpCabinetIterator(geom) vals = [] for row in sci: vals.append(row['properties'][columnname]) return vals