R leaflet.minicharts change addflows direction on map - r

I have a leaflet map in R, and am using the leaflet.minicharts function addFlows to show direction of product from origin to destination. This causes some confusion on the links from China to the United States. Leaflet defaults to showing the lines going from east to west, instead of from west to east, across the Pacific Ocean. Is there any way to change the direction the China --> United States lines are plotted?

Answering my own question, for future searchers.
For longitudes < 0 degrees (Western Hemisphere), add 360 degrees. This makes China --> US flows go over the International Date Line.
Note that you need to do this for both the leaflet.minicharts::addFlows lng0 and lng1, and the longitude of any markers/circlemarkers.
Referencing accepted answer at
How to display Leaflet markers near the 180° meridian?

Related

r - plotting lines with mapview - automatically connects inaccurately

I`m trying to plot flights with mapview::mapview() but I have this problem where mapview automatically connects flights with straight lines if they go from Australia towards South America (across the Pacific Ocean), or from Russia to Canada (across the North pole) - see image below. Can this be fixed somehow? Removing the straight lines artificially introduced would solve my problem, but other ideas and suggestions are welcomed
:

Original Plotl.y map inverted North and South Korea

I am making a choropleth map using the Plot.ly demo and noticed that Plot.ly's global map inherently inverted North and South Korea. That is, on a map, North Korea's position is in the South, and the South Korea's location is in the North.
Of course, I can always act as if North is South, and vice versa, by entering data on the opposite vectors. However, this is a bit "unprofessional" communicating with others working on data entry.
When working with problems like this, is there a way to change the contents of the package myself?

How to get the bounding box for a particular city for openmap() in R?

I'm trying to plot a map of San Francisco using R and perform some operations over it. I am not understanding about the calculation of bounding box given a specific city. I am new to R please help me with this.
install.packages("OpenStreetMap")
library(OpenStreetMap)
#City of San Francisco 37.6213° N, 122.3790° W
SFO_map=openmap(c( ),c( ),type="osm")
plot(SFO_map)
I use https://boundingbox.klokantech.com/ and select the visual bounding box on the place I am interested. If you select TSV it gives you the bounding box:
You need to identify upper left coordinates for SF (far west part of the City, like the Presidio and north, like the Golden Gate Bridge) and lower right coordinates (far east, like west Oakland, and south, perhaps Pacific Grove), then put them in the right order in the call. By 'right order', the first latitude is less than the second latitude (or that is what I think I learned from trial and error.). Here is the map of part of Princeton, NJ.
Princeton_map <- openmap(c(40.3832,-74.674273), c(40.339373,-74.661333), type="osm")

Divide a city into regions in Google Maps

I am trying to divide a certain city into several blocks, each representing North, North-West, North-East, South...and so on. I just need the coordinates of the region boundaries (e.g.: North is between X and Y latitude and between Z and T longitude), so that I can check in my app whether a point belongs to a region or another. The regions should not depend on a certain zoom level's boundaries and they don't need to be the same size (maybe the North part of a city is a little bit larger then the South one).
Any idea how can I "draw" these region boundaries? Thank you!
For boundary data, you would have to do a search. Depends on the city and country. In the US, many municipalities provide this data directly through a city or country web site. Generally it will be in a GIS data format such as a shapefile. You have a number of different options for working programmatically with GIS data formats. I recommend using the GDAL libraries,
particularly ogr2ogr. Once you've got the boundary data, you can draw it on the map using polyline overlays or create a raster images of the data, say using gdal_rasterize. Or you can convert the data to KML using ogr2ogr, and upload it to Google Fusion Tables using Google Docs and overlay it using a FusionTablesLayer.

google map api v3 - Draw line proceeding X meters north of a give point

User supplies a location (City,State or postal code). I get the lat/long and set a marker. I want to start by drawing a line x meters (distance also supplied by user) North, emanating from the marker.
Eventually, I want to radiate equidistant lines out North, South, East and West of the marker, based on the distance supplied by the user.
It would look like this (going East and west)
-------------------------------X-------------------------------
I'm only going to have the one point; the lat/long of the user's location.
This page should help...
Lat/Long manipulations page

Resources