Helper function to get all possible geometry

    :param layer_purpose_key: A layer purpose key.
    :type layer_purpose_key: str

    :returns: List of all allowed geometries.
    :rtype: list
10058
def get_allowed_geometries(layer_purpose_key):
    
    preferred_order = [
        'point',
        'line',
        'polygon',
        'raster'
    ]
    allowed_geometries = set()
    all_layer_type = []
    if layer_purpose_key == layer_purpose_hazard['key']:
        all_layer_type = hazard_all
    elif layer_purpose_key == layer_purpose_exposure['key']:
        all_layer_type = exposure_all

    for layer in all_layer_type:
        for allowed_geometry in layer['allowed_geometries']:
            allowed_geometries.add(allowed_geometry)

    allowed_geometries = list(allowed_geometries)
    allowed_geometries_definition = []
    for allowed_geometry in allowed_geometries:
        allowed_geometries_definition.append(definition(allowed_geometry))

    # Adapted from http://stackoverflow.com/a/15650556/1198772
    order_dict = {color: index for index, color in enumerate(preferred_order)}
    allowed_geometries_definition.sort(key=lambda x: order_dict[x["key"]])

    return allowed_geometries_definition
573928
def geometry_type(layer):
    
    if is_raster_layer(layer):
        return layer_geometry_raster['key']
    elif is_point_layer(layer):
        return layer_geometry_point['key']
    elif is_line_layer(layer):
        return layer_geometry_line['key']
    elif is_polygon_layer(layer):
        return layer_geometry_polygon['key']
    else:
        return None
794759
private List<Coordinate> getCoordinates(List<Geometry> geometries) {
		List<Coordinate> coordinates = new ArrayList<Coordinate>();
		for (Geometry geometry : geometries) {
			Coordinate[] geometryCoordinates = geometry.getCoordinates();
			for (int i = 0; i < geometryCoordinates.length; i++) {
				coordinates.add(geometryCoordinates[i]);
			}
		}
		return coordinates;
	}
1046582
def ontologyShapeTree(self):
        
        treedict = {}
        if self.all_shapes:
            treedict[0] = self.toplayer_shapes
            for element in self.all_shapes:
                if element.children():
                    treedict[element] = element.children()
            return treedict
        return treedict
1216222
def get_entry_points(key):
    
    result = {}
    for entry_point in pkg_resources.iter_entry_points(key):
        result[entry_point.name] = entry_point.load()
    return result
665601
def _get_bounds_local(layers):
    
    if not layers:
        return {'west': None, 'south': None, 'east': None, 'north': None}

    bounds = layers[0].bounds

    for layer in layers[1:]:
        bounds = np.concatenate(
            (
                np.minimum(
                    bounds[:2],
                    layer.bounds[:2]
                ),
                np.maximum(
                    bounds[2:],
                    layer.bounds[2:]
                )
            )
        )

    return dict(zip(['west', 'south', 'east', 'north'], bounds))
1133152
def get_layer_names(self):
    
    layer_names = [x.name for x in self.model.layers]
    return layer_names
1343025
def _get_items(self, request):
        
        if request.gpd_iterator is None:
            self.gpd_iterator = GeopediaFeatureIterator(request.layer, bbox=request.bbox, base_url=self.base_url,
                                                        gpd_session=request.gpd_session)
        else:
            self.gpd_iterator = request.gpd_iterator

        field_iter = self.gpd_iterator.get_field_iterator(request.image_field_name)
        items = []

        for field_items in field_iter:  # an image field can have multiple images

            for item in field_items:
                if not item['mimeType'].startswith('image/'):
                    continue

                mime_type = MimeType.from_string(item['mimeType'][6:])

                if mime_type is request.image_format:
                    items.append(item)

        return items
655676
def _key(self):
        
        return Key(self._schema.key_type, self._identity, self._name,
                   [str(item.value) for item in self._dimension_fields.values()])
60253
def selected_value(self, layer_purpose_key):
        
        if layer_purpose_key == layer_purpose_exposure['key']:
            role = RoleExposureConstraint
        elif layer_purpose_key == layer_purpose_hazard['key']:
            role = RoleHazardConstraint
        else:
            return None

        selected = self.tblFunctions2.selectedItems()
        if len(selected) != 1:
            return None
        try:
            return selected[0].data(role)
        except (AttributeError, NameError):
            return None
