Python handles geographic data-geopandas and PYSHP

Source: Internet
Author: User
Tags python script

This blog is not about Geopandas tutorials and pyshp tutorials!

There are a lot of related packages for using Python to process geographic data, and recent research needs to deal with some geographic data, but ArcGIS's arcpy is always unsatisfactory. So here's a list of other Python-related data-processing packages.

1. Reading and writing of geographic data

The general common format for geographic data is SHP file, which reads and writes two packets, one is Fiona and the other is pyshp.

Fiona is based on C + + library packaging, so the direct use of PIP installation in use will be problematic, you can use Conda first install Gdal, and then install Fiona.

Pyshp is a pure Python script-written package, so it's better to install and use it than Fiona, but it might be a little less efficient, and I didn't test it.

2. Processing of geographic data

The processing of geographical data is generally shapely this library, here does not do the detailed introduction, it mainly to produce buffer ah, and so on this kind of geographic data processing operation

3. How to work with both property and collection data

Under Pandas, there's a bag called Geopandas. It expands the pandas to handle geographic data. It is mainly packaged on Pandas,fiona and shpely. So install it before installing these dependencies first

Geopandas can read and write geographic data at the same time, and it can also handle attribute data. Therefore, it is recommended to use this library

4. Comparative summary

When using Geopandas, I want to first understand shapely and pandas, I use Geopandas to save the shape file when the teacher error:

1

WARNING:Fiona:CPLE_AppDefined in one or several characters couldn ' t is converted correctly from UTF-8 to iso-8859-1.
This warning is not being emitted anymore.

File"f:/xiaokangworkspace/pythonwork/geopandasfrompandas.py", line 46,inch<module>2Test1.to_file ('test6.shp')3 4File"C:\Users\wybert\Anaconda2\lib\site-packages\geopandas\geodataframe.py", Line 305,inchTo_file5 c.write (Feature (I, row))6 7File"C:\Users\wybert\Anaconda2\lib\site-packages\fiona\collection.py", Line 402,inch __exit__8 self.close ()9 TenFile"C:\Users\wybert\Anaconda2\lib\site-packages\fiona\collection.py", line 386,inchClose One Self.flush () A  -File"C:\Users\wybert\Anaconda2\lib\site-packages\fiona\collection.py", Line 376,inchFlush - Self.session.sync (self) the  -File"Fiona/ogrext.pyx", line 939,inchFiona.ogrext.WritingSession.sync (fiona/ogrext.c:15649) -  -runtimeerror:failed to sync to disk

This error is due to the fact that my property sheet contains Chinese characters, which in the final analysis should be a coding problem, I have done this with python3, and there is no warning message, but the same problem still occurs. Using ArcGIS to open the collection information for a file that has already been written but the property sheet cannot be opened, but using Qgis to open, you can see that the column containing Chinese in the attribute table is garbled (using EXCE can open the attribute table in DBF). The following solutions are available to handle this problem:

    1. use Geopandas to process data but use PYSHP to write files: This scheme is better, and the files written by ArcGIS and Qgis all recognize
    2. write the file using Geopandas and then follow up with DBF : Sadly, pandas does not provide read/write to the DBF file (a good solution here), which can be read using the SIMPLEDBF package and then written using the DBF package. However, this scheme can also be implemented using PYSHP because PYSHP implements the ability to read and write DBF files separately.

Python handles geographic data-geopandas and PYSHP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.