How to set an offset for a RichMarker? - ruby-on-rails

Failed enough to ask another question:
Using
gmaps4rails v0.11.1 - great gem!
RichMarker
Managed to make markers flat using :marker_anchor => [10, true]
But i have an arrow on the bottom of the marker, so how to set an offset for a marker`s html(RichMarker) to be placed?
Now it is done by setting a css offset for a div in the richmarker html. But that seems kind a wierd.
Is it possible to set an offset using Gmaps4rails methods?

Have a look at the wiki in the markers section:
"rich_marker" => , # html, facultative
# If used, all other attributes skipped except "marker_anchor". This array is used as follows:
# [ anchor , flat ] : flat is a boolean, anchor is an int.
# See doc here: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/docs/reference.html
So basically, the first element of 'marker_anchor => [10, true]' represents the offset.
Have a look at the link I provide: Richmarker's offset aren't expressed with pixels but are integers meaning TOP_LEFT etc...
If you desire precise offset, keep your css!

Related

Buffer country borders with st_buffer and a SpatialPolygonsDataFrame?

I'm using coordinate_cleaner's country test cc_coun but it's flagging entries with coordinates near to the edges country borders. To try to keep them I wanted to buffer the terrestrial area of countries, essentially expanding their borders a little so that it doesn't flag these entries.
I've tried:
require(rnaturalearth)
world <- ne_countries(scale = "large", returnclass = "sf") %>% st_buffer(dist=.001)
Using st_buffer(dist=.001) does change the geometry, but I noticed whatever I put into dist doesn't matter as it changes it to the same thing regardless (I tried .001, 0.1, 1, 2, and -1, though any minus number removes the geometry altogether).
I found that maybe I need to transform my sf file into something else and then use st_buffer so it's in meters rather than degrees(?). I saw this question/answer but I don't understand it well enough to help my situation: What unit is the `dist` argument in `st_buffer` set to by default?
In the end I'm looking to create a SpatialPolygonsDataFrame reference file to feed into cc_coun. Using the above code I followed on with:
world <- sf:::as_Spatial(world)
coun_test <- cc_coun(x = data,
lon = "Decimal_Long",
lat = "Decimal_Lat",
iso3 = "Country_code",
value = "flagged",
ref = world,
verbose = TRUE)
Which ended up flagging more entries than when I didn't use st_buffer on the reference fine.
In summary, I want to add a buffer to the edge of every country border by around 100 meters in a file I can use as a reference in this test. Is this the best way to go about it or is there a better/easier way? I'd appreciate any advice.
Thank you

Format Altair choropleth map legend scale and tooltip

I am trying to make the tool tip 'Percentage' be an actual percent and not a decimal. Even when I include alt.Tooltip('Percentage:Q',format='.2%'), it doesn't seem to work.
Also, I am trying to make the legend scale from 0-100% instead of 40-70%.
Any help would be appreciated!
import altair as alt
from vega_datasets import data
states = alt.topo_feature(data.us_10m.url, 'states')
variable_list = ['Percentage', 'State Name', 'state_id']
alt.Chart(states).mark_geoshape().encode(
color=alt.Color('Percentage:Q', title='Positive NFB', legend=alt.Legend(format=".0%"), scale=alt.Scale(scheme='yellowgreen')),
tooltip=['State Name:N', 'Percentage:Q', alt.Tooltip('Percentage:Q',format='.2%')]).properties(title="Percentage of People in Households with Positive NFB"
).transform_lookup(
lookup='id',
from_=alt.LookupData(states_positive_NFB, 'state_id', variable_list)
).properties(
width=500,
height=300
).project(
type='albersUsa'
)
Current map:
To change the domain of the color scale, you can pass the domain argument to alt.Scale(): e.g.
alt.Scale(scheme='yellowgreen', domain=[0, 1])
To make the tooltip format appear, you can remove the duplicated tooltip encoding, as the first one appears to be taking precedence. That is, rather than
tooltip=['State Name:N', 'Percentage:Q', alt.Tooltip('Percentage:Q',format='.2%')]
you should use
tooltip=['State Name:N', alt.Tooltip('Percentage:Q', format='.2%')]

How to get the bounding box from a Revit Element with Revit API, then call to center of that bounding box

I am trying to rotate Revit elements about their center points. In order to do that, I need to select a Revit element and find its center point, then create a line with the coordinates at that elements center point.
My best idea to accomplish this is to wrap a Revit element in a bounding box and then find the center of that box. My problem is that I am unsure how to accomplish this.
I am using pyRevit (amazing tool) and I am stuck on how to either wrap the selected element with a bounding box or retrieve its existing bounding box.
Any help would be greatly appreciated! I am really trying to learn the Revit API and understand how everything works. I am making progress but there is a lot to unpack.
def pickobject():
from Autodesk.Revit.UI.Selection import ObjectType
#define the active Revit application and document
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
#define a transaction variable and describe the transaction
t = Transaction(doc, 'This is my new transaction')
# Begin new transaction
t.Start()
# Select an element in Revit
picked = uidoc.Selection.PickObject(ObjectType.Element, "Select something.")
### ?????????? ###
# Get bounding box of selected element.
picked_bb = BoundingBoxXYZ(picked)
# Get max and min points of bounding box.
picked_bb_max = picked_bb.Max
picked_bb_min = picked_bb.Min
# Get center point between max and min points of bounding box.
picked_bb_center = (picked_bb_max + picked_bb_min) / 2
### ?????????? ###
# Close the transaction
t.Commit()
return picked, picked_bb_center
Thanks in advance for taking a look at what I have so far. Please let me know if anything needs further clarification!
edit:
#CyrilWaechter
I think you are right. Using LocationPoint would probably make more sense. I looked through the script you linked (thank you btw!) and I tried implementing this section in my code.
transform = doc.GetElement(picked.ElementId).GetTransform()
I am passing the ElementId through this statement but I get the error, "Wall" object has no attribute 'GetTransform'. Could you please help me understand this?
edit 2:
Thanks #JeremyTammik and #CyrilWaechter, your insights helped me understand where I was going wrong. While I still feel that certain properties are ambiguous in the Revit API, I was able to get my code to execute properly. I will post the code that I was able to get working below.
The centre of the bounding box is very easy to obtain. picked is a Reference. Get the ElementId from that, open it using doc.GetElement, and retrieve the bounding box using get_BoundingBox, cf. Conduits Intersecting a Junction Box
:
Element e = Util.SelectSingleElement(
uidoc, "a junction box" );
BoundingBoxXYZ bb = e.get_BoundingBox( null );
For certain elements and certain irregular shapes, you might want to use the centroid instead of the bounding box:
Solid Centroid and Volume Calculation
GetCentroid on GitHub
Edited and preserved for posterity by The Building Coder:
Python Rotate Picked Around Bounding Box Centre
Many thanks to Christian for the interesting discussion and Cyril for the wealth of additional information he provides!
Here is how I was able to solve my problem using pyRevit. This code allows you to rotate an element about its Z axis from the center of its bounding box.
To use this code, select a single Revit element and then open the Revit Python Shell. Copy and paste the code below into the Revit Python Shell notepad and click the run button. This will rotate the element by 45 degrees because the current rotateSelectedElement() argument is 45. You may change this number to any value before running.
# Import the math module to convert user input degrees to radians.
import math
# Get a list of all user selected objects in the Revit Document.
selection = [doc.GetElement(x) for x in uidoc.Selection.GetElementIds()]
# Definitions
def rotateSelectedElement(degrees_to_rotate):
from Autodesk.Revit.UI.Selection import ObjectType
#define the active Revit application and document
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
#define a transaction variable and describe the transaction
t = Transaction(doc, 'This is my new transaction')
# Convert the user input from degrees to radians.
converted_value = float(degrees_to_rotate) * (math.pi / 180.0)
# Begin new transaction
t.Start()
# Get the first selected element from the current Revit doc.
el = selection[0].Id
# Get the element from the selected element reference
el_ID = doc.GetElement(el)
# Get the Bounding Box of the selected element.
el_bb = el_ID.get_BoundingBox(doc.ActiveView)
# Get the min and max values of the elements bounding box.
el_bb_max = el_bb.Max
el_bb_min = el_bb.Min
# Get the center of the selected elements bounding box.
el_bb_center = (el_bb_max + el_bb_min) / 2
#Create a line to use as a vector using the center location of the bounding box.
p1 = XYZ(el_bb_center[0], el_bb_center[1], 0)
p2 = XYZ(el_bb_center[0], el_bb_center[1], 1)
myLine = Line.CreateBound(p1, p2)
# Rotate the selected element.
ElementTransformUtils.RotateElement(doc, el, myLine, converted_value)
# Close the transaction
t.Commit()
# Execute
# Add the desired degrees to rotate by as an argument for rotateSelectedElement()
rotateSelectedElement(45)
edit: Made code clearer. Code now executes in Revit Python Shell without any further modifications. Refer to directions above if you have trouble!

Remove legend bar in R using Image.Plot

This is the test code im using
x_coord <- c(1,2,3,4)
y_coord <- c(1,2,3,4)
value <- c(12,15,19,30)
foo <- data.frame(x_coord, y_coord, value)
library(MBA)
foo=foo[ order(foo[,1], foo[,2],foo[,3]), ]
mba.int <- mba.surf(foo, 300, 300, extend=T)$xyz.est
library(fields)
fields::image.plot(mba.int,legend.only = FALSE, axes=FALSE)
The axes part deletes the axis, but when i try to remove the legend bar, the vertical bar indicating the color measurements, it will not go away.
i have tried smallplot = 1, but that gives me an error but it gets rid of the vertical legend,
Anyone have any idea of how to get rid of the legend without any errors produced ?
If you don't want the color legend, just use the built-in image function instead. The function you are using is designed specifically for adding a legend easily.
If you want to keep the same color scheme as the fields image.plot function:
image(<your data>, ..., col = tim.colors())
Using this creates the exact same image without a legend.
The image and image.plot functions actually have quite different plotting functionality.
One problem (at least for me, trying to plot regional climate model data) with using the built-in image is that it cannot handle irregular grids. The image.plot function uses the poly.image function internally to create the plot. Both are included in the fields package. The good thing is that the poly.image function also can be used on its own, for example like this:
library("fields")
# create an example of an irregular 3x3 grid by adding random perturbations up to ±0.6
x <- matrix(rep(1:3,each=3) + 0.6*runif(9), ncol=3)
y <- matrix(rep(7:9,times=3) + 0.6*runif(9), ncol=3)
# 9 values, from 1 to 9
z <- matrix(1:9,nrow=3)
# Please avoid the default rainbow colours, see e.g.
# https://www.climate-lab-book.ac.uk/2014/end-of-the-rainbow/
# Other examples of colour schemes: https://colorbrewer2.org/
col <- colorRampPalette(c("#2c7bb6","#abd9e9","#ffffbf","#fdae61","#d7191c"))(9)
par(mfrow=c(1,3), mar=c(4,4,4,1), oma=c(0,0,0,0))
image(x=7:9,y=1:3,z,col=col, main="image()\n Only regular grid. Also note transposition.")
image.plot(x,y,z,col=col, main="image.plot()\n Always with colorbar.")
poly.image(x,y,z,col=col, main="poly.image()\n Does not include colorbar.")

Each statement inside another each malfunctions?

I'm coding a Google sketchup plugin with Ruby, and I faced a little problem. I have an array containing descriptions of every point like:
desc_array = ["anna ", "anna 45", "anna689", "anna36", "anna 888", "anna ",...]
The array containing every point's coordinates is:
todraw_su = [
[-16.23317, -16.530533, 99.276929],
[-25.142825, -12.476601, 99.237414],
[-32.716122, -5.92341, 99.187951],
[-38.964589, 4.181119, 99.182358],
[-41.351064, 18.350418, 99.453714],
[-40.797511, 33.987519, 99.697253],
...
]
I want to add a text in Google sketchup for each point. According to the Sketchup API this can be done by:
Sketchup.active_model.entities.add_text "This is the text", [x, y, z]
I tried:
todraw_su.each {|todraw| desc_array.each {|desc| Sketchup.active_model.entities.add_text desc,todraw }}
But, it gave me something unexpected, as it returns all the elements in desc_array for every element in to_draw.
What I want is every element in desc_array for every element in to_draw.
[desc_array, todraw_su].transpose.each do |desc, coord|
# ...
end
You can also do this with #zip like...
desc_array.zip(todraw_su).each do |desc, coord|
# ...
end
With the #zip technique, the result will always have the first array's dimension, with the second truncated or nil-padded as needed. This may or may not be TRT. Transpose will raise IndexError in that case.

Resources