The sample code for this article has been uploaded to my
Github
Warehouse https://github.com/CNFeffery/DataScienceStudyNotes
Hello, everyone. I'm Mr. Fei , Just a few days ago ,geopandas
Published its 0.11.0
Official version , From its previous version (0.10.2
) Half a year has passed since the release , What important new features have been brought to us in this new version update , In today's article, I will take you to find out .
You can geopandas
Upgrade based on , You can also create a new virtual environment and install it directly 0.11.0
edition , In line with the principle of cautious taste , We can use the following command to create a new virtual environment at one go 、geopandas
And related dependent installations , And install jupyterlab
As IDE demonstrate :
conda create -n geopandas-env python=3.8 -c https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main -y
conda activate geopandas-env
conda install geopandas=0.11.0 pygeos pyogrio -c conda-forge -y
pip install jupyterlab -i https://pypi.douban.com/simple/
Execute the following commands in the terminal to verify whether it is correctly installed :
python -c "import geopandas as gpd;print(gpd.__version__)"
Everything is all set. , Let's take a look at some of the more important features in this update :
In the new version read_file()
And to_file()
Parameters are introduced engine
Used to specify the engine on which to read and write common vector files , The default is the original 'fiona'
, Optional 'pyogrio'
, This is from geopandas
Another library maintained by the development team , It can greatly improve the understanding of common vector file formats, such as shapefile
Reading and writing speed , Take the reading of the whole building contour data in Guangzhou with millions of polygons as an example , new IO The engine brings near 5 Times the read performance :
And equally close 5 Times the write performance :
0.11
New in for GeoSeries
and GeoDataFrame
Methods clip_by_rect(minx, miny, maxx, maxy)
, The target rectangular coordinate range can be passed in , Quickly cut out the vector within the rectangle , For example, we are based on the previously read building outline data of Guangzhou , Randomly generate the side length by the following function 10000 The rectangular range of meters is used as cutting material :
import numpy as np
import matplotlib.pyplot as plt
from shapely.geometry import box
# Calculate the target GeoDataFrame Range
minx, miny, maxx, maxy = gdf.total_bounds
def generate_random_rectangle(minx, miny, maxx, maxy):
'''
Randomly obtained within the scope of the study 100000 M side length rectangle
'''
random_rectangle = [
np.random.uniform(minx, maxx - 10000),
np.random.uniform(miny, maxy - 10000)
]
return [
*random_rectangle,
random_rectangle[0] + 10000,
random_rectangle[1] + 10000,
]
call clip_by_rect()
:
The returned result is consistent with the number of original vector records , Where presented GEOMETRYCOLLECTION EMPTY
The record of indicates that it does not intersect with the target rectangle , We make use of is_empty
To reverse filter out the vector records that have been trimmed :
besides , You can also direct [minx, miny, maxx, maxy]
The input format is passed into the classic clip()
Cutting method , It will call directly at the bottom clip_by_rect()
And automatically return the effective vector cutting result :
from 0.11.0
Version start ,geopandas
When facing a date time field , Whether it is written to GIS File or from GIS File read in , Can be correctly resolved to date time type :
You can https://github.com/geopandas/geopandas/releases/tag/v0.11.0
See the full version update instructions , Overall speaking , There are not many important updates brought about by this new version update , But they are quite practical , You can use it on your own data .
The above is the whole content of this paper , Welcome to discuss with me in the comments section ~