We have now looked at how we can go from a vector to a raster, so it is now time to go from a raster to a vector. This method is much more common because most of our vector data is derived from remotely sensed data, such as satellite images, orthophotos, or some other remote sensing dataset, such as lidar
.
As usual, enter the workon pygeoan_cb
command in your Python virtual environment:
$ source venvs/pygeoan_cb/bin/activate
This recipe only requires four steps utilizing OGR and GDAL so please open up a new file for your code:
Import the
ogr
andgdal
modules and go straight ahead and open the raster we want to convert by passing it the filename on disk and getting a raster band:#!/usr/bin/env python # -*- coding: utf-8 -*- from osgeo import ogr from osgeo import gdal # get raster data source open_image = gdal.Open( "../geodata/cadaster_borders-2tone-black-white.png" ) input_band = open_image.GetRasterBand...