Beispiel #1
0
def bb():    
    try:
        # script to update the status of the blue bikes
        r = requests.get('https://gbfs.bluebikes.com/gbfs/en/station_status.json')
        r = r.json()['data']['stations']
        df = pd.DataFrame.from_dict(json_normalize(r), orient='columns')
        df = df.rename(columns={'last_reported':'last_reported','station_id':'description', 'num_bikes_available':'bikes_available',
                                'num_docks_available':'docks_available'})

        
        bb_table = df[['last_reported','description', 'bikes_available', 'docks_available']]
        
        bb_features = gis.content.get(fc_id).layers[7]
        bb_features
        bb_fset = SpatialDataFrame.from_layer(bb_features)
        bb_fset = bb_features.query(where="category_subtype = 'Blue Bikes'") #querying without any conditions returns all the features    

        overlap_rows = pd.merge(left = bb_fset.sdf, right = bb_table, how='inner', on = 'description')
        
        #print (overlap_rows.head())
        features_for_update = [] #list containing corrected features
        all_features = bb_fset.features

        # inspect one of the features
        #print (all_features[2])

        # update all features that were joined
        for root_id in overlap_rows['description']:    
            # get the feature to be updated
            original_feature = [f for f in all_features if f.attributes['description'] == root_id][0]

            feature_to_be_updated = deepcopy(original_feature)        

            # get the matching row from csv
            matching_row = bb_table.where(bb_table.description == root_id).dropna()
            #print('snr' + tablenumber + '', 'snr' + tablenumber + 'average', float(matching_row['snrval'].values))
            
            timestamp = matching_row['last_reported'].values[0]
            
            #print (str(datetime.fromtimestamp(timestamp)))
            feature_to_be_updated.attributes['use_type'] = matching_row['bikes_available'].values[0]
            feature_to_be_updated.attributes['source_name'] = matching_row['docks_available'].values[0]
            #feature_to_be_updated.attributes['source_type'] = str(datetime.fromtimestamp(matching_row['last_reported'].values[0]))
            
            feature_to_be_updated.attributes['source_type'] = str(datetime.fromtimestamp(matching_row['last_reported'].values[0]).strftime("%I:%M %p"))

            features_for_update.append(feature_to_be_updated)
        #print (features_for_update)
        bb_features.edit_features(updates= features_for_update)
    except:
        print("Something went wrong")
        os._exit(0)
Beispiel #2
0
from arcgis.gis import GIS
from arcgis.features import SpatialDataFrame
from IPython.display import display
import passwords

gis = GIS("https://www.arcgis.com", passwords.user_name, passwords.password)

search_results = gis.content.search(
    query='title: "Park*" AND type: "Feature Service"')
display(search_results)

# In[2]:

feature_service_item = search_results[0]
feature_layer = feature_service_item.layers[0]
display(feature_layer)

# In[3]:

# Search for an item and construct a Spatial Data Frame

# In[4]:

sdf = SpatialDataFrame.from_layer(feature_layer)
sdf.head()

# In[ ]:

# sdf.to_featureclass(out_location = 'path/to/save/data', out_name = 'file.shp')
Beispiel #3
0
gis = GIS("URLofESRIPortal", UserID, Password)
print("Connected")
siteMessages = []
for key, value in sites.items():
    #print(value)
    item = gis.content.get(value)
    #print(item)

    flayer = item.layers[0]
    #print(flayer)
    #Query produces a Feature Set, which is needed to call .features
    fSet = flayer.query()
    #Stores all features so that ones needing update can be copied
    all_features = fSet.features
    #Pulls data into Data Frame for manipulation with Pandas
    ESRIdf = SpatialDataFrame.from_layer(flayer)
    #print(ESRIdf.head())

    features_for_update = []
    #Iterate over ESRI Data Frame
    print("Starting Query")
    for index, row in ESRIdf.iterrows():
        # skip rows that already have a gateway IP or don't contain a machine
        if pd.notnull(row['gatewayip']) or row['followup'] != 'No':
            #print("Skipped Row")
            continue
        # Skip rows without an asset tag
        elif pd.isnull(row['asset']):
            #print("Skipped " + str(row['objectid']))
            continue
        else: