程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

(data science learning records 139) list of important new features of geosandas version 0.11

編輯:Python

The sample code for this article has been uploaded to my Github Warehouse https://github.com/CNFeffery/DataScienceStudyNotes

1 brief introduction

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 .

2 geopandas 0.11 List of important new features of version

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 :

2.1 Faster vector file reading and writing

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 :

2.2 New rectangular cutting method with improved performance clip_by_rect()

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 :

2.3 Read and write correctly GIS Date time field in file

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 ~


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved