Exemple #1
0
def qualify_adjacency(data, **kwargs):
    qualify_adjacency.relation_set = 'adj'
    qualify_adjacency.arity = 2

    relata_list = list()

    relata_list.append(ff.filter(data, type_list=['boma', 'olopololi']))
    relata_list.append(ff.filter(data, type_list=['mountain', 'boundary']))

    qcn = []

    for relata in relata_list:
        max_min_dist = compute_max_min_dist([r['geometry'] for r in relata])
        for i in range(len(relata) - 1):
            for sec in relata[i + 1:]:
                o1 = relata[i]['attributes']['ssm_id']
                o2 = sec['attributes']['ssm_id']
                g1 = relata[i]['geometry']
                g2 = sec['geometry']
                relation = compute_adjacency(g1, g2, max_min_dist)
                qcn.append({'obj_1': o1, 'obj_2': o2, 'relation': relation})

        return 'ADJACENCY', 2, {}, qcn
    else:
        return 'ADJACENCY', 2, {}, []
Exemple #2
0
def get_qualifier_functions(data):
    """Loops through a list of qualifiers, initializing them
    and returning a list of qualifier functions that can be applied on
    any 'well formed' data.
    """
    #  append qualifier for each aspect and return list
    qualifier_function_list = []

    # 1. rcc8
    qualifier_function_list.append((qualify_rcc8, None))

    # 2. rcc11
    qualifier_function_list.append((qualify_rcc11, None))

    # 3. RegionStarVars
    fargs = {'num_sectors': 4}
    regstarvars_ref_objects = filter(data, type_list=['mountain'])
    regstarvars_ref_pairs = grp(perm(regstarvars_ref_objects, 2),
                                key=lambda x: x[0])
    fargs['reference_pair_groups'] = regstarvars_ref_pairs
    qualifier_function_list.append((qualify_relative_direction, fargs))

    # 4. relative distance
    qualifier_function_list.append((qualify_relative_distance, None))

    # 5. left-right relations
    qualifier_function_list.append((qualify_left_right, None))

    # 6. adjacency
    qualifier_function_list.append((qualify_adjacency, None))

    return qualifier_function_list
Exemple #3
0
def qualify_relative_distance(data, **kwargs):
    # every qualifier function must specify these two parameters\n",
    qualify_relative_distance.relation_set = 'REL_DIST'
    qualify_relative_distance.arity = 2,

    relata_list = []

    relata_list.append(
        ff.filter(data,
                  type_list=[
                      'boma', 'olopololi', 'school', 'borehole', 'church',
                      'river', 'marsh'
                  ]))
    relata_list.append(
        ff.filter(data, type_list=['mountain', 'marsh', 'river', 'road']))

    qcn = []
    near_ends, far_ends = [], []

    for relata in relata_list:
        near_end, far_end = compute_relative_dist_ranges(
            [r['geometry'] for r in relata])
        near_ends.append(near_end), far_ends.append(far_end)

    for k in range(len(relata_list)):
        relata = relata_list[k]
        near_end, far_end = near_ends[k], far_ends[k]

        for i in range(len(relata) - 1):
            for sec in relata[i + 1:]:
                if relata[i]['attributes']['feat_type'] in ['road', 'river', 'marsh'] \
                        and sec['attributes']['feat_type'] in ['road', 'river', 'marsh'] \
                        and i == 0:
                    continue

                o1 = relata[i]['attributes']['ssm_id']
                o2 = sec['attributes']['ssm_id']
                g1 = relata[i]['geometry']
                g2 = sec['geometry']
                relation = distance_relation(g1, g2, near_end, far_end)
                qcn.append({'obj_1': o1, 'obj_2': o2, 'relation': relation})

    return 'REL_DIST', 2, {}, qcn
Exemple #4
0
def qualify_rcc8(data, **kwargs):
    f_data = ff.filter(data, filter_geoms=ff.FILTER_POLYGONS)

    qcn = []
    for i in range(len(f_data[:-1])):
        for sec in f_data[i + 1:]:
            o1 = f_data[i]['attributes']['ssm_id']
            o2 = sec['attributes']['ssm_id']
            relation = polygonal_topology(f_data[i]['geometry'],
                                          sec['geometry'])
            qcn.append({'obj_1': o1, 'obj_2': o2, 'relation': relation})

    return 'RCC8', 2, {}, qcn
