How to use the arcgis.features.FeatureLayerCollection.fromitem 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 / ago-clone-items / clone_items.py View on Github external
def _add_features(self, layers, relationships, layer_field_mapping, wkid):
        """Add the features from the definition to the layers returned from the cloned item.
        Keyword arguments:
        layers - Dictionary containing the id of the layer and its corresponding arcgis.lyr.FeatureLayer
        relationships - Dictionary containing the id of the layer and its relationship definitions
        layer_field_mapping - field mapping if the case or name of field changed from the original service
        wkid -  The wkid for the spatial reference to create the features in"""

        # Get the features if they haven't already been queried
        features = self.features
        original_layers = []
        if not features and self.portal_item:
            svc = FeatureLayerCollection.fromitem(self.portal_item)    
            features = {}
            original_layers = svc.layers + svc.tables
            for layer in original_layers:
                features[str(layer.properties['id'])] = self._get_features(layer, wkid)
        else:
            return   

        # Update the feature attributes if field names have changed
        for layer_id in features:
            if int(layer_id) in layer_field_mapping:
                field_mapping = layer_field_mapping[int(layer_id)]
                for feature in features[layer_id]:
                    _update_feature_attributes(feature, field_mapping)

        # Add in chunks of 2000 features
        chunk_size = 2000
github Esri / ago-clone-items / clone_items.py View on Github external
# Check if the url is incorrect after sharing and set back to correct url.
                if 'url' in new_item and new_item['url'] is not None:
                    url = new_item['url']
                    new_item = target.content.get(new_item['id'])
                    if new_item['url'] != url:
                        new_item.update({'url' : url})
             
            if isinstance(item_definition, _FeatureServiceDefinition):
                # Need to handle Feature Services specially as their layer ids and fields names can
                # change during creation. Especially when going from Online to Portal
                layer_field_mapping = {}
                layer_id_mapping = {}
                layer_fields = {}

                if not new_item_created:
                    new_feature_service = FeatureLayerCollection.fromitem(new_item)    
                    new_layers = new_feature_service.layers + new_feature_service.tables
                    for new_layer in new_layers:
                        layer_fields[new_layer.properties.id] = new_layer.properties.fields
                                     
                    original_layers_definition = item_definition.layers_definition
                    original_layers = original_layers_definition['layers'] + original_layers_definition['tables']
                    if len(new_layers) == len(original_layers):
                        i = 0
                        for layer in original_layers:
                            layer_id_mapping[layer['id']] = new_layers[i].properties['id']
                            i += 1

                        # Get any layer field mapping saved with the feature service
                        data = new_item.get_data()
                        layers = []
                        if 'layers' in data and data['layers'] is not None:
github Esri / ago-clone-items / clone_items.py View on Github external
try:
                    item_id = service.properties['serviceItemId']
                    feature_service = source.content.get(item_id)
                except RuntimeError:
                    _add_message("Failed to get feature service item {0}".format(item_id), 'Error')
                    raise
                _get_item_definitions(feature_service, item_definitions)

        for feature_collection in feature_collections:
            if 'itemId' in feature_collection and feature_collection['itemId'] is not None:
                feature_collection = source.content.get(feature_collection['itemId'])
                _get_item_definitions(feature_collection, item_definitions)

    # If the item is a feature service determine if it is a view and if it is find all it's sources
    elif item['type'] == 'Feature Service':
        svc = FeatureLayerCollection.fromitem(item)
        service_definition = dict(svc.properties)

        is_view = False
        if "isView" in service_definition and service_definition["isView"] is not None:
            is_view = service_definition["isView"]

        # Get the definitions of the the layers and tables
        layers_definition = {'layers' : [], 'tables' : []}
        for layer in svc.layers:
            layers_definition['layers'].append(dict(layer.properties))
        for table in svc.tables:
            layers_definition['tables'].append(dict(table.properties))

        # Get the item data, for example any popup definition associated with the item
        data = item.get_data()