In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Pandas,GeoPandas and ArcGIS to achieve data processing and mapping, the article is very detailed, has a certain reference value, interested friends must read it!
The first part is to learn to use pandas for data. There are two big data structures in pandas, which are series sequence and DataFrame data frame. The experimental subjects using pandas are some weather data local to the computer before, and the storage format is .xlsx. Experimental data are only experimental data, and it is good to use it to practice pandas, at least for now.
The general steps of pandas data analysis are not complex, importing libraries-> reading data-> data operations (slicing, filtering, combining, sorting, batch processing, etc.)-> writing data to csv or xlsx or txt plain text.
Pandas's data is easy to read:
Import pandas as pddata = pd.read_excel (rusted D:\ inuyasha\ codeX\ Python\ Meteorological data 1960-2018\ 1960.xlsx')
Series = data ['mean temperature'] # sequence, which is series_to_dataframe=pd.DataFrame (series) # arranged in this way: 1 series data structure into data frame structure, pd and big data structure series_to_dataframe
Rename to add index operations:
Datare = data.rename (columns= {'mean temperature': 'mean temperature'}) # rename the column using the rename method, dictionary, 1 is the original name, 2 is the changed name datare ['INDEX'] = datare.index # based on the original index, .index method, the name INDEXdatare [' mean temperature'] = datare ['average temperature'] # does not replace the original column, but adds a new column, exactly the same Add datare.drop (columns='INDEX') # to the end to delete the original column datare
Delete a row, or you can delete multiple rows. Index is the row index, and the axis pointer is for all columns:
Df1 = datare.drop (index=0,axis=1)
Delete multiple rows according to the index, index is the row index, and axis pointer to all columns df2 = datare.drop (index= [0mem1mem2mem3], axis=1)
Locate and extract data:
Datare ['area station number'] .isin ([50136]) # isin function to determine whether this number exists in this column without quotation marks, otherwise it will become a string datare [datare ['area station number'] .isin ([50136])] # take the located data datare [- datare ['area station number'] .isin ([50136])] # take out the located data in the original data, preceded by a horizontal line to indicate the reverse selection
If you want to extract more than one column at a time, put the required columns in the form of list
Data_multicolu2 = datare [['area station number', 'latitude', 'longitude', 'year', 'month', 'day', 'average temperature'] # list form to extract the desired multi-column slices data_multicolu2
Sort:
Datare.sort_values (by=' mean temperature', ascending=False)
There are more functions, so we won't write them all here. Use it a few more times and you'll be familiar with it. The question I thought about before was how to extract some data from multiple xlsx, which worked. Haha.
The second part is Geopandas reading shp data + drawing display + adding longitude and latitude identification (EWSN)
The script is as follows:
Import geopandas as gpdimport numpy as npimport matplotlib.pyplot as pltimport cartopy.crs as ccrsfrom cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatterimport cmaps#import arcpygd_boundary = gpd.read_file ('D:\ ArcGISgeobase\ guangdata\ gd_boundary.shp') gd_road = gpd.read_file ('D:\ ArcGISgeobase\ guangdata\ gd_road.shp') # fig,ax = plt.subplots (figsize= (16)) # set canvas size plt.figure (figsize= (16) 12) ax = plt.subplot (projection=ccrs.PlateCarree ()) # Global setting plt.rcParams ['font.family'] =' Times New Roman'plt.rcParams ['font.size'] = 16
Gd_boundary.plot (ax=ax,facecolor='none',edgecolor='k',linewidth=0.99) # Boundary Settings gd_road.plot (ax=ax,edgecolor='b',cmap=cmaps.posneg_2,lw=0.3,legend=False) # Road Network Settings
Ax.set_yticks (np.arange (20,26,1.0), crs=ccrs.PlateCarree () ax.set_xticks (np.arange (109,118,1.0), crs=ccrs.PlateCarree ())
Ax.xaxis.set_major_formatter (LongitudeFormatter ()) # Latitude and longitude indication, EWSNax.yaxis.set_major_formatter (LatitudeFormatter ())
# ax.set_axis_on () # Open the rectangular border ax.set_title ('Guangdong_Roads',fontsize=16) # set the title
Plt.grid () # set the grid
The display results are shown in the following figure, and it is found that there is no latitude and longitude mark, although it can be identified according to the change direction of the data, but it is better to add the upper longitude and latitude mark. Then Gu Brother browser looked for a solution, but did not find it. He saw that many tutorials did not add this latitude and longitude logo, so he did it himself:
Add latitude and longitude marks yourself:
Plt.figure (figsize= (16,10) ax = plt.subplot (projection=ccrs.PlateCarree ()) ax.set_yticks (np.arange (20,26,1.0), crs=ccrs.PlateCarree ()) ax.set_xticks (np.arange (109,118,1.0), crs=ccrs.PlateCarree ())
Ax.xaxis.set_major_formatter (LongitudeFormatter ()) # Latitude and longitude indication, EWSNax.yaxis.set_major_formatter (LatitudeFormatter ())
Now let's take a look at the effect. AHA, in that case, the latitude and longitude marks are coming.
Then I want to use ArcPy to do a line density analysis of the road network, but it is too troublesome to configure it, so I switch to ArcGIS to operate it (although I am afraid that it will be stuck at any time, especially if the data is not saved)
The third part uses ArcGIS to do the line density operation and local magnification of the road network. Local magnification has its own function, that is, if it looks blurred in the case of high density, then it may need to be locally enlarged, so draw a schematic diagram:
So, when you come to ArcGIS, it is enough to load road network data and vector boundaries.
Decorate the picture, it looks reluctantly, this color seems to be adjusted by himself a few days ago, it should be, if you remember correctly.
Some places feel too dense and not good-looking, so enlarge it locally. The principle is to create a new data box.
The above is all the contents of the article "how to use Pandas,GeoPandas and ArcGIS to achieve data processing and drawing". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.