Exemple #5
0
def qualify_left_right(data, **kwargs):
    # every qualifier function must specify these two parameters\n",
    relation_set = 'LEFT_RIGHT'
    arity = 2

    relata = ff.filter(data)
    referents = ff.filter(relata, type_list=['river', 'road'])

    for ref in referents:
        relata.remove(ref)

    qcn = []

    for referent in referents:
        for relatum in relata:
            o1 = referent['attributes']['ssm_id']
            o2 = relatum['attributes']['ssm_id']
            g1 = referent['geometry']
            g2 = relatum['geometry']
            relation = left_or_right(g1, g2)
            qcn.append({'obj_1': o1, 'obj_2': o2, 'relation': relation})

    return relation_set, arity, {}, qcn
Exemple #6
0
    def compute_tiles(self,d):
        tiles ={}
        relatum = d[0]['geometry']

        secondary_object_list=(ff.filter(self.data, type_list=self.type_list))

        near_end, far_end, vfar_end = compute_relative_dis_ranges_1_to_M(relatum, secondary_object_list)
        #print(near_end, far_end,vfar_end)

        base_bounds = relatum.bounds  # returns the tuple (minx, miny, maxx, maxy)
        diam = sqrt((base_bounds[2] - base_bounds[0]) ** 2 + (base_bounds[3] - base_bounds[1]) ** 2)

        relatum_nearEnd = relatum.buffer( near_end)
        relatum_farEnd = relatum.buffer(  far_end)
        relatum_vfarEnd = relatum.buffer( far_end)
        #print(relatum_nearEnd, relatum_farEnd,relatum_vfarEnd)


        tiles['near'] = relatum_nearEnd
        tiles['far'] = relatum_farEnd
        tiles['vfar'] = relatum_vfarEnd
        return tiles
def qualify_relative_direction(data, **kwargs):
    relation_set = 'REGION_STAR_VARS'
    arity = 2
    # get random pair of polygons
    f_data = ff.filter(data, filter_geoms=ff.FILTER_POINTS_POLYGONS)

    or_obj1 = rnd.choice(f_data)
    or_obj2 = rnd.choice(f_data)

    while or_obj1 == or_obj2:
        or_obj2 = rnd.choice(f_data)

    reference_pair_groups = [(or_obj1, [(or_obj1, or_obj2)]),
                             (or_obj2, [(or_obj2, or_obj1)])]

    num_sectors = kwargs.get('num_sectors', 4)
    reference_pair_groups = kwargs.get('reference_pair_groups',
                                       reference_pair_groups)

    modifiers = {'reference_pair_groups': [], 'number_of_sectors': num_sectors}

    # f_data = ff.filter(data, filter_geoms=ff.FILTER_POINTS_POLYGONS)

    qcn = []
    for ref, reference_pairs in reference_pair_groups:
        reference_obj_1 = {
            'ssm_id': ref['attributes']['ssm_id'],
            'feat_type': ref['attributes']['feat_type'],
            'geometry': ref['geometry']
        }
        modifiers['reference_pair_groups'].append(reference_obj_1['ssm_id'])
        d_sectors_list = []
        # generate all orientations for ref
        for reference_pair in reference_pairs:
            # determine the centroids of their convex hulls
            reference_obj_2 = {
                'ssm_id': reference_pair[1]['attributes']['ssm_id'],
                'feat_type': reference_pair[1]['attributes']['feat_type'],
                'geometry': reference_pair[1]['geometry']
            }
            cntr1 = reference_obj_1['geometry'].convex_hull.centroid
            cntr2 = reference_obj_2['geometry'].convex_hull.centroid

            # determine the global orientation of the ray from centroid 1 to centroid 2
            v = np.array(cntr2.coords[:][0]) - np.array(cntr1.coords[:][0])
            # using degrees instead of radians
            dir_deg = np.rad2deg(vector_angle(v))
            d_sectors_list.append(
                calculate_sectors(dir_deg, 360.0, num_sectors))

        o1 = ref['attributes']['ssm_id']
        g1 = ref['geometry']
        for sec in f_data:
            o2 = sec['attributes']['ssm_id']
            g2 = sec['geometry']
            relation = []
            for d_sectors in d_sectors_list:
                relation.append([
                    sector_range(
                        directional_relation(g1, g2, dir_deg, 360.0,
                                             d_sectors), num_sectors),
                    sector_range(
                        directional_relation(g2, g1, dir_deg, 360.0,
                                             d_sectors), num_sectors)
                ])
            qcn.append({'obj_1': o1, 'obj_2': o2, 'relation': relation})

    return relation_set, arity, modifiers, qcn