Converting raster file into a shapefile using python

preview_player
Показать описание
This video explains how to convert a raster file into a shapefile by using python

Gdal.Polygonize function:

You should watch the following video if you have problem using Geopandas

#Python
Chapters

0:00 Introduction
00:15 Setting up the Jupyter Notebook
2:16 Reading the raster file
5:32 Converting raster into a shapefile
18:05 Reading the shapefile created
Рекомендации по теме
Комментарии
Автор

What change in the code would you make so that the polygon doesn't join like-features? What I mean is, each vector attribute is it's own feature/row of data rather than being dissolved?

connors_corndogs
Автор

i run the code exactly same as you did, but my google colab always showing crashed for many times. i haven't made the effort.. what could go wrong?

NabilaPutri-koyj
Автор

Hi! when i run shp_layer = create_shp.CreateLayer('Layer1', srs = shp_proj), it says the Layer already exists. How can I fix this?

roxanaluciadeceukelaire
Автор

Can ı do same process with land use land cover data (netcdf format).

davutturkmen
Автор

How do I do the opposite, convert a shapefile to raster?

johnhebert
Автор

Hello!
raster =
raster
band + raster.GetRasterBand(1)
band

NameError Traceback (most recent call last)
Cell In[37], line 1
----> 1 band + raster.GetRasterBand(1)
2 band

NameError: name 'band' is not defined


What is this error?

celisantos
Автор

Very useful video. I appreciate it. However, I tried to replicate it, but I encountered the following problem.
TypeError Traceback (most recent call last)
Cell In[21], line 3
1 proj=raster.GetProjection
2 shp_proj = osr.SpatialReference()
----> 3 shp_proj.ImportFromWkt(proj)
5 output_file = os.path.join(sub_dir, '2021CDL_Landuse.shp')
6 call_drive = ogr.GetDriverByName('ESRI Shapefile')

File C:\ProgramData\Anaconda3\envs\myspatial\Lib\site-packages\osgeo\osr.py:756, in SpatialReference.ImportFromWkt(self, *args)
754 def ImportFromWkt(self, *args):
755 self, char ** ppszInput) -> OGRErr"""
--> 756 return _osr.SpatialReference_ImportFromWkt(self, *args)

TypeError: not a string

Does anyone have any suggestions, including the presenter? I am grateful for your answer in advance.

maheshmaskey
Автор

Hi sir,
while I try to import the gdal, ogr and osr from osgeo, one error is coming that osgeo module is not available.
what should i do?
thank you in advance.

mohdhassanin