1048783
function(key, options, callback){
    var self = this;
    //var layer = 0;
    var error = false,
      totalLayers,
      queryOpts = {},
      allLayers = [];

    // closure to check each layer and send back when done
    var collect = function(err, data){
      if (err) error = err;
      allLayers.push(data);
      if (allLayers.length == totalLayers){
        callback(error, allLayers);
      }
    };

    this._query('select info from "'+this.infoTable+'" where id=\''+(key+':'+(options.layer || 0 )+":info")+'\'', function(err, rows){
      if ( err || !rows || !rows.length ){
        callback('Not Found', []);
      } else if (rows[0].info.status == 'processing' && !options.bypassProcessing ) {
        callback( null, [{ status: 'processing' }]);
      } else {
          var info = JSON.parse(rows[0].info);
          var select = 'select feature from "' + key+':'+(options.layer || 0)+'"';

          // parse the where clause
          if ( options.where && options.where != '1=1'){
            var where = sql.parse( 'select * from foo where '+ options.where).where;
            select = self.parseWhere( select, where);
          }

          // parse the geometry param from GeoServices REST
          if ( options.geometry ){

            if ( typeof(options.geometry) == 'string' ){
              try {
                options.geometry = JSON.parse( options.geometry );
              } catch(e){
                console.log('Error parsing options.geometry', options.geometry);
                try {
                  if ( options.geometry.split(',').length == 4 ){
                    var extent = options.geometry.split(',');
                    options.geometry = { spatialReference: {wkid: 4326} };
                    options.geometry.xmin = extent[0];
                    options.geometry.ymin = extent[1];
                    options.geometry.xmax = extent[2];
                    options.geometry.ymax = extent[3];
                  }
                } catch(ex){
                  console.log('Error building bbox from', options.geometry);
                }
              }
            }

            if (options.geometry.xmin && options.geometry.ymin ){
              var box = options.geometry;
              if (box.spatialReference.wkid != 4326){
                var mins = merc.inverse( [box.xmin, box.ymin] ),
                  maxs = merc.inverse( [box.xmax, box.ymax] );
                box.xmin = mins[0];
                box.ymin = mins[1];
                box.xmax = maxs[0];
                box.ymax = maxs[1];
              }

              select += (options.where ) ? ' AND ' : ' WHERE ';
              select += 'ST_Intersects(ST_GeomFromGeoJSON(feature->>\'geometry\'), ST_MakeEnvelope('+box.xmin+','+box.ymin+','+box.xmax+','+box.ymax+'))';
            }
          }

          if ( options.limit ) {
            select += ' LIMIT ' + options.limit;
          }

          //console.log(select);
          self._query( select, function (err, rows) {
            if ( rows && rows.length ) {
              callback( null, [{
                type: 'FeatureCollection',
                features: _.map(_.pluck(rows, 'feature'), function(jsonStr) { return JSON.parse(jsonStr); }),
                name: info.name,
                sha: info.sha,
                info: info.info,
                updated_at: info.updated_at
              }]);
            } else {
              callback( 'Not Found', [{
                type: 'FeatureCollection',
                features: []
              }]);
            }
          });
        }
    });
  }
1067742
def field_keyword_for_the_layer(self):
        
        layer_purpose_key = self.step_kw_purpose.selected_purpose()['key']
        if layer_purpose_key == layer_purpose_aggregation['key']:
            return get_compulsory_fields(layer_purpose_key)['key']
        elif layer_purpose_key in [
                layer_purpose_exposure['key'], layer_purpose_hazard['key']]:
            layer_subcategory_key = \
                self.step_kw_subcategory.selected_subcategory()['key']
            return get_compulsory_fields(
                layer_purpose_key, layer_subcategory_key)['key']
        else:
            raise InvalidParameterError
500029
def get_all_regions_with_tiles(self):
        
        for key in self.get_all_keys():
            (layer, rx, ry) = struct.unpack('>BHH', key)
            if layer == 1:
                yield (rx, ry)
701290
def subcategories_for_layer(self):
        
        purpose = self.parent.step_kw_purpose.selected_purpose()
        layer_geometry_key = self.parent.get_layer_geometry_key()
        if purpose == layer_purpose_hazard:
            return hazards_for_layer(layer_geometry_key)
        elif purpose == layer_purpose_exposure:
            return exposures_for_layer(layer_geometry_key)
841426
def _get_self_bounds(self):
        
        if not self.embed:
            raise ValueError('Cannot compute bounds of non-embedded GeoJSON.')

        data = json.loads(self.data)
        if 'features' not in data.keys():
            # Catch case when GeoJSON is just a single Feature or a geometry.
            if not (isinstance(data, dict) and 'geometry' in data.keys()):
                # Catch case when GeoJSON is just a geometry.
                data = {'type': 'Feature', 'geometry': data}
            data = {'type': 'FeatureCollection', 'features': [data]}

        bounds = [[None, None], [None, None]]
        for feature in data['features']:
            for point in iter_points(feature.get('geometry', {}).get('coordinates', {})):  # noqa
                bounds = [
                    [
                        none_min(bounds[0][0], point[1]),
                        none_min(bounds[0][1], point[0]),
                        ],
                    [
                        none_max(bounds[1][0], point[1]),
                        none_max(bounds[1][1], point[0]),
                        ],
                    ]
        return bounds
341208
def selected_impact_function_constraints(self):
        

        hazard = self.step_fc_functions1.selected_value(
            layer_purpose_hazard['key'])
        exposure = self.step_fc_functions1.selected_value(
            layer_purpose_exposure['key'])

        hazard_geometry = self.step_fc_functions2.selected_value(
            layer_purpose_hazard['key'])
        exposure_geometry = self.step_fc_functions2.selected_value(
            layer_purpose_exposure['key'])
        return hazard, exposure, hazard_geometry, exposure_geometry
320551
def get_as_map(self, key):
        
        value = self.get(key)
        return AnyValueMap.from_value(value)