Converting raster file into a shapefile using python

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ธ.ค. 2024

ความคิดเห็น • 21

  • @connors_corndogs
    @connors_corndogs ปีที่แล้ว

    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?

  • @davutturkmen6790
    @davutturkmen6790 2 ปีที่แล้ว +1

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

    • @geogislabs
      @geogislabs  2 ปีที่แล้ว +2

      Yes, you can do it. You just need to read the netcdf file using Gdal.Open(). i.e. raster = gdal.Open(r'filename.nc')

  • @arminyeganeh8321
    @arminyeganeh8321 ปีที่แล้ว

    Very useful! Thank you!

  • @NabilaPutri-ko2yj
    @NabilaPutri-ko2yj 8 หลายเดือนก่อน

    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?

  • @ankratijain
    @ankratijain ปีที่แล้ว +1

    Thank you for a video

  • @johnhebert7725
    @johnhebert7725 2 ปีที่แล้ว +1

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

    • @geogislabs
      @geogislabs  2 ปีที่แล้ว +1

      Hi John, I will publish that video on Friday

    • @johnhebert7725
      @johnhebert7725 2 ปีที่แล้ว

      @@geogislabs ok, continue with the videos, they are very interesting. I will sign up!

  • @mohdhassanin8292
    @mohdhassanin8292 2 ปีที่แล้ว

    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.

    • @geogislabs
      @geogislabs  2 ปีที่แล้ว

      Try installing Gdal. So, if you are using jupyter notebook from anaconda, try this in one of the cell: conda install -c conda-forge gdal --y. After that, run this code again "from osgeo import gdal, ogr, osr". Let me know if this solve your problem

    • @mohdhassanin8292
      @mohdhassanin8292 2 ปีที่แล้ว

      @@geogislabs sure sir, I will try this and I will be back soon.
      Thank you

    • @mohdhassanin8292
      @mohdhassanin8292 2 ปีที่แล้ว

      @@geogislabs this error came- DDL load failed while importing_gdal: specified module could not be found.

    • @geogislabs
      @geogislabs  2 ปีที่แล้ว

      @@mohdhassanin8292
      1. Uninstalling GDAL with:
      pip uninstall gdal
      2. Installing the GDAL wheels from www.lfd.uci.edu/~gohlke/pythonlibs/#gdal (follow the instructions on the website in your question concerning python and windows version). you can use:
      pip install GDAL-2.2.4-cp36-cp36m-win_amd64.whl
      see original post: gis.stackexchange.com/questions/259902/gdal-importerror-dll-load-failed-the-specified-module-could-not-be-found

    • @georgeknowles7504
      @georgeknowles7504 2 ปีที่แล้ว +1

      @@mohdhassanin8292 Run an environment first "conda create -n [environment name] python=3.9"
      Then use "conda install -c conda-forge GDAL python=3.9" (plus any other modules you want to install). I installed Geopandas, GDAL, Fiona, Shapely and Pandas using this method after days of having import issues.
      Personally I didn't have much luck with wheel files.

  • @maheshmaskey4592
    @maheshmaskey4592 10 หลายเดือนก่อน

    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 r"""ImportFromWkt(SpatialReference 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.

    • @geogislabs
      @geogislabs  10 หลายเดือนก่อน

      You should try adding the parentheses in the GetProjection function. project = raster.GetProjection() and see if it works

  • @celisantos7862
    @celisantos7862 7 หลายเดือนก่อน

    Hello!
    raster = gdal.Open(r'MNC_verano-2023/MNC_verano-2023.tif')
    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?

  • @roxanaluciadeceukelaire4877
    @roxanaluciadeceukelaire4877 11 หลายเดือนก่อน

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