### Install TransBigData with conda-forge Source: https://github.com/ni1o1/transbigdata/blob/main/README.md Installs the TransBigData library using conda-forge. This method automatically resolves and installs all necessary dependencies. ```shell conda install -c conda-forge transbigdata ``` -------------------------------- ### Install TransBigData with pip Source: https://github.com/ni1o1/transbigdata/blob/main/README.md Installs the TransBigData library using pip. Ensure that the geopandas package is already installed as a prerequisite. ```shell pip install transbigdata ``` -------------------------------- ### Visualize Gridded Data with Basemap and Scale Source: https://github.com/ni1o1/transbigdata/blob/main/README.md Provides a comprehensive example of visualizing gridded data on a basemap using Matplotlib. It includes loading a basemap with `tbd.plot_map`, defining a colorbar, plotting the aggregated data, and adding a compass and scale with `tbd.plotscale` for professional map presentation. ```python import matplotlib.pyplot as plt fig =plt.figure(1,(8,8),dpi=300) ax =plt.subplot(111) plt.sca(ax) #Load basemap tbd.plot_map(plt,bounds,zoom = 11,style = 4) #Define colorbar cax = plt.axes([0.05, 0.33, 0.02, 0.3]) plt.title('Data count') plt.sca(ax) #Plot the data grid_agg.plot(column = 'VehicleNum',cmap = 'autumn_r',ax = ax,cax = cax,legend = True) #Add scale tbd.plotscale(ax,bounds = bounds,textsize = 10,compasssize = 1,accuracy = 2000,rect = [0.06,0.03],zorder = 10) plt.axis('off') plt.xlim(bounds[0],bounds[2]) plt.ylim(bounds[1],bounds[3]) plt.show() ``` -------------------------------- ### Cite TransBigData in Research Source: https://github.com/ni1o1/transbigdata/blob/main/README.md Provides the recommended BibTeX entry for citing the TransBigData package in academic publications. Proper citation ensures attribution to the authors and the software when used in research. ```bibtex @article{Yu2022, doi = {10.21105/joss.04021}, url = {https://doi.org/10.21105/joss.04021}, year = {2022}, publisher = {The Open Journal}, volume = {7}, number = {71}, pages = {4021}, author = {Qing Yu and Jian Yuan}, title = {TransBigData: A Python package for transportation spatio-temporal big data processing, analysis and visualization}, journal = {Journal of Open Source Software} } ``` -------------------------------- ### Install TransBigData Python Package Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/index.rst Instructions to install the TransBigData library using pip, after ensuring geopandas is installed as a prerequisite. ```bash pip install -U transbigdata ``` -------------------------------- ### Map and Aggregate Data on Hexagonal/Triangular Grids Source: https://github.com/ni1o1/transbigdata/blob/main/README.md Demonstrates mapping GPS data to hexagonal or triangular grids, which require three columns for unique identification. It then shows how to aggregate data by these non-rectangular grid cells, generate their geometries, and prepare them for visualization as a GeoDataFrame. ```python #Triangle and Hexagon grids requires three columns to store ID data['loncol_1'],data['loncol_2'],data['loncol_3'] = tbd.GPS_to_grid(data['lon'],data['lat'],params) #Aggregate data into grids grid_agg = data.groupby(['loncol_1','loncol_2','loncol_3'])['VehicleNum'].count().reset_index() #Generate grid geometry grid_agg['geometry'] = tbd.grid_to_polygon([grid_agg['loncol_1'],grid_agg['loncol_2'],grid_agg['loncol_3']],params) #Change the type into GeoDataFrame import geopandas as gpd grid_agg = gpd.GeoDataFrame(grid_agg) #Plot the grids grid_agg.plot(column = 'VehicleNum',cmap = 'autumn_r') ``` -------------------------------- ### Install TransBigData Python Package Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/index.rst.txt This command demonstrates how to install or upgrade the TransBigData library using pip. It is recommended to have GeoPandas installed beforehand as TransBigData builds upon it. ```python pip install -U transbigdata ``` -------------------------------- ### Generate Rectangular Grid Parameters with TransBigData Source: https://github.com/ni1o1/transbigdata/blob/main/README.md Illustrates how to obtain gridding parameters for rectangular grids from a defined study area using `tbd.area_to_params`. These parameters define the grid's coordinate system, including its origin, cell size, and angle, which are essential for subsequent data mapping and aggregation. ```python #Obtain the gridding parameters params = tbd.area_to_params(bounds,accuracy = 1000) params ``` -------------------------------- ### Configure Hexagonal/Triangular Grids with Rotation Source: https://github.com/ni1o1/transbigdata/blob/main/README.md Explains how to modify the gridding parameters to utilize hexagonal or triangular grid systems instead of rectangular ones. It also demonstrates how to apply a rotation angle to the grid, offering flexibility in spatial tessellation for different analytical needs. ```python #set to the hexagon grids params['method'] = 'hexa' #or set as triangle grids: params['method'] = 'tri' #set a rotation angle (degree) params['theta'] = 5 ``` -------------------------------- ### Build HTML Documentation with Sphinx Source: https://github.com/ni1o1/transbigdata/blob/main/docs/README.md This snippet provides commands to clean the existing 'build' directory, ensuring a fresh start. It then generates the complete HTML documentation for the project using Sphinx from the 'source' directory. ```cmd # 移除build中原有文件 rm -r build # 正式build sphinx-build -b html ./source build ``` -------------------------------- ### Install TransBigData using pip Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/getting_started.rst Installs or upgrades the TransBigData library using Python's pip package manager. Users must ensure geopandas is installed separately before running this command. ```Shell pip install -U transbigdata ``` -------------------------------- ### Install Kepler.gl for TransBigData Visualization Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/example-taxi/example-taxi.rst.txt This command installs the `keplergl` Python package, which is a prerequisite for using the advanced visualization features provided by the `TransBigData` library, enabling interactive mapping capabilities. ```bash pip install keplergl ``` -------------------------------- ### Install Kepler.gl for Jupyter Visualization Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/visualization.html Instructions for installing the `keplergl` Python package and enabling necessary Jupyter plugins (`jupyter-js-widgets`, `keplergl-jupyter`) to display interactive visualizations within Jupyter Notebooks. ```Python pip install keplergl ``` -------------------------------- ### Configure Basemap Image Storage Path Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/plot_map.rst This snippet shows how to specify a local directory for `transbigdata` to save downloaded map tiles. This improves performance by loading cached maps for subsequent displays. Examples for both Linux/macOS and Windows paths are provided. ```Python # Set your map basemap storage path # On linux or mac, the path is written like this. # Note that there is a backslash at the end tbd.set_imgsavepath(r'/Users/xxxx/xxxx/') # On windows, the path is written like this. # Finally, pay attention to two slashes to prevent escape tbd.set_imgsavepath(r'E:\pythonscript\xxx\\') ``` -------------------------------- ### Install TransBigData using conda Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/getting_started.rst Installs the TransBigData library via the conda package manager from the conda-forge channel. This method automatically handles and resolves all necessary dependencies. ```Shell conda install -c conda-forge transbigdata ``` -------------------------------- ### Read Taxi GPS Data with TransBigData and Pandas Source: https://github.com/ni1o1/transbigdata/blob/main/README.md Demonstrates how to read a sample CSV file containing taxi GPS data into a pandas DataFrame. It assigns appropriate column names for further processing with the TransBigData library. ```python import transbigdata as tbd import pandas as pd #Read taxi gps data data = pd.read_csv('TaxiData-Sample.csv',header = None) data.columns = ['VehicleNum','time','lon','lat','OpenStatus','Speed'] data ``` -------------------------------- ### Example Usage of transbigdata.plotscale Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/plot_map.html An example demonstrating how to call the `transbigdata.plotscale` function with specific parameters to customize the appearance and position of the compass and scale on the map. ```Python tbd.plotscale(ax,bounds = bounds,textsize = 10,compasssize = 1,accuracy = 2000,rect = [0.06,0.03]) ``` -------------------------------- ### Import TransBigData in Python Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/getting_started.rst Imports the TransBigData library into a Python script or interactive session, aliasing it as 'tbd' for convenient access to its functions and classes. ```Python import transbigdata as tbd ``` -------------------------------- ### Aggregate and Visualize Data on Rectangular Grids Source: https://github.com/ni1o1/transbigdata/blob/main/README.md Details the process of aggregating data by rectangular grid cells, generating geometric representations of these grids using `tbd.grid_to_polygon`, and converting the result into a GeoDataFrame. This enables spatial visualization of aggregated data counts on a map. ```python #Aggregate data into grids grid_agg = data.groupby(['LONCOL','LATCOL'])['VehicleNum'].count().reset_index() #Generate grid geometry grid_agg['geometry'] = tbd.grid_to_polygon([grid_agg['LONCOL'],grid_agg['LATCOL']],params) #Change the type into GeoDataFrame import geopandas as gpd grid_agg = gpd.GeoDataFrame(grid_agg) #Plot the grids grid_agg.plot(column = 'VehicleNum',cmap = 'autumn_r') ``` -------------------------------- ### Clean Out-of-Bounds Data with TransBigData Source: https://github.com/ni1o1/transbigdata/blob/main/README.md Demonstrates how to define a study area using geographical bounds and utilize the `tbd.clean_outofbounds` method to remove data points that fall outside these specified boundaries. This is a fundamental step for focusing analysis on relevant regions. ```python #Define the study area bounds = [113.75, 22.4, 114.62, 22.86] #Delete the data out of the study area data = tbd.clean_outofbounds(data,bounds = bounds,col = ['lon','lat']) ``` -------------------------------- ### Map GPS Data to Rectangular Grids Source: https://github.com/ni1o1/transbigdata/blob/main/README.md Shows how to map GPS coordinates (longitude and latitude) to their corresponding rectangular grid cells using the `tbd.GPS_to_grid` method. This process generates `LONCOL` and `LATCOL` columns in the dataset, which together uniquely identify each grid cell. ```python #Map the GPS data to grids data['LONCOL'],data['LATCOL'] = tbd.GPS_to_grid(data['lon'],data['lat'],params) ``` -------------------------------- ### Python: Generate Sample Data and Plot Distribution Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/gisprocess.html This Python example demonstrates how to generate synthetic 2D point data using NumPy and Pandas, then visualize its distribution using Matplotlib. It sets up a basic scatter plot with coordinate axes and limits for clear visualization. ```Python import pandas as pd import transbigdata as tbd import numpy as np #生成测试用数据 data = np.random.uniform(1,10,(100,2)) data[:,1:] = 0.5*data[:,0:1]+np.random.uniform(-2,2,(100,1)) data = pd.DataFrame(data,columns = ['x','y']) #绘制数据分布 import matplotlib.pyplot as plt plt.figure(1,(5,5)) #绘制数据点 plt.scatter(data['x'],data['y'],s = 0.5) #绘制坐标轴 plt.plot([-10,10],[0,0],c = 'k') plt.plot([0,0],[-10,10],c = 'k') plt.xlim(-15,15) plt.ylim(-15,15) plt.show() ``` -------------------------------- ### Python Example: Using transbigdata.data_summary Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/quality.rst.txt Illustrates the practical application of `transbigdata.data_summary` using a sample taxi dataset. The example demonstrates how to load CSV data into a Pandas DataFrame, assign column names, convert the 'Time' column to datetime objects, and then call `data_summary` to analyze the data, specifically requesting the display of sampling duration information. ```python import transbigdata as tbd import pandas as pd #读取数据 data = pd.read_csv('TaxiData-Sample.csv',header = None) data.columns = ['Vehicleid','Time','Lng','Lat','OpenStatus','Speed'] data['Time'] = pd.to_datetime(data['Time']) #轨迹增密前的采样间隔 tbd.data_summary(data,col = ['Vehicleid','Time','Lng','Lat'],show_sample_duration=True) ``` -------------------------------- ### Enable Sphinx Read the Docs Theme Navigation Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/traj.html This JavaScript snippet utilizes jQuery to ensure that the navigation functionality provided by the Sphinx Read the Docs theme is enabled once the document's DOM is fully loaded. This is a standard practice for interactive elements in web pages generated by Sphinx. ```javascript jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); ``` -------------------------------- ### Python Example: Visualize Origin-Destination (OD) Data Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/visualization.html Demonstrates how to use `transbigdata.visualization_od` to visualize Origin-Destination (OD) flows from taxi GPS data. It loads sample data, extracts OD pairs using `tbd.taxigps_to_od`, and then visualizes the resulting OD data. ```Python import transbigdata as tbd import pandas as pd #读取数据 data = pd.read_csv('TaxiData-Sample.csv',header = None) data.columns = ['VehicleNum','Time','Lng','Lat','OpenStatus','Speed'] #提取OD oddata = tbd.taxigps_to_od(data,col = ['VehicleNum','Time','Lng','Lat','OpenStatus']) #OD可视化 tbd.visualization_od(oddata) ``` -------------------------------- ### Python Example: Visualize Data Point Distribution Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/visualization.html Demonstrates how to use `transbigdata.visualization_data` to visualize taxi GPS data points. It loads sample CSV data, assigns column names, and then calls the visualization function with specified longitude and latitude columns and aggregation accuracy. ```Python import transbigdata as tbd import pandas as pd #读取数据 data = pd.read_csv('TaxiData-Sample.csv',header = None) data.columns = ['VehicleNum','Time','Lng','Lat','OpenStatus','Speed'] #可视化数据点分布 tbd.visualization_data(data,col = ['Lng','Lat'],accuracy=300) ``` -------------------------------- ### Python Example: Visualize Trajectory Data Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/visualization.html Illustrates how to use `transbigdata.visualization_trip` to visualize taxi GPS trajectory data. It loads sample data, assigns column names, and then visualizes the trajectories using specified columns for location, vehicle ID, and time. ```Python import transbigdata as tbd import pandas as pd #读取数据 data = pd.read_csv('TaxiData-Sample.csv',header = None) data.columns = ['VehicleNum','Time','Lng','Lat','OpenStatus','Speed'] #轨迹数据可视化 tbd.visualization_trip(data,col = ['Lng', 'Lat', 'VehicleNum', 'Time']) ``` -------------------------------- ### Generate and Visualize Sample Data for Confidence Ellipse Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/gisprocess.rst.txt This Python snippet demonstrates how to generate synthetic 2D point data using `numpy` and `pandas`, then visualize its distribution using `matplotlib`. This setup is typical for preparing data for confidence ellipse analysis. ```python import pandas as pd import transbigdata as tbd import numpy as np #生成测试用数据 data = np.random.uniform(1,10,(100,2)) data[:,1:] = 0.5*data[:,0:1]+np.random.uniform(-2,2,(100,1)) data = pd.DataFrame(data,columns = ['x','y']) #绘制数据分布 import matplotlib.pyplot as plt plt.figure(1,(5,5)) #绘制数据点 plt.scatter(data['x'],data['y'],s = 0.5) #绘制坐标轴 plt.plot([-10,10],[0,0],c = 'k') plt.plot([0,0],[-10,10],c = 'k') plt.xlim(-15,15) plt.ylim(-15,15) plt.show() ``` -------------------------------- ### Visualize Initial Community Grouping of Grid Nodes Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/example-bikesharing/example-bikesharing.html This code snippet visualizes the initial community grouping of grid nodes. It plots the 'group' field of the GeoDataFrame, where different groups are represented by different colors, to quickly check if the community detection was successful and to get a preliminary visual understanding of the spatial distribution. ```python node.plot('group') ``` -------------------------------- ### Perform Community Detection using Fast Unfolding Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/example-bikesharing/example-bikesharing.html This snippet applies the Fast Unfolding community detection algorithm to the constructed graph. It uses `igraph`'s `g.community_multilevel` method, passing the `edge_weights` to guide the algorithm. The `return_levels` parameter is set to `False` to obtain only the final community assignment result. ```python g_clustered = g.community_multilevel(weights = edge_weights, return_levels=False) ``` -------------------------------- ### Prepare Node Information for Network Construction Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/example-bikesharing/example-bikesharing.html This code prepares node information for network construction from OD data. It combines longitude and latitude columns from the OD GeoDataFrame (`od_gdf`) to create unique string identifiers for start ('S') and end ('E') points. It then extracts all unique nodes, converts them into a Pandas DataFrame, and assigns a new sequential integer ID to each node. ```python od_gdf['S'] = od_gdf['SLONCOL'].astype(str) + ',' + od_gdf['SLATCOL'].astype(str) od_gdf['E'] = od_gdf['ELONCOL'].astype(str) + ',' + od_gdf['ELATCOL'].astype(str) node = set(od_gdf['S'])|set(od_gdf['E']) node = pd.DataFrame(node) node['id'] = range(len(node)) node ``` -------------------------------- ### Extract Origin-Destination (OD) from Taxi GPS Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/index.rst.txt This example showcases the use of `tbd.taxigps_to_od` to extract origin-destination pairs from the prepared taxi GPS data. The method requires a list of column names corresponding to vehicle ID, timestamp, start longitude, start latitude, and open status. ```python # Extract OD data from GPS using TransBigData oddata = tbd.taxigps_to_od(data, col=['VehicleNum', 'time', 'slon', 'slat', 'OpenStatus']) ``` -------------------------------- ### Example: Add Scale Bar and North Arrow to Plot Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/plot_map.rst Demonstrates a basic usage of the `tbd.plotscale()` function to add a scale bar and compass to an existing Matplotlib axes. It shows common parameters like bounds, text size, compass size, and accuracy. ```Python tbd.plotscale(ax,bounds = bounds,textsize = 10,compasssize = 1,accuracy = 2000,rect = [0.06,0.03]) ``` -------------------------------- ### Plot Map Basemap with Scale Bar and North Arrow Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/plot_map.rst This comprehensive example demonstrates how to define a display range, initialize a Matplotlib figure, add a Mapbox basemap using `tbd.plot_map()`, and then overlay a scale bar and north arrow with `tbd.plotscale()`. It also shows how to set plot limits and hide axes. ```Python bounds = [113.6,22.4,114.8,22.9] # Plot Frame import matplotlib.pyplot as plt fig =plt.figure(1,(8,8),dpi=250) ax =plt.subplot(111) plt.sca(ax) # Add map basemap tbd.plot_map(plt,bounds,zoom = 11,style = 4) # Add scale bar and north arrow tbd.plotscale(ax,bounds = bounds,textsize = 10,compasssize = 1,accuracy = 2000,rect = [0.06,0.03],zorder = 10) plt.axis('off') plt.xlim(bounds[0],bounds[2]) plt.ylim(bounds[1],bounds[3]) plt.show() ``` -------------------------------- ### Initialize TransBigData and Load Sample Data Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/grids.rst This snippet demonstrates how to import necessary libraries like `transbigdata`, `pandas`, and `geopandas`. It then loads sample taxi data from a CSV file into a pandas DataFrame and assigns meaningful column names for subsequent data processing. ```Python import transbigdata as tbd import pandas as pd import geopandas as gpd #read data data = pd.read_csv('TaxiData-Sample.csv',header = None) data.columns = ['VehicleNum','time','slon','slat','OpenStatus','Speed'] ``` -------------------------------- ### Model Subway Network Topology with NetworkX Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/gallery/Example 7-Modeling for subway network topology.ipynb This code prepares the subway line data by assigning operational speed and stop time attributes. It then imports NetworkX and uses `tbd.metro_network` to construct a topological graph `G` of the subway system, incorporating transfer times. The graph is then drawn, providing a visual representation of the network structure for subsequent pathfinding and analysis. ```python line['speed'] = 55 #operation speed 55km/h line['stoptime'] = 0.5 #stop time at each stations 30s import networkx as nx G = tbd.metro_network(line,stop, transfertime=5) nx.draw(G,node_size=20) ``` -------------------------------- ### Importing Core Libraries for TransBigData Bus GPS Processing Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/example-busgps/example-busgps.html This snippet imports the essential Python libraries required for bus GPS data processing: 'transbigdata' for specialized spatial functions, 'pandas' for data manipulation and analysis, and 'geopandas' for handling geospatial data. ```python import transbigdata as tbd import pandas as pd import geopandas as gpd ``` -------------------------------- ### Enable Sphinx ReadTheDocs Theme Navigation Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/Example-pNEUMA/Example-pNEUMA.html This JavaScript snippet, executed via jQuery's document ready function, enables the navigation features provided by the Sphinx ReadTheDocs theme. It ensures that the sidebar navigation is interactive and functional. ```javascript jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); ``` -------------------------------- ### transbigdata.busgps_arriveinfo() API Reference Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/genindex.html API documentation for the `transbigdata.busgps_arriveinfo()` function, a built-in function from the `transbigdata` library for extracting arrival information from bus GPS data. ```APIDOC transbigdata.busgps_arriveinfo() ``` -------------------------------- ### Load Taxi Data and Assign Column Names (Python) Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/grids.rst.txt This Python snippet demonstrates how to load taxi data from a CSV file named 'TaxiData-Sample.csv' into a pandas DataFrame. It then assigns descriptive column names such as 'VehicleNum', 'time', 'slon' (start longitude), 'slat' (start latitude), 'OpenStatus', and 'Speed' for easier data manipulation and analysis. ```Python data = pd.read_csv('TaxiData-Sample.csv',header = None) data.columns = ['VehicleNum','time','slon','slat','OpenStatus','Speed'] ``` -------------------------------- ### transbigdata.split_subwayline(line,stop) Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/metroline.rst.txt 用公交/地铁站点对公交/地铁线进行切分,得到断面 (Splits bus/subway lines using bus/subway stops to get sections). ```APIDOC transbigdata.split_subwayline(line,stop) line: GeoDataFrame 公交/地铁线路 stop: GeoDataFrame 公交/地铁站点 Returns: metro_line_splited: GeoDataFrame 生成的断面线型 ``` -------------------------------- ### Download Subway Line and Stop Data with TransBigData Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/gallery/Example 7-Modeling for subway network topology.ipynb This code imports essential data manipulation and geospatial libraries (pandas, numpy, geopandas) along with TransBigData. It then uses `tbd.getbusdata` to download geographic data for specified subway lines and stops in a given city, returning them as GeoDataFrames. ```python import pandas as pd import numpy as np import geopandas as gpd import transbigdata as tbd line,stop = tbd.getbusdata('厦门',['1号线','2号线','3号线']) ``` -------------------------------- ### Constructing a Graph Network using Python igraph Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/example-bikesharing/example-bikesharing.rst.txt This code demonstrates how to build a graph network using the `igraph` library. It initializes an empty graph, adds vertices based on the number of unique nodes, adds edges using the 'S_id' and 'E_id' columns from the `edge` DataFrame, and then assigns 'count' values as weights to each edge. ```Python import igraph #创建网络 g = igraph.Graph() #在网络中添加节点。 g.add_vertices(len(node)) #在网络中添加边。 g.add_edges(edge[['S_id','E_id']].values) #提取边的权重。 edge_weights = edge[['count']].values #给边添加权重。 for i in range(len(edge_weights)): g.es[i]['weight'] = edge_weights[i] ``` -------------------------------- ### API Reference: transbigdata.plotscale Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/plot_map.rst Documentation for the `plotscale` function in `transbigdata`, which adds a scale bar and north arrow to a Matplotlib plot. It requires the axes object, geographic bounds, and various styling parameters. ```APIDOC transbigdata.plotscale ``` -------------------------------- ### Aggregate Origin-Destination (OD) Data to a Grid System Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/example-bikesharing/example-bikesharing.html This snippet prepares the OD data for network analysis by aggregating it into a uniform grid. It first defines the geographical bounds of the study area and calculates grid parameters for a 500x500 meter grid using `transbigdata.grid_params`. Finally, `transbigdata.odagg_grid` is used to aggregate the individual OD trips into these predefined grid cells, creating a spatially aggregated OD dataset. ```python bounds = (120.85, 30.67, 122.24, 31.87) params = tbd.grid_params(bounds,accuracy = 500) od_gdf = tbd.odagg_grid(move_data, params, col=['slon', 'slat', 'elon', 'elat']) ``` -------------------------------- ### Plot Map with Custom Mapbox Style URL Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/plot_map.rst This snippet illustrates how to use a custom Mapbox style URL with `tbd.plot_map()` instead of a predefined style number. This allows for greater flexibility in map appearance. ```Python tbd.plot_map(plt,bounds,zoom = 11,style = 'mapbox://styles/ni1o1/cl38pljx0006r14qp7ioy7gcc') ``` -------------------------------- ### Import Libraries and Load Taxi GPS Data Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/example-taxi/example-taxi.rst.txt This snippet imports necessary Python libraries including `transbigdata`, `pandas`, and `geopandas`. It then loads sample taxi GPS data from a CSV file, assigns appropriate column names, and displays the initial DataFrame structure. ```Python import transbigdata as tbd import pandas as pd import geopandas as gpd #读取数据 data = pd.read_csv('TaxiData-Sample.csv',header = None) data.columns = ['VehicleNum','Time','Lng','Lat','OpenStatus','Speed'] data ``` -------------------------------- ### API Reference: transbigdata.plot_map Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/plot_map.rst Documentation for the `plot_map` function within the `transbigdata` library, used for adding a basemap to a Matplotlib plot. It takes the plot object, geographic bounds, zoom level, and style as parameters. ```APIDOC transbigdata.plot_map ``` -------------------------------- ### Set Mapbox Access Token for TransBigData Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/plot_map.rst Before using `transbigdata` for plotting maps, a Mapbox access token is required. This code snippet demonstrates how to set the token using `tbd.set_mapboxtoken()`. The token only needs to be set once. ```Python import transbigdata as tbd #Set your mapboxtoken with the following code tbd.set_mapboxtoken('pk.eyxxxxxxxxxx.xxxxxxxxx') # The token you applied for must be set in it. # Copying this line of code directly is invalid ``` -------------------------------- ### Calculate One-Way Travel Time for Bus Routes Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/example-busgps/example-busgps.rst.txt Calculates the one-way travel time for bus routes between specified start and end stops using the `transbigdata` library. It takes arrival information and stop names as input to determine the duration for each vehicle. ```Python onewaytime = tbd.busgps_onewaytime(arriveinfo, start = '延安东路外滩', end = '申昆路枢纽站',col = ['VehicleId','stopname']) ``` -------------------------------- ### transbigdata.grid_params_best() API Reference Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/genindex.html API documentation for the `transbigdata.grid_params_best()` function, a built-in function from the `transbigdata` library for determining optimal grid parameters. ```APIDOC transbigdata.grid_params_best() ``` -------------------------------- ### Get Bus Data (transbigdata.getbusdata) Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/getbusdata.rst.txt This function retrieves bus route geometries and bus stop locations for a specified city and keywords. It takes the city name and a list of keywords (line names) as input and returns GeoDataFrames for the bus lines and stops. ```APIDOC transbigdata.getbusdata(city: str, keywords: List) Parameters: city (str): 城市 (City) keywords (List): 关键词,线路名称 (Keywords, line names) Returns: data (GeoDataFrame): 生成的公交线路 (Generated bus lines) stop (GeoDataFrame): 生成的公交站点 (Generated bus stops) ``` -------------------------------- ### API Documentation for transbigdata.polyon_exterior Function Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/api/transbigdata.polyon_exterior.rst Detailed API reference for the `polyon_exterior` function, including its module and a placeholder for its signature, parameters, and return values as typically generated by Sphinx's `autofunction` directive. ```APIDOC Function: polyon_exterior Module: transbigdata Description: This function is part of the 'transbigdata' library. Signature: polyon_exterior(...) Parameters: (Details to be automatically generated by Sphinx) Returns: (Details to be automatically generated by Sphinx) ``` -------------------------------- ### Load Taxi GPS Data with Pandas and TransBigData Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/index.rst Demonstrates how to import TransBigData and Pandas, then load a sample taxi GPS dataset from a CSV file, assigning column names for further processing. ```python import transbigdata as tbd import pandas as pd data = pd.read_csv('TaxiData-Sample.csv',header = None) data.columns = ['VehicleNum','time','slon','slat','OpenStatus','Speed'] data ``` -------------------------------- ### Update Sphinx Internationalization (i18n) Files Source: https://github.com/ni1o1/transbigdata/blob/main/docs/README.md This snippet outlines the process for internationalization. It first generates gettext message catalogs from the source. Subsequently, it updates the Chinese (zh_CN) translation files using `sphinx-intl` based on these catalogs. ```cmd sphinx-build -b gettext ./source build/gettext sphinx-intl update -p ./build/gettext -l zh_CN ``` -------------------------------- ### Perform Point-to-Point Nearest Neighbor Match (GeoDataFrame) Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/gisprocess.html This example demonstrates the use of `tbd.ckdnearest_point` for matching points between two GeoDataFrames, `dfA` and `dfB`. Unlike `ckdnearest`, this function directly operates on GeoDataFrames with point geometries, and the calculated distance is based on the geographic coordinates. ```Python tbd.ckdnearest_point(dfA,dfB) #此时计算出的距离为经纬度距离 ``` -------------------------------- ### Visualize Trajectory Data with TransBigData and Kepler.gl Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/example-taxi/example-taxi.rst.txt This Python code uses the `visualization_trip` function from the `transbigdata` library to generate an interactive visualization of the `data_deliver` trajectory data. This function leverages Kepler.gl for rich mapping capabilities. ```Python tbd.visualization_trip(data_deliver) ``` -------------------------------- ### Prepare Node Data for Network Graph Construction Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/_sources/example-bikesharing/example-bikesharing.rst.txt Extracts and prepares unique node information from the aggregated OD data for building a network graph. It combines the grid coordinates of origin and destination points into unique string identifiers, collects all unique identifiers, converts them into a Pandas DataFrame, and assigns a sequential numerical ID to each node. ```python #把起终点的经纬度栅格编号变为一个字段 od_gdf['S'] = od_gdf['SLONCOL'].astype(str) + ',' + od_gdf['SLATCOL'].astype(str) od_gdf['E'] = od_gdf['ELONCOL'].astype(str) + ',' + od_gdf['ELATCOL'].astype(str) #提取节点集合 node = set(od_gdf['S'])|set(od_gdf['E']) #把节点集合变成DataFrame node = pd.DataFrame(node) #重新编号节点 node['id'] = range(len(node)) node ``` -------------------------------- ### Find K-Shortest Paths Between Subway Stations Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/gallery/Example 7-Modeling for subway network topology.ipynb This snippet uses `tbd.get_k_shortest_paths` to identify multiple (k) shortest paths between two specified subway stations ('镇海路' and '蔡厝') in the network graph `G`. This is useful for exploring alternative routes and understanding network redundancy. ```python paths = tbd.get_k_shortest_paths(G,stop,'镇海路','蔡厝',2) paths ``` -------------------------------- ### Perform various coordinate conversions using TransBigData Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/CoordinatesConverter.rst This snippet demonstrates how to use the `transbigdata` (tbd) library to convert geographic coordinates between different systems like WGS84, GCJ02, and BD09. It shows examples of converting longitude and latitude columns in a pandas DataFrame, leveraging numpy column computation for efficiency. ```Python >>> data['Lng'],data['Lat'] = tbd.wgs84tobd09(data['Lng'],data['Lat']) >>> data['Lng'],data['Lat'] = tbd.wgs84togcj02(data['Lng'],data['Lat']) >>> data['Lng'],data['Lat'] = tbd.gcj02tobd09(data['Lng'],data['Lat']) >>> data['Lng'],data['Lat'] = tbd.gcj02towgs84(data['Lng'],data['Lat']) >>> data['Lng'],data['Lat'] = tbd.bd09togcj02(data['Lng'],data['Lat']) >>> data['Lng'],data['Lat'] = tbd.bd09towgs84(data['Lng'],data['Lat']) >>> data['Lng'],data['Lat'] = tbd.bd09mctobd09(data['Lng'],data['Lat']) ``` -------------------------------- ### Plot Specific Vehicle Data with Pandas Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/traj.html This Python snippet demonstrates how to filter a Pandas DataFrame (`tmp2`) to isolate data for a specific 'Vehicleid' (e.g., 36805) and then plot the resulting subset. It's commonly used for visualizing individual trajectories or specific data points within a larger dataset. ```python tmp2[tmp2['Vehicleid']==36805].plot() ``` -------------------------------- ### Perform Point-to-Point Nearest Neighbor Match (DataFrame) Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/gisprocess.html This example demonstrates how to use `tbd.ckdnearest` to find the nearest point in `dfB` for each point in `dfA`. It explicitly specifies the longitude and latitude column names for both DataFrames, and the calculated distance represents the actual geographic distance converted from longitude and latitude. ```Python tbd.ckdnearest(dfA,dfB,Aname=['lon1','lat1'],Bname=['lon','lat']) #此时计算出的距离为经纬度换算实际距离 ``` -------------------------------- ### Enable Sphinx Read the Docs Theme Navigation Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/plot_map.html This JavaScript snippet uses jQuery to enable the navigation functionality provided by the Sphinx Read the Docs theme upon document readiness. ```JavaScript jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); ``` -------------------------------- ### transbigdata.getadmin() API Reference Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/genindex.html API documentation for the `transbigdata.getadmin()` function, a built-in utility function from the `transbigdata` library, likely for retrieving administrative boundary data. ```APIDOC transbigdata.getadmin() ``` -------------------------------- ### Python: Estimate Confidence Ellipse Parameters Source: https://github.com/ni1o1/transbigdata/blob/main/docs/source/_build/html/gisprocess.html This Python example demonstrates how to use `transbigdata.ellipse_params` to estimate the parameters of a 95% confidence ellipse from a Pandas DataFrame. It shows the function call with custom column names and the structure of the returned parameters, which include centroid, axis lengths, angle, area, and flatness. ```Python ellip_params = tbd.ellipse_params(data,confidence=95,col = ['x','y']) ellip_params ```