How to use the arcgis.features.FeatureLayer function in arcgis

To help you get started, we’ve selected a few arcgis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Esri / crowdsource-reporter-scripts / CityworksConnection / connect_to_cityworks.py View on Github external
else:
                print("Spatial reference not defined")
            raise Exception("Spatial reference not defined")

        # get problem types
        prob_types = get_problem_types()

        if prob_types == "error":
            if log_to_file:
                log.write("Problem types not defined\n")
            else:
                print("Problem types not defined")
            raise Exception("Problem types not defined")

        for layer in layers:
            lyr = FeatureLayer(layer, gis=gis)
            oid_fld = lyr.properties.objectIdField
            lyrname = lyr.properties["name"]

            # Get related table URL
            reltable = ""
            for relate in lyr.properties.relationships:
                url_pieces = layer.split("/")
                url_pieces[-1] = str(relate["relatedTableId"])
                table_url = "/".join(url_pieces)

                if table_url in tables:
                    reltable = table_url
                    break

            # query reports
            sql = "{}='{}'".format(fc_flag, flag_values[0])
github ngageoint / state-of-the-data / state-of-the-data-for-webgis / sotd_indicators / indicators.py View on Github external
def temporal_accuracy(c_features, curr_url, output_workspace, output_features, years, curr_gis):

    import zipfile
    import arcpy

    fl = FeatureLayer(url=curr_url, gis=curr_gis)

    item = curr_gis.content.get(fl.properties.serviceItemId)

    export_item = item.export(export_format='File Geodatabase', title='CURRENCY')

    result = export_item.download(save_path=output_workspace)

    folder = os.path.dirname(result)

    with zipfile.ZipFile(result, "r") as zip_ref:
        zip_ref.extractall(folder)

    gdbs = []
    for file in zip_ref.namelist():
        gdbs.append(os.path.split(file)[0])
github ngageoint / state-of-the-data / state-of-the-data-for-webgis / sotd_processor.py View on Github external
def process_by_metadata(gis):
    return_all_records = False

    look_back_days = config.look_back_days

    dates = csl.get_dates_in_range(look_back_days)
    where_clause = csl.form_query_string(dates)

    grid_fl = FeatureLayer(url=config.grid_url)
    grid_sdf = grid_fl.query(return_all_records=return_all_records, where=where_clause).df

    geometry = grid_sdf.geometry
    sr = {'wkid':4326}
    sp_rel = "esriSpatialRelIntersects"

    for idx, row in enumerate(grid_sdf.iterrows()):
        geom = row[1].SHAPE

        new_geom = Geometry({
            "rings" : [[[geom.extent.upperRight.X-.1, geom.extent.lowerLeft.Y+.1], [geom.extent.lowerLeft.X+.1, geom.extent.lowerLeft.Y+.1], [geom.extent.lowerLeft.X+.1, geom.extent.upperRight.Y-.1], [geom.extent.upperRight.X-.1, geom.extent.upperRight.Y-.1], [geom.extent.upperRight.X-.1, geom.extent.lowerLeft.Y+.1]]],
            "spatialReference" : {"wkid" : 4326}
        })

        grid_filter = filters._filter(new_geom, sr, sp_rel)
        sp_filter = filters._filter(geom, sr, sp_rel)
github Esri / crowdsource-reporter-scripts / servicefunctions.py View on Github external
username = cfg['email settings']['smtp username']
        password = cfg['email settings']['smtp password']
        tls = cfg['email settings']['use tls']
        from_address = cfg['email settings']['from address']
        if not from_address:
            from_address = ''
        reply_to = cfg['email settings']['reply to']
        if not reply_to:
            reply_to = ''
        global substitutions
        substitutions = cfg['email settings']['substitutions']

        # Process each service
        for service in cfg['services']:
            try:
                lyr = FeatureLayer(service['url'], gis=gis)

                # GENERATE IDENTIFIERS
                idseq = service['id sequence']
                idfld = service['id field']
                if id_settings and idseq and idfld:
                    if idseq in id_settings:
                        new_sequence_value = add_identifiers(lyr, idseq, idfld)
                        id_settings[idseq]['next value'] = new_sequence_value
                    else:
                        _add_message('Sequence {} not found in sequence settings'.format(idseq), 'WARNING')

                # ENRICH REPORTS
                if service['enrichment']:
                    # reversed, sorted list of enrichment settings
                    enrich_settings = sorted(service['enrichment'], key=lambda k: k['priority'], reverse=True)
                    for reflayer in enrich_settings:
github Esri / crowdsource-reporter-scripts / EnrichReports / enrich_reports.py View on Github external
def main():
    # Create log file
    with open(path.join(sys.path[0], 'attr_log.log'), 'a') as log:
        log.write('\n{}\n'.format(dt.now()))

        # connect to org/portal
        gis = GIS(orgURL, username, password)

        for service in services:
            try:
                # Connect to target layer
                fl = FeatureLayer(service['url'], gis)
                fl_fields = [field['name'] for field in fl.properties.fields]

                # get wkid of target layer for spatial queries
                wkid = fl.properties.extent.spatialReference.wkid

                for reflayer in reversed(service['enrichment layers']):  # reversed so the top llayer is processed last
                    # Connect to source layer
                    polyfeats = FeatureLayer(reflayer['url'], gis)

                    # test that source and target fields exist in source and target layers
                    poly_fields = [field['name'] for field in polyfeats.properties.fields]
                    if not reflayer['source field'] in poly_fields:
                        raise Exception(
                            'Source field {} not found in layer {}'.format(reflayer['source field'], reflayer['url']))

                    if not reflayer['target field'] in fl_fields:
github ngageoint / state-of-the-data / src / sotd_indicators / utils.py View on Github external
def get_grid_sdf():

    dates = get_dates_in_range(look_back_days)
    where_clause = form_query_string(dates)

    grid_fl = FeatureLayer(url=grid_url)
    return grid_fl.query(where=where_clause).df
github Esri / crowdsource-reporter-scripts / EnrichReports / enrich_reports.py View on Github external
# connect to org/portal
        gis = GIS(orgURL, username, password)

        for service in services:
            try:
                # Connect to target layer
                fl = FeatureLayer(service['url'], gis)
                fl_fields = [field['name'] for field in fl.properties.fields]

                # get wkid of target layer for spatial queries
                wkid = fl.properties.extent.spatialReference.wkid

                for reflayer in reversed(service['enrichment layers']):  # reversed so the top llayer is processed last
                    # Connect to source layer
                    polyfeats = FeatureLayer(reflayer['url'], gis)

                    # test that source and target fields exist in source and target layers
                    poly_fields = [field['name'] for field in polyfeats.properties.fields]
                    if not reflayer['source field'] in poly_fields:
                        raise Exception(
                            'Source field {} not found in layer {}'.format(reflayer['source field'], reflayer['url']))

                    if not reflayer['target field'] in fl_fields:
                        raise Exception(
                            'Target field {} not found in layer {}'.format(reflayer['target field'], service['url']))

                    # Query for target features
                    try:
                        rows = fl.query(reflayer['query'])
                    except:
                        raise Exception('Failed to execute query {}. Please verify the syntax. Layer: {}'.format(reflayer['query'], service['url']))