Exemplo n.º 1
0
    def onRectangle(self, rectangle_geometry):
        polygon_extent = utils.extentPolygon(rectangle_geometry)
        # the current _selected_ layer in ArcMap
        layer = utils.selectedLayer()
        if layer is None:
            return None

        # store the results in memory, no need to bring spindles into this
        output_feature = 'in_memory/primary_selection_points'
        utils.intersectFeatures(layer.name, polygon_extent, output_feature)

        # get the stats for our inviduals
        indiv_stats = utils.selectIndividuals(output_feature, self.display)
        """
        so we'd probably want to identify the specific columns of interest (haplotypes?),
        perhaps using a drop-down menu, and then use the select tool to generate our areas of
        interest, and shoot back out some summary statistics based on those observations.
        """

        results = {
            'indiv_stats': indiv_stats,
            'output_feature': output_feature
        }

        # push results to a shared variable
        config.primary_results = results
        return results
Exemplo n.º 2
0
    def onRectangle(self, rectangle_geometry):
        polygon_extent = utils.extentPolygon(rectangle_geometry)
        # the current _selected_ layer in ArcMap
        layer = utils.selectedLayer()
        if layer is None:
            return None

        # store the results in memory, no need to bring spindles into this
        output_feature = 'in_memory/primary_selection_points'
        utils.intersectFeatures(layer.name, polygon_extent, output_feature)

        # get the stats for our inviduals
        indiv_stats = utils.selectIndividuals(output_feature, self.display)
        """
        so we'd probably want to identify the specific columns of interest (haplotypes?),
        perhaps using a drop-down menu, and then use the select tool to generate our areas of
        interest, and shoot back out some summary statistics based on those observations.
        """

        results = {'indiv_stats': indiv_stats, 'output_feature': output_feature}
       
        # push results to a shared variable
        config.primary_results = results
        return results
Exemplo n.º 3
0
    def onRectangle(self, rectangle_geometry):
        with open(config.log_path, 'a') as log:
            polygon_extent = utils.extentPolygon(rectangle_geometry)
            layer = utils.selectedLayer()
            if layer is None:
                return None
            log.write("Compare encounters operating on layer {}\n".format(layer.name))
            
            output_feature = 'in_memory/compare_selection_points'
            utils.intersectFeatures(layer.name, polygon_extent, output_feature)

            res2 = utils.selectIndividuals(output_feature, False)

            # XXX now, get the results from the summarize encounters tool,
            # and add these selection results back to the table
            fields = arcpy.ListFields(layer.dataSource)

            field_name = settings.population_field
            try:
                if field_name not in fields:
                    log.write("Adding {} to {}\n".format(field_name, layer.dataSource))
                    arcpy.AddField_management(layer.dataSource, field_name, 'TEXT')
               
                if config.primary_results is None:
                    pythonaddins.MessageBox("Please make first selection before running"
                            " this tool", "requires primary selection")
                    return None

                first_pop = config.primary_results['indiv_stats']['unique']
                second_pop = res2['unique']
               
                if len(first_pop) == 0:
                    pythonaddins.MessageBox("No results in primary selection.")
                    return None
                if len(second_pop) == 0:
                    pythonaddins.MessageBox("No results in secondary selection.")
                    return None

                log.write("Setting populations as {}, and {}\n".format(first_pop, second_pop))
                with arcpy.da.UpdateCursor(layer, [settings.id_field, field_name]) as cur:
                    for row in cur:
                        id_field = row[0]
                        if id_field in first_pop and id_field in second_pop:
                            pop = 'both populations'
                        elif id_field in second_pop:
                            pop = 'second population only' 
                        elif id_field in first_pop:
                            pop = 'first population only'
                        else:
                            pop = None
                        row[1] = pop
                        cur.updateRow(row)
                            
            except Exception as e:
                msg = "Error adding {} column.".format(field_name)
                title = "Compare Encounters: Selecting Populations"
                f.write("Selecting populations generated Exception: %s\n" % e)

                pythonaddins.MessageBox(msg, title)
                return None
    
            if self.display:
                log.write("primary results: {}\n".format(config.primary_results))
                if config.primary_results is not None:
                    res = config.primary_results['indiv_stats']

                    common_indiv = res['unique'].intersection(res2['unique']) 
                    # compare the two sets of results
                    msg = ("First Set:  {0} samples, "
                           "{1} unique individuals\n"
                           "Second Set: {2} samples, "
                           "{3} unique individuals\n\n"
                           "Common to both: {4}\n\n"
                           "Results saved to field \"{5}\"".format(
                               len(res['indiv']), len(res['unique']),
                               len(res2['indiv']), len(res2['unique']),
                               len(common_indiv)), field_name)
                    title = "Comparison Results" 
                    pythonaddins.MessageBox(msg, title)
                else:
                    pythonaddins.Messagebox("Please select first set", "Selection Missing")
            else:
                log.write("Not displaying output as display is set to {}".format(self.display))
