graticule | Create graticule objects
kandi X-RAY | graticule Summary
kandi X-RAY | graticule Summary
Graticules are the longitude latitude lines shown on a projected map, and defining and drawing these lines is not easy to automate. The graticule package provides the tools to create and draw these lines by explicit specification by the user. This provides a good compromise between high-level automation and the flexibility to drive the low level details as needed, using base graphics in R.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of graticule
graticule Key Features
graticule Examples and Code Snippets
Community Discussions
Trending Discussions on graticule
QUESTION
I am trying to add a grid to my map (just like the graticule) using distances between lines and I would like the line labels to stay at the same position and have the grid updated on view change.
I am listening to prerender events on a vector layer and drawing from the CanvasImmediateRenderer
returned by getVectorContext(event);
and I have been unsuccesful at keeping the labels sticking to the top and left borders.
Any help is very much appreciated.
...ANSWER
Answered 2021-Apr-29 at 08:33It looks like line placement of text does not work well with immediate rendering. Separate Point drawings for the labels would be better, you could use event.framestate.extent
to determine the left or top coordinates.
Use a separate style for top and side labels, textAlign
'left'
or 'right'
as appropriate and a Math.PI/2 rotation for the top labels.
To force rendering for the grid use a dedicated layer with one barely visible feature and an infinite renderBuffer like so :
QUESTION
I am trying to rotate a globe (orthographic projection). What I have now does rotate the globe, though it is very choppy, and it breaks how the map looks after i drag it (graticules and ocean fill)
How can I improve my code to make it better? Here is the relevant code:
...ANSWER
Answered 2021-Mar-21 at 12:12Okay so I did two things.
Inside of the
dragged
function instead of selecting all the path elements as one I selected them individually... so replace the linesvg.selectAll("path").attr("d", pathGenerator)
withsvg.selectAll(".graticule").attr("d", pathGenerator)
andsvg.selectAll(".country").attr("d", pathGenerator)
.When you append the countries you use selectAll('path') like this
g.selectAll('path').data(countries.features)
... I think this confuses d3 because you have already appended some path elements so I changed it to a unique selector like thisg.selectAll('.country').data(countries.features)
.
I'm not 100% sure why d3 behaves like that (maybe @AndrewReid can shed some light) but i've learned from experience that it's best practice to use unique selectors when appending and updating SVG elements with d3.
QUESTION
I have a world map build in D3.js For performance's sake I am using world-atlas 110m version, but I want to increase the map detail as I zoom in.
I also want to change projection and, therefore topojson file when I click on the United States. (That is to use geoAlbersUsa(), and render US states)
I've got some very basic functionality on changing the map projection on click, but I am struggling on how to change the topojson file.
...ANSWER
Answered 2021-Feb-05 at 04:47If you want to change features/data source/whatever with zoom, you'll need to get the current zoom state, which is contained in the the event passed to the zoom event listener (or d3.event before d3 v6).
This gives us a relatively easy zoom listener:
QUESTION
I'm a D3 beginner and I want to use this d3 element into my Vue.js component. The problem here is that the periodic rotation I need does not work. It starts looping errors of null on the element projection that is globally defined. It seems that the first time works but in the second one the object is no longer defined.
Here's the code:
...ANSWER
Answered 2020-Nov-30 at 21:28I solved my problem remembering that in Javascript sometimes "this" element is not always what we expect when we work inside other functions.
So what I needed to do was to save the "this" object in a variable and using that variable to do what I needed:
QUESTION
I am modifying this example so that I can dynamically add the locations. I need to modify the lineToLondon
function to make it accept a dynamic source. Right now, it sets London as the source everytime. In my fiddle, I've defined a new function called lineToLocation
that tries to do this, but I can't seem to get it working. I get Uncaught TypeError: Cannot read property 'coordinates' of undefined
My fiddle can be found here: https://jsfiddle.net/p0r6tmqs/2/. Note: I am sourcing the data dynamically, so the source will not be known ahead of time.
...ANSWER
Answered 2020-Nov-11 at 20:38i dunno how you initialize src but, i have no problem if i write
QUESTION
I have modified this d3 example to dynamically add the places/dots and red line AFTER the globe is drawn. (Essentially, I want to add data dynamically rather than starting with a fixed set of points like the example does). The red dotted line gets drawn but, as the globe spins, the lines stay in the same position. How do I get my lines to spin with the globe like they do in the example? My fiddle: https://jsfiddle.net/6qhvt8aL/2/
...ANSWER
Answered 2020-Nov-11 at 05:57You update everything in the refresh function except the lines, you just need to update those as well.
You can't use svg.selectAll(".lines").attr("d", lineToLondon)
because you have a g
with a class lines
holding all the paths with that class. Instead you can use:
QUESTION
I'm using healpy to plot the locations of galaxies on the sky from a list of RAs and Decs. So far, I think I've been able to correctly plot the galaxies, but I'd like to improve the finished product. Is there any way to bin the number of galaxies that appear in each healpy tile, rather than just coloring being based on whether there is or isn't a catalog member in the tile?
Here I show the image that I'm currently making —
right now it's only really useful for telling you where the Milky Way isn't. Here's the code I'm using.
...ANSWER
Answered 2020-Sep-28 at 20:47You could use numpy.bincount
to create an array of the number of galaxies per pixels and then create a map of that.
QUESTION
When having a marker on a globe, the marker lays flat on the surface.
Although there might be trouble the moment the marker rotates out of sight; is there a way to give this marker height?
Instead of a dot on the surface of the globe, I'm trying to get a dot on a needle, sticking out a little bit above the surface of the globe.
Not this:
...ANSWER
Answered 2020-Nov-04 at 14:49Using this answer as inspiration, you can create a second projection, equivalent to the first one, but with a larger scale
value. That will project a point directly above the actual point on the globe, as if it was hanging above it. This allows you to draw a line from the ground up, and look at it from all angles. It even works with your hide marker logic.
QUESTION
I'm trying to set the size of this globe to 200 x 200px.
I've learned that the projection is currently sized 960 x 500px.
Changing the size of the SVG doesn't shrink the globe. I'm having trouble understanding why.
Without luck I have tried to add the following to the code:
...ANSWER
Answered 2020-Nov-03 at 06:19Projection.scale()
The scale of the projection determines the size of the projected world. Generally speaking d3 projections have a default scale value that will fill a 960x500 SVG/Canvas. A map produced with d3.geoOrthographic doesn't have a long edge, so this is 500x500 pixels. The default scale value is: 249.5 - half the width/height (allowing for stroke width). This scale factor is linear on both width and height: double it and double both (quadruple projected size of world). So if you want a 200x200 px world you'll want: 99.5 to be your scale value.
This is the default for d3.geoOrthographic, other scales have other scale defaults. For a Mercator, for example, it is 480/π: 2π of longitude across 960 pixels of width.
Projection.translate()
However, if you change the scale for a 200x200 pixel world, you'll have an issue with the default projection translate. By default this is set to [250,480] - half of [500,960], the default D3 anticipated size of the SVG/Canvas. This coordinate is where the geographic center of the projection (by default 0°N,0°W) is projected to. You'll want to change this to a value of [100,100]: the center of your SVG/Canvas.
Solution
QUESTION
ANSWER
Answered 2020-Jun-09 at 21:32D3 is fairly unique when it comes to geographic data: it uses spherical math (which despite many benefits, does lead to some challenges). d3.geoPath samples a line segment between two points so that the path follows a great circle (the shortest path between two points on a globe). Parallels do not follow great circle distances, so your path does not follow the parallel.
The behavior you are looking for requires us to draw a line between two points of latitude longitude as though they were Carteisan, even though they are not, and then preserve the points along that line when applying the stereographic projection.
When using an cylindrical projection the solution is easy enough, don't sample between points on a line. This answer contains such a solution.
This doesn't help with a stereographic projection - the linked approach would just result in a straight line between the first point and end point instead of a curved line along the parallel.
A solution is to manually sample points between start and end as though the data were Cartesian, then treat them as 3D in order to project them with a stereographic projection. This results in a path that follows parallels where start and end have the same north/south value. How frequently you sample reduces/eliminates the effect of great circle distances when using d3.geoPath.
In my solution I'm going to use two d3 helper functions:
- d3.geoDistance which measures the distance between two lat long pairs in radians.
- d3.interpolate which creates an interpolation function between two values.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install graticule
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page