Title: | Chinese Leaflet Map Relate Operation |
---|---|
Description: | Provides 'sf' data for Chinese provinces and cities, methods for plotting shape maps of Chinese provinces and cities, Convert Coordinates Between Different Systems, and a layer for 'leaflet' with Gaode tiles. It is designed to facilitate geographical data visualization in China. |
Authors: | Damonsoul [aut, cre] |
Maintainer: | Damonsoul <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1 |
Built: | 2024-11-25 15:20:52 UTC |
Source: | CRAN |
This function adds a polygon area to a given map using the specified latitude and longitude coordinates.
addAreaPolygons(map, longitude, latitude, coordinate = "WGS-84")
addAreaPolygons(map, longitude, latitude, coordinate = "WGS-84")
map |
The map object to which the polygons will be added. |
longitude |
A vector of longitudes. |
latitude |
A vector of latitudes. |
coordinate |
A string indicating the coordinate system of the input data. Options are "WGS-84", "GCJ-02", "BD-09". |
The updated map object with added polygons.
library(leaflet) m <- leaflet() %>% addTilesAmap() m <- addAreaPolygons(m, longitude = c(121.0, 122.1, 121.2, 122.15, 121.2), latitude = c(31.1, 31.919, 31.917, 31.15, 31.12), coordinate = "WGS-84" ) m
library(leaflet) m <- leaflet() %>% addTilesAmap() m <- addAreaPolygons(m, longitude = c(121.0, 122.1, 121.2, 122.15, 121.2), latitude = c(31.1, 31.919, 31.917, 31.15, 31.12), coordinate = "WGS-84" ) m
Adds a choropleth map layer for citys with additional customization options.
addCityShape( map, data, adcode = NULL, layerId = NULL, group = NULL, valueProperty = NULL, labelProperty = NULL, labelOptions = leaflet::labelOptions(), popupProps = NULL, popupOptions = leaflet::popupOptions(), scale = c("white", "red"), steps = 5, mode = "q", channelMode = c("rgb", "lab", "hsl", "lch"), padding = NULL, correctLightness = FALSE, bezierInterpolate = FALSE, colors = NULL, stroke = TRUE, color = "#ffffff", weight = 1, opacity = 0.5, fillOpacity = 0.7, dashArray = NULL, smoothFactor = 1, noClip = FALSE, pathOptions = leaflet::pathOptions(), highlightOptions = leaflet::highlightOptions(weight = 2, color = "#000000", fillOpacity = 1, opacity = 1, bringToFront = TRUE, sendToBack = TRUE), legendOptions = NULL, ... )
addCityShape( map, data, adcode = NULL, layerId = NULL, group = NULL, valueProperty = NULL, labelProperty = NULL, labelOptions = leaflet::labelOptions(), popupProps = NULL, popupOptions = leaflet::popupOptions(), scale = c("white", "red"), steps = 5, mode = "q", channelMode = c("rgb", "lab", "hsl", "lch"), padding = NULL, correctLightness = FALSE, bezierInterpolate = FALSE, colors = NULL, stroke = TRUE, color = "#ffffff", weight = 1, opacity = 0.5, fillOpacity = 0.7, dashArray = NULL, smoothFactor = 1, noClip = FALSE, pathOptions = leaflet::pathOptions(), highlightOptions = leaflet::highlightOptions(weight = 2, color = "#000000", fillOpacity = 1, opacity = 1, bringToFront = TRUE, sendToBack = TRUE), legendOptions = NULL, ... )
map |
The leaflet map object to add the layer to. |
data |
A data frame containing the data to be visualized. |
adcode |
China administrative division code |
layerId |
An optional string to identify the layer. |
group |
An optional string for grouping data. |
valueProperty |
The property in the geojson data that corresponds to the value to be mapped. |
labelProperty |
The property in the geojson data that will be used for labels. |
labelOptions |
Options for labels, defaults to leaflet's labelOptions. |
popupProps |
A named vector of properties to display in the popup. |
popupOptions |
Options for popups, defaults to leaflet's popupOptions. |
scale |
A vector of colors to use for the scale of the choropleth map. |
steps |
The number of steps for the color scale. |
mode |
The mode for the color scale, can be "q" for quantile, "e" for equal interval, etc. |
channelMode |
The color channel mode, can be "rgb", "lab", "hsl", or "lch". |
padding |
Optional padding for the choropleth layer. |
correctLightness |
A logical value to correct lightness for color scales. |
bezierInterpolate |
Whether to use bezier interpolation for the lines. |
colors |
An optional vector of colors to override the default color scale. |
stroke |
Whether to draw the stroke along the paths. |
color |
The color for the paths, defaults to white. |
weight |
The weight for the paths. |
opacity |
The opacity for the paths. |
fillOpacity |
The fill opacity for the paths. |
dashArray |
An optional array to create dashed lines. |
smoothFactor |
A factor to smooth the factor for the paths. |
noClip |
Whether to disable clipping of the paths. |
pathOptions |
Additional options for the paths, defaults to leaflet's pathOptions. |
highlightOptions |
Options for highlighting features, defaults to leaflet's highlightOptions. |
legendOptions |
Options for the legend. |
... |
Additional arguments passed to other functions. |
The modified leaflet map object with the added layer.
# use adcode,adcode can be obtained from leafletZH::china_city library(leaflet) library(leaflet.extras) library(leafletZH) library(sf) data <- data.frame(adcode = seq(110101, 110110, 1), value = runif(5)) leaflet() |> leafletZH::addTilesAmap() |> addCityShape( data = data, adcode = "adcode", valueProperty = "value", popupProps = c("value") ) |> setView(lng = 116, lat = 40, zoom = 8)
# use adcode,adcode can be obtained from leafletZH::china_city library(leaflet) library(leaflet.extras) library(leafletZH) library(sf) data <- data.frame(adcode = seq(110101, 110110, 1), value = runif(5)) leaflet() |> leafletZH::addTilesAmap() |> addCityShape( data = data, adcode = "adcode", valueProperty = "value", popupProps = c("value") ) |> setView(lng = 116, lat = 40, zoom = 8)
Adds a choropleth map layer for provinces with additional customization options.
addProvinceShape( map, data, adcode = NULL, provinceName = NULL, layerId = NULL, group = NULL, valueProperty = NULL, labelProperty = NULL, labelOptions = leaflet::labelOptions(), popupProps = NULL, popupOptions = leaflet::popupOptions(), scale = c("white", "red"), steps = 5, mode = "q", channelMode = c("rgb", "lab", "hsl", "lch"), padding = NULL, correctLightness = FALSE, bezierInterpolate = FALSE, colors = NULL, stroke = TRUE, color = "#ffffff", weight = 1, opacity = 0.5, fillOpacity = 0.7, dashArray = NULL, smoothFactor = 1, noClip = FALSE, pathOptions = leaflet::pathOptions(), highlightOptions = leaflet::highlightOptions(weight = 2, color = "#000000", fillOpacity = 1, opacity = 1, bringToFront = TRUE, sendToBack = TRUE), legendOptions = NULL, ... )
addProvinceShape( map, data, adcode = NULL, provinceName = NULL, layerId = NULL, group = NULL, valueProperty = NULL, labelProperty = NULL, labelOptions = leaflet::labelOptions(), popupProps = NULL, popupOptions = leaflet::popupOptions(), scale = c("white", "red"), steps = 5, mode = "q", channelMode = c("rgb", "lab", "hsl", "lch"), padding = NULL, correctLightness = FALSE, bezierInterpolate = FALSE, colors = NULL, stroke = TRUE, color = "#ffffff", weight = 1, opacity = 0.5, fillOpacity = 0.7, dashArray = NULL, smoothFactor = 1, noClip = FALSE, pathOptions = leaflet::pathOptions(), highlightOptions = leaflet::highlightOptions(weight = 2, color = "#000000", fillOpacity = 1, opacity = 1, bringToFront = TRUE, sendToBack = TRUE), legendOptions = NULL, ... )
map |
The leaflet map object to add the layer to. |
data |
A data frame containing the data to be visualized. |
adcode |
China administrative division code |
provinceName |
A string specifying the column name in the data frame that corresponds to the province names. |
layerId |
An optional string to identify the layer. |
group |
An optional string for grouping data. |
valueProperty |
The property in the geojson data that corresponds to the value to be mapped. |
labelProperty |
The property in the geojson data that will be used for labels. |
labelOptions |
Options for labels, defaults to leaflet's labelOptions. |
popupProps |
A named vector of properties to display in the popup. |
popupOptions |
Options for popups, defaults to leaflet's popupOptions. |
scale |
A vector of colors to use for the scale of the choropleth map. |
steps |
The number of steps for the color scale. |
mode |
The mode for the color scale, can be "q" for quantile, "e" for equal interval, etc. |
channelMode |
The color channel mode, can be "rgb", "lab", "hsl", or "lch". |
padding |
Optional padding for the choropleth layer. |
correctLightness |
A logical value to correct lightness for color scales. |
bezierInterpolate |
Whether to use bezier interpolation for the lines. |
colors |
An optional vector of colors to override the default color scale. |
stroke |
Whether to draw the stroke along the paths. |
color |
The color for the paths, defaults to white. |
weight |
The weight for the paths. |
opacity |
The opacity for the paths. |
fillOpacity |
The fill opacity for the paths. |
dashArray |
An optional array to create dashed lines. |
smoothFactor |
A factor to smooth the factor for the paths. |
noClip |
Whether to disable clipping of the paths. |
pathOptions |
Additional options for the paths, defaults to leaflet's pathOptions. |
highlightOptions |
Options for highlighting features, defaults to leaflet's highlightOptions. |
legendOptions |
Options for the legend. |
... |
Additional arguments passed to other functions. |
The modified leaflet map object with the added layer.
# Plot using province name, match using first two words of field library(leaflet) library(leaflet.extras) library(leafletZH) data <- data.frame(name = leafletZH::china_province$name, value = runif(34)) backg <- htmltools::tags$style(".leaflet-container { background: #000; }") leaflet() |> addProvinceShape( data = data, provinceName = "name", valueProperty = "value", popupProps = c("value") ) |> setView(lng = 110, lat = 40, zoom = 4) |> htmlwidgets::prependContent(backg) # Use adcode to match, adcode can be obtained in leafletZH::china_province library(leaflet) library(leaflet.extras) library(leafletZH) library(sf) data <- data.frame(adcode = seq(110000, 150000, 10000), value = runif(5)) leaflet() |> leafletZH::addTilesAmap() |> addProvinceShape( data = data, adcode = "adcode", valueProperty = "value", popupProps = c("value") ) |> setView(lng = 110, lat = 40, zoom = 4)
# Plot using province name, match using first two words of field library(leaflet) library(leaflet.extras) library(leafletZH) data <- data.frame(name = leafletZH::china_province$name, value = runif(34)) backg <- htmltools::tags$style(".leaflet-container { background: #000; }") leaflet() |> addProvinceShape( data = data, provinceName = "name", valueProperty = "value", popupProps = c("value") ) |> setView(lng = 110, lat = 40, zoom = 4) |> htmlwidgets::prependContent(backg) # Use adcode to match, adcode can be obtained in leafletZH::china_province library(leaflet) library(leaflet.extras) library(leafletZH) library(sf) data <- data.frame(adcode = seq(110000, 150000, 10000), value = runif(5)) leaflet() |> leafletZH::addTilesAmap() |> addProvinceShape( data = data, adcode = "adcode", valueProperty = "value", popupProps = c("value") ) |> setView(lng = 110, lat = 40, zoom = 4)
This function adds a tile layer from Amap to a leaflet map object.
addTilesAmap( map, attribution = "© <a href=\"http://amap.com\">amap.com</a >", ... )
addTilesAmap( map, attribution = "© <a href=\"http://amap.com\">amap.com</a >", ... )
map |
A leaflet map object to which the tile layer will be added. |
attribution |
A string containing the attribution text to be displayed on the map. It defaults to "© <a href=\"http://amap.com\">amap.com</a>". |
... |
Additional arguments to be passed to the 'leaflet::addTiles' function. |
The leaflet map object with the added tile layer.
library(leaflet) leaflet() %>% addTilesAmap() %>% setView( lng = 120.33739, lat = 31.13533, zoom = 3 )
library(leaflet) leaflet() %>% addTilesAmap() %>% setView( lng = 120.33739, lat = 31.13533, zoom = 3 )
This function takes in latitude and longitude vectors and calculates the area of the polygon defined by those points. It can handle different coordinate systems such as WGS-84, GCJ-02, and BD-09.
areaCalculator(longitude, latitude, coordinate = "WGS-84", chull = TRUE)
areaCalculator(longitude, latitude, coordinate = "WGS-84", chull = TRUE)
longitude |
A numeric vector of longitude points. |
latitude |
A numeric vector of latitude points. |
coordinate |
A string indicating the coordinate system of the input points, can be "WGS-84", "GCJ-02", or "BD-09". Default is "WGS-84". |
chull |
A logical value indicating whether to use the convex hull of the points. Default is TRUE. |
A numeric value representing the area of the polygon in square meters.
area <- areaCalculator( longitude = c(121.0, 122.1, 121.2, 122.15, 121.2), latitude = c(31.1, 31.919, 31.917, 31.15, 31.12), coordinate = "WGS-84" )
area <- areaCalculator( longitude = c(121.0, 122.1, 121.2, 122.15, 121.2), latitude = c(31.1, 31.919, 31.917, 31.15, 31.12), coordinate = "WGS-84" )
This dataset contains spatial (sf) data for city in China, with various attributes specific to each district.
china_city
china_city
An object of class sf
(inherits from data.frame
) with 476 rows and 10 columns.
http://datav.aliyun.com/tools/atlas/
The name of the district
The administrative code for the district, a unique identifier (e.g., "110101")
The number of lower-level administrative divisions within the district (usually 0 for districts)
The administrative level of the area, which is "district" for all entries in this dataset
An index representing the sub-features within the district
The geographical centroid of the district, represented as a string of coordinates
The center point of the district, also represented as a string of coordinates
A JSON string representing the parent administrative entity, usually the province-level data
A JSON array of administrative codes that represent the full administrative hierarchy leading to the district
Spatial geometry of the district, stored as an sf object in MULTIPOLYGON format
This dataset contains spatial (sf) data for provinces in China, including various attributes related to each province.
china_province
china_province
An object of class sf
(inherits from data.frame
) with 34 rows and 10 columns.
http://datav.aliyun.com/tools/atlas/
The name of the province
The administrative code for the province, a unique identifier (e.g., "110000")
The number of administrative divisions (e.g., counties) within the province
The administrative level of the area, which is generally "province" for the entries in this dataset
An index representing the sub-features within the province
The geographical centroid of the province, represented as a string of coordinates
The center point of the province, also represented as a string of coordinates
A JSON string representing the parent administrative entity, usually the country-level data
A JSON array of administrative codes that represent the administrative hierarchy leading to the province
Spatial geometry of the province, stored as an sf object in MULTIPOLYGON format
This function converts geographical coordinates between different coordinate systems, including WGS-84, GCJ-02 (Chinese National Standard), and BD-09 (Baidu Map).
convertCoordinates(latitude, longitude, from, to)
convertCoordinates(latitude, longitude, from, to)
latitude |
Numeric value representing the latitude of the point to convert. |
longitude |
Numeric value representing the longitude of the point to convert. |
from |
A character string indicating the source coordinate system. Options include "WGS-84", "GCJ-02", and "BD-09". |
to |
A character string indicating the target coordinate system. Options include "WGS-84", "GCJ-02", and "BD-09". |
A numeric vector of length 2, containing the converted latitude and longitude.
# Convert WGS-84 coordinates to GCJ-02 convertCoordinates(39.90105, 116.42079, from = "WGS-84", to = "GCJ-02") # Convert GCJ-02 coordinates to BD-09 convertCoordinates(39.90245, 116.42702, "GCJ-02", "WGS-84") # Convert WGS-84 coordinates to BD-09 convertCoordinates(39.90105, 116.42079, "WGS-84", "BD-09")
# Convert WGS-84 coordinates to GCJ-02 convertCoordinates(39.90105, 116.42079, from = "WGS-84", to = "GCJ-02") # Convert GCJ-02 coordinates to BD-09 convertCoordinates(39.90245, 116.42702, "GCJ-02", "WGS-84") # Convert WGS-84 coordinates to BD-09 convertCoordinates(39.90105, 116.42079, "WGS-84", "BD-09")