I am using folium to generate a map.
m = folium.Map(
location=[47.842167, -120.101655],
zoom_start=8,
tiles='Stamen Toner'
)
points = (47.842167, -120.101655), (46.835627, -118.26239)
folium.Rectangle(bounds=points, color='#ff7800', fill=True, fill_color='#ffff00', fill_opacity=0.2).add_to(m)
m
I would like to save just the part that is in the rectangle..
Is it possible to do that with python ?
Thank you in advance.
Using a combination of disabling pan and zoom features and also using folium's fit_bounds() you could do something like this. I think this comes close to your goal
Note: if you don't want to "lock down" the exported file, you can omit the last 3 params in Map() i.e. zoom_control, scrollWheelZoom and dragging
m = folium.Map(
location=[47.842167, -120.101655],
zoom_start=8,
tiles='Stamen Toner',
zoom_control=False,
scrollWheelZoom=False,
dragging=False
)
sw = [46.835627, -120.101655]
ne = [47.842167, -118.26239]
m.fit_bounds([sw, ne])
m.save('mymap.html')
Related
Is it possible to select color attributes in blender with python? Idea is to do the same like clicking on the vertex color in viewport. The goal is to make the colors visible in the viewport.
My current approach looks like this:
# accessing color attributes
test_1 = bpy.data.meshes['Cube'].color_attributes['test_1']
test_2 = bpy.data.meshes['Cube'].color_attributes['test_2']
# try to change selection
bpy.ops.geometry.color_attribute_render_set(name="test_2")
Unfortunately this is not working. Is there an easy approach to solve this? Thanks in advance.
Solved it by creating a material like this:
def create_mat():
mat = bpy.data.materials.new(name="test")
obj.data.materials.append(mat)
mat.use_nodes = True
mat.node_tree.nodes.new(type="ShaderNodeVertexColor")
mat.node_tree.nodes["Color Attribute"].layer_name = "test_1"
input = mat.node_tree.nodes["Principled BSDF"].inputs["Base Color"]
output = mat.node_tree.nodes["Color Attribute"].outputs["Color"]
mat.node_tree.links.new(input, output)
def change_mat():
mat = bpy.data.materials["test"]
mat.node_tree.nodes["Color Attribute"].layer_name = "test_2"
create_mat()
change_mat()
I have a situation, where I decided to distinguish my markers slightly by adding the MarkerCluster to the existing Marker.
The clustering works, although isn't synchronized. It means, that if I switch one layer off, just the first markercluster disappears, whereas the second criterion defined as CircleMarker still appears like shown below.
My code is:
df = pd.read_csv("or_geo.csv")
fo=FeatureGroup(name="OR",overlay = True)
openreach_cluster = MarkerCluster(name="OR").add_to(map)
openreach_status = MarkerCluster(control=False,
visible=True
).add_to(map)
for i,row in df.iterrows():
lat =df.at[i, 'lat']
lng = df.at[i, 'lng']
sp = df.at[i, 'sp']
stat = df.at[i,'status']
popup = df.at[i,'sp'] +'<br>' + str(df.at[i, 'street']) + '<br>' + str(df.at[i, 'post code']) + '<br>{}'.format(style)
or_marker = folium.Marker(location=[lat,lng], tooltip='<strong>Job details</strong>', popup=popup, icon = folium.Icon(
color='blue', icon='glyphicon-calendar'))
or_stat_marker = folium.CircleMarker(
location=[lat,lng],
radius=10,
color=or_color(stat),
fill_color=or_color(stat),
fill_opacity=0.5)
openreach_cluster.add_child(or_marker)
openreach_status.add_child(or_stat_marker)
Is there any way to combine these markerClusters together or sync them?
UPDATE:
The first approach from the answer below, unfortunately, doubles the jobs up and the user can't see them until clicks on any of them shown below:
This option would be fantastic if the behavior could be the same as in the image above.
UPDATE II:
The second approach is still not what I am looking for, because the clusters are doubled again and after clicking the circlemarker falls almost in the opposite direction as presented in the image above.
I need to have the behaviors exactly like those displayed on the top-left image. The circlemarker should be integrated with the point marker.
If I got you right, I think there are two possibilities:
Use the same cluster
Add your markers from or_stat_marker to the openreach_cluster and not to another cluster to de-/activate them at the same time with the same button
# was
openreach_cluster.add_child(or_marker)
openreach_status.add_child(or_stat_marker)
# try this
openreach_cluster.add_child(or_marker)
openreach_cluster.add_child(or_stat_marker)
Use marker subgroups
In this case you will have three checkmarks, one parent and two childs for each markercluster which gives full control to visibility
UPDATE: If you add the control=False option to the subgroup you will only see the parent group in LayerControl which then show/hide both groups. But the matter of markers "spreading for visibility" still is a problem I think
Another UPDATE: You are able to deactivate the clustering according to the map zoom level or even at all by using disableClusteringAtZoom option (use True or an int number for zoom level). See here for reference
# markergroups in layercontrol
mc = folium.plugins.MarkerCluster(name='OR',
overlay=True,
control=True,
show=True,
disableClusteringAtZoom=15) # choose zoom lvl to your needs
mc.add_to(map)
sub1 = folium.plugins.FeatureGroupSubGroup(mc, name='openreach_cluster', control=False, show=True) # False --> deactivated at start
sub1.add_to(map)
sub2 = folium.plugins.FeatureGroupSubGroup(mc, name='openreach_status', control=False)
sub2.add_to(map)
# the layercontrol itself
lc = folium.map.LayerControl(collapsed=False)
lc.add_to(map)
# ...
for i, row in df.iterrows():
# ...
or_marker = folium.Marker(...)
or_marker.add_to(sub1)
or_stat_marker = folium.CircleMarker(...)
or_stat_marker.add_to(sub2)
My Result:
By following the second approach described I get a map shown here. There is one checkmark "Segment Markers" which shows/hides the markers including the circles. They don't move around when clicked and are fully shown when zoomed in to a specific lvl by using disableClusteringAtZoom.
Sorry this didn't work for your problem, I really don't know why ..
Exactly like the title says, I've used some code that I collected from multiple places to build up this Chord diagram, but unfortunately one last thing that's kind of going to hinder that 100% perfection is this popup that shows up whenever I hover over the label. The pop up remains there even when the mouse is moving elsewhere...
By the way, I'm using Python and Holoviews for plotting the chord.
I'm pretty sure this is due to a bug or something... however, I'd love to find a way to bypass it...
Example here : bug example
Code :
%%opts Chord [height=600 width=600 title="Transactions from 2000 to 2021" ]
#plot
#edit links = moves[moves['Transactions'] > x] // x refers to the number of transactions minimum for the diagram display
moves = moves[moves['Transactions']>5]
links = moves
chord = hv.Chord(links)
chord
nodesl = []
c = []
for i, row in moves.iterrows():
c.append(row[0])
c.append(row[1])
c = pd.DataFrame(c)
c.drop_duplicates(inplace=True)
c.reset_index(inplace=True)
c.drop(columns='index', inplace=True)
c
nodes = []
for i, row in c.iterrows():
nodes.append({'name':row[0]})
nodes = pd.DataFrame(nodes)
# nodes
nodes = hv.Dataset(nodes, 'name')
nodes.data.head()
%%opts Chord [height=800 width=800 bgcolor="black"]
%%opts Chord [title="Transactions from 2000 to 2021 (Countries with over 5 moves)\nTip: Please do not hover over the label as it might produce a bug, else refresh the page" ]
chord = hv.Chord((links, nodes)).select(value=(5, None))
#this function allows text to fit perfectly on the screen
def rotate_label(plot, element):
text_cds = plot.handles['text_1_source']
length = len(text_cds.data['angle'])
text_cds.data['angle'] = [0]*length
xs = text_cds.data['x']
text = np.array(text_cds.data['text'])
xs[xs<0] -= np.array([len(t)*0.019 for t in text[xs<0]])
chord.opts(
opts.Chord(cmap='Category10',
edge_color=dim('Target').str(),
node_color=dim('name').str(),
labels='name',
label_text_color="white",
hooks=[rotate_label]
))
chord
The ??? usually indicates that some field it's trying to display isn't available; not sure why that would be in this case. You can always override the default tools HoloViews uses for Bokeh by setting default_tools=[] and then specify whatever tools you do want, without 'hover', e.g. tools=['save', 'pan', 'wheel_zoom', 'box_zoom', 'reset'].
Beginner python user, having some success with heatmaps using Folium. I am experimenting with using the Global Terrorism Database as a source for some visualizations but I really wanted to use ipywidgets to select a specific terrorist group from a list to update my heatmap. I've already constructed a heatmap for ISIS, created an ipyvuetify button containing the groups I want to compare, but am having trouble figuring out the function and widgets.link syntax. I'd really appreciate some help because there don't seem to be any good guides (for my skill level) on how to do what I'm trying to do here.
import ipyvuetify as v
import ipywidgets as widgets
import folium
from folium import plugins
from folium.plugins import HeatMap as hm
map = folium.Map(location = [25,15], tiles = "cartodbdark_matter", zoom_start = 2)
selected = gtd.loc[gtd['Group'] == 'Islamic State of Iraq and the Levant (ISIL)']
coords = selected[['Latitude','Longitude']]
hm(coords).add_to(map)
terrorists = [
'Taliban',
'Shining Path (SL)',
'Islamic State of Iraq and the Levant (ISIL)',
'Farabundo Marti National Liberation Front (FMLN)',
'Al-Shabaab',
'Irish Republican Army (IRA)',
'Revolutionary Armed Forces of Colombia (FARC)',
'New Peoples Army (NPA)',
'Kurdistan Workers Party (PKK)',
'Boko Haram']
# This is where things go off the rails for me, not exactly sure how to arrange this function
def update(x):
if widget_terrorist_selector.selected is not None:
xmin, xmax = widget_terrorist_selector.selected
widget_terrorist_selector.observe(update,'widget_terrorist_selector')
# The selector here works but I can't figure out how to link it to my map so that it pushes a new set of heatmap coordinates
widget_terrorist_selector = v.Select(label='Choose Option', items=terrorists, v_model=terrorists[0])
widget_terrorist_selector
# This bit keeps throwing a "TypeError: Each object must be HasTraits, not <class 'pandas.core.frame.DataFrame'>"
widgets.link((widget_terrorist_selector,'v_model'),(selected, 'Group'))
Thanks in advance!
widgets.link is used for keeping two ipywidgets in sync. I'm not sure that's what you're trying to achieve here, it can probably be achieved with plain old observe.
I think in your update function you need to make the necessary change to your map, something like
def update(x):
new_choice = widget_terrorist_selector.selected
selected = gtd.loc[gtd['Group'] == new_choice]
coords = selected[['Latitude','Longitude']]
hm(coords).add_to(map)
I get all shapes assigned to baseMaterial, select the shapes and then assign the occlusionShader.
for materialClass in materialClassList:
select(materialClass.baseMaterial)
hyperShade(objects="")
hyperShade(a=materialClass.occlusionShader)
works just fine, but if I use it as a pre render script:
Error: line 0: hyperShade command not supported in batch mode
What can I change the two last lines of my function to to make this work?
Here is an example with cmds.sets() to assign a shader :
all = cmds.ls(type='mesh')
shadingEngine = 'initialShadingGroup'
cmds.sets(all, e=True, forceElement=shadingEngine)
as you can guess, to query meshes with the material :
lamb1_mshs = cmds.sets(shadingEngine, q=True)
i got it to work with:
for materialClass in materialClassList:
sets(materialClass.occlusionShadingGroup, e = True, forceElement = materialClass.meshList)
I collect the meshes when I create the materialClass now, which makes much more sense then selecting them for each renderlayer.