Exemplo n.º 4
0
    def onRectangle(self, rectangle_geometry):
        with open(config.log_path, 'a') as log:
            polygon_extent = utils.extentPolygon(rectangle_geometry)
            layer = utils.selectedLayer()
            if layer is None:
                return None
            log.write("Compare encounters operating on layer {}\n".format(
                layer.name))

            output_feature = 'in_memory/compare_selection_points'
            utils.intersectFeatures(layer.name, polygon_extent, output_feature)

            res2 = utils.selectIndividuals(output_feature, False)

            # XXX now, get the results from the summarize encounters tool,
            # and add these selection results back to the table
            fields = arcpy.ListFields(layer.dataSource)

            field_name = settings.population_field
            try:
                if field_name not in fields:
                    log.write("Adding {} to {}\n".format(
                        field_name, layer.dataSource))
                    arcpy.AddField_management(layer.dataSource, field_name,
                                              'TEXT')

                if config.primary_results is None:
                    pythonaddins.MessageBox(
                        "Please make first selection before running"
                        " this tool", "requires primary selection")
                    return None

                first_pop = config.primary_results['indiv_stats']['unique']
                second_pop = res2['unique']

                if len(first_pop) == 0:
                    pythonaddins.MessageBox("No results in primary selection.")
                    return None
                if len(second_pop) == 0:
                    pythonaddins.MessageBox(
                        "No results in secondary selection.")
                    return None

                log.write("Setting populations as {}, and {}\n".format(
                    first_pop, second_pop))
                with arcpy.da.UpdateCursor(
                        layer, [settings.id_field, field_name]) as cur:
                    for row in cur:
                        id_field = row[0]
                        if id_field in first_pop and id_field in second_pop:
                            pop = 'both populations'
                        elif id_field in second_pop:
                            pop = 'second population only'
                        elif id_field in first_pop:
                            pop = 'first population only'
                        else:
                            pop = None
                        row[1] = pop
                        cur.updateRow(row)

            except Exception as e:
                msg = "Error adding {} column.".format(field_name)
                title = "Compare Encounters: Selecting Populations"
                f.write("Selecting populations generated Exception: %s\n" % e)

                pythonaddins.MessageBox(msg, title)
                return None

            if self.display:
                log.write("primary results: {}\n".format(
                    config.primary_results))
                if config.primary_results is not None:
                    res = config.primary_results['indiv_stats']

                    common_indiv = res['unique'].intersection(res2['unique'])
                    # compare the two sets of results
                    msg = ("First Set:  {0} samples, "
                           "{1} unique individuals\n"
                           "Second Set: {2} samples, "
                           "{3} unique individuals\n\n"
                           "Common to both: {4}\n\n"
                           "Results saved to field \"{5}\"".format(
                               len(res['indiv']), len(res['unique']),
                               len(res2['indiv']), len(res2['unique']),
                               len(common_indiv)), field_name)
                    title = "Comparison Results"
                    pythonaddins.MessageBox(msg, title)
                else:
                    pythonaddins.Messagebox("Please select first set",
                                            "Selection Missing")
            else:
                log.write(
                    "Not displaying output as display is set to {}".format(
                        self.display))