Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Open Source Image cutting in GIS Development

Shulou Source: shulou.com Published: 2022-06-01 03:44:41 09月15日 Update

This article mainly introduces how to use open source image cutting in GIS development, the article is very detailed, has a certain reference value, interested friends must read it!

In the process of using image data, it is sometimes necessary to cut the image data according to a coordinate range. Commonly used tools such as arcmap can be used for image cutting. The following introduces a use of open source class library for image cutting, the development language is python.

The name of the open source library is: https://github.com/mapbox/rasterio rasterio,github is a specialized image processing library with a variety of image processing functions, as described on the website.

Let's briefly say that you can use rasterio to do a simple image data cutting.

Before development, prepare a basic image, a cutting image area vector data, here prepare a shp file, to ensure that the vector cutting data and image data coordinate system is consistent.

The specific python code is as follows:

Import fiona

Import rasterio

Import rasterio.mask

# fiona Open the shp file and install it using conda or pip

# Open a shp file as read-only

With fiona.open ("Vector File clipdata.shp", "r") as shapfile:

# cycle through the area coordinate information of the shp file

Features = [feature ["geometry"] for feature in shapfile]

# Open the path of the cut tif file

With rasterio.open ("tif file path L15.tif") as src:

# cut layers according to the coordinate range of the vector

Out_image,out_transform = rasterio.mask.mask (src,features

Crop=True)

# copy the data of the source tif

Out_meta = src.meta.copy ()

# update the replicated source tif data according to the cutting information

Out_meta.update ({"driver": "GTiff"

"height": out_image.shape [1]

"width": out_image.shape [2]

"transform": out_transform})

# Save tif to a new file and write it to disk

With rasterio.open ("Save path clip.tif", "w", * * out_meta) as dest:

Dest.write (out_image)

Cut image effect:

These are all the contents of the article "how to use Open Source Image cutting in GIS Development". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Images data files development coordinates vectors paths information content articles scope preparation processing consistency code value interest function name coordinate system Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS OPPO Reno Linux Shulou Information Apple