Creating masks

Michael-James Coetzee
Satellite Intelligence
3 min readAug 29, 2019

At this point we have a geojson file which represents current sugarcane areas in Queensland and we have a geojson file with the coordinates for the 4 corners of each tile. We can intersect our sugarcane area and tiles (assuming they are in the same format see note below).

We want to know which pixels lie within the intersection (part of the mask) and which do not. Shapely is a python library for working with geometric data and can be used to calculate intersections with methods like intersect (returns a boolean) and intersection (returns a geometric object as a result of the intersection). We can generate coordinate representations for the pixels within the tile in a similar fashion to how we created tile geojson files discussed in (Generating tile geometry files) in this case the step size we move will just be a pixel in length.

PIL(https://pypi.org/project/Pillow/ , https://en.wikipedia.org/wiki/Python_Imaging_Library) is a python library for working with images, format, resizing, manipulation ,etc. PIL has the ability to work with images at the pixel level.

So consider the following pseudocode:

To see if you are heading in the right direction you could import a tiles geometry.json into national map (this will create a transparent square). Import current sugarcane areas from data- part of which will intersect your transparent square if its a tile with sugarcane- and compare this intersection to the mask you have created (or for an even more accurate comparison generate the mask on top of the tile image and compare).

Note: FullSugar.geojson is already converted to the desired format for you.

Geo-spatial data comes in various formats, so if you have 2 separate shapes stored in geojson format and would like to calculate their intersection they will need to be in the same format. The Queensland sugar cane data is in format epsg:3577 and our tiles are in format epsg: 4326.

A solution could be to convert the sugar cane data to be in the same format as the tiles geometry file. To do this we read in the Queensland agricultural data .geojson file into geopandas dataframe. Geopandas is an extension of pandas to support geometric data the same way geojson is an extension of json. We filter down to sugar cane only as we do not need other crop information and then convert/re-project (http://geopandas.org/projections.html) the data to the new format (dataframe.to_crs(epsg=4326)).

--

--