r - plotting lines with mapview - automatically connects inaccurately - r

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
:

Related

R leaflet.minicharts change addflows direction on map

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?

Lost data within a spatial polygon

Hopefully the following makes sense and apologies if not!
I have a dataset of GPS locations (of various species footprints), and am measuring the distance from where each point was found to the boundary of a national park in R. Im doing this with a series of environmental factors, (roads/villages/lakes etc), and for all other enviro variables (and kml files) Ive had no problems, however when I run my park boundary data, (using a kml file read in as a spatial polygon of the national park), I keep getting negative values for all the GPS points that occur within the park boundary? (So anything within the polygon essentially). The results output I am getting shows the correct measurements from GPS points to the boundary that occur on the OUTSIDE of the boundary, (or polygon), but anything inside the park/polygon outputs as a zero value. Ive tried to reproject the polygon as just an outline and tried removing the 'fill' etc, along with a few other tricks Ive found, but no luck so far?
Am I correct in assuming the data is just not there and that I need to recreate the boarder of the park some other way? Or is it more an issue with how Im asking r to calculate the distance measurements?
Below is an example of the code I am using
KSNP_Poly <- readOGR("KSNPboundaryexport.kml")
Points <- read.csv("AllPoints.csv")
sptsPoints = SpatialPoints(Points)
plot(KSNP_Poly)
plot(sptsPoints)
apply(gDistance(sptsPoints,KSNP_Poly,byid=TRUE),2,min)
KSNPResults <- apply(gDistance(sptsPoints,KSNP_Poly,byid=TRUE),2,min)
Hope this made sense and any advice greatly appreciated!
Thanks!
Kass

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?

Feature engineering of X,Y coordinates in neighborhoods of San Francisco

I am participating in a starter Kaggle competition(Crimes in San Francisco) in which I want to predict the category of a crime using a bunch of predictor variables including X and Y coordinates of a crime. As I doubt of the predictive power of the coordinates, I want to transform these variables to something more relevant to the crime category.
So I am thinking that if I had the neighbourhood of San Francisco in which the crime took place, it would be more informative than the actual coordinates of the crime. I can find the neighbourhoods online but of course I cant use the borders of each neighbour to classify the corresponding crime because their shapes are not rectangular or anything like that.
Does anyone have any idea about how I could solve this one?
Thanks guys
Well that's interesting AntoniosK and it's getting close to what I want to accomplish. The problem is that the information " south-east and 2km from city center" can lead to more than one neighborhoods.
I am still thinking that the partition of the city in neighborhoods is valuable because the socio-economic and structural differences between them ( there is a reason why the neighborhoods of each city are separated as such, right?) can lead to a higher probability for a certain category crime and a lower one for another.
That said, your idea made me thinking of using the south-east etc mapping and then use the angle of the segment(point to city center) with x axis to map the point to appropriate neighborhood. I am on it right now. Thanks
After some time on the problem I found that the procedure I want to perform is titled " reverse geocoding". It also turns out that there are some api's to solve this. The best according to my opinion is revgeocode() function contained in ggmap package(google's edition). This one though has a query limit per day(2500 queries) unless you pay for extra.
The one that I turned to though is geonames package and GNneighbourhood function that turns coordinates to neighbours. It is free, though I have experienced some errors(keep in mind that this one is only for US and Canada cities)
revgeocode function-ggmap package
Gnneighbourhood-geonames package

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.

Resources