I have an orthomosaic of a crop field with small research plots (3.8 X 1.44 m and 0.22m b/w plots and 0.50m b/w range spacing).

I would like to create a polygon layer using this information. After every three ranges and ten columns there are 1.0m and 1.30m wide allies, respectively.

I tried using the 'pyshp' module in python following this answer to Creating square grid polygon shapefile with Python?, but it did not help much.

So I was wondering if there is any tool available that would allow me to create polygon layers more efficiently ?

Do you have any suggestions on what would be the best way to do in Python, ArcGIS for Desktop, or QGIS ?

Edit: Here is the raster image of the field. So I tried the layer copy-paste method but the attribute table had FID all over the place i.e. without any proper sequence. The only way to asign the plot id to each polygon is to highlight each polygon in attribute table and enter the id manually. As MappaGnosis suggested, I would like to give python scripting a try.

  • 1
    Are you having difficulty with the python aspect or pyshp? arcpy has the ability to create geometries and would probably be just as easy. Perhaps, if you don't want to code this, edit in ArcMap (or QGIS) create one block, copy & paste and move to the new location... repeat. How many blocks are there? There are some keyboard shortcuts in ArcMap that will help you draw accurately (constrain to length/angle etc..) Jul 22, 2015 at 1:39
  • Michael, thanks for your inputs. Since I am new to python, coding is a bit of an issue too. I will give block copy paste trick a try first.
    – SinghD
    Jul 22, 2015 at 2:35
  • Are you able to show an example?
    – TsvGis
    Jul 22, 2015 at 3:08
  • @TsvGis Please see my edit above.
    – SinghD
    Jul 28, 2015 at 0:04
  • Oh I see. I think I may have a solution. I would create a network of lines and then assign them a width (eg 1.0m would be .5m as I am about to buffer). Then I would buffer the lines based off their distances. The output would be a polygon representing spaces/corridors between the fields. From there, I would create a new polygon layer that covers the entire area and use the first polygon (spaces/corridors) to erase the same areas from the second polygon. What I would be left with is the areas of the crop fields. If I get time, Ill post examples in the answer section below.
    – TsvGis
    Jul 28, 2015 at 1:12

2 Answers 2


To be honest, a python script (if you are familiar with Python) would be the most efficient method of creating your polygons in your use-case. However, if you are not familiar with scripting, then there are a variety of tools that you should investigate in QGIS (e.g. Vector->Research Tools->Vector Grid). You will have to use a crazy combination of these to get your result (probably something along the lines of creating a vector along the mid lines of your allies and then successively overlaying other grids... but it gets nasty very quickly because of your allies and spaces).

So, if programming is out of the question and hours of experimenting with unfamiliar tools is not appealing, I suggest you think laterally (though this is still going to require a pretty hefty formula)! I assume you are familiar with Excel. You can set up a spreadsheet to mimic your research area. Each cell will have a comma separated value along the lines of this: 1-1,234156,654789 where the first value '1-1' is a plot id and the second pair of values are the x and y coordinates of the corner of the plot. Each plot will have four Excel cells and you will use a simple repeating formula to calculate the offsets. You then auto fill your spreadsheet, export to a CSV but use spaces as the delimiter between cells. Then use MSWord or similar to globally change spaces to carriage returns and add a header line "id,x,y". Now import this as a text delimited file into QGIS and it will give you an array of points. Next use the Points2One plugin to generate polygons based on your plot id.

I would set Excel up this way:
Enter the coordinates of your first corner with the id 1-1. Now you need a formula. Each subsequent point will be an offset from the first corner. Your plot spaces and allies are identified by testing the value of ROW() and COLUMN() using rules:

  1. If it is even, your coordinate equals the previous coordinate plus the width/height of the plot. If it is odd, offset by the plot spacing. Use this to also know whether to increment your plot id as each group of four cells must have the same ID.
  2. Test ROW() and COLUMN() using MOD for your ranges (you don't say how many plots a range is). Remember to allow two columns in the X direction and two rows in the Y direction for every plot (one cell per plot corner - remember!).
  3. Use MOD to test for multiples of 3 and 10 ranges to offset by the ally width.

In this way you will build a (large) formula using a nested IF() statement. It will start with concatenating COLUMN() '_' ROW() as a string and add (through an IF() statement for X and another IF() statement for Y) the coordinates so that every cell will contain id,x,y. Then export and convert to polygons as described above.

Personally... I'd write a Python script, but if you know Excel, this will work.

  • The reply was surely helpful. After reading your reply, actually now I am more inclined to give Python scripting a try. Could you point to me a primer/pseudocode that I should start playing around with ? Here is the raster file to give you a better idea.
    – SinghD
    Jul 28, 2015 at 0:08
  • If your plots are based on that aerial image, an alternative zero scripting solution might be to use edge detection to generate your polygons. It's not often you see such a prime candidate for edge detection! Well worth a shot. As for getting started with Python, have a look at this community wiki. If you scroll down to my answer there, you'll find a great link to on-line tutorials to get you started using the GDAL libraries. Jul 28, 2015 at 6:36

After seeing the raster image of the field, I though of this process - I used Arcgis 10.2.1. (Note: Just realised that I have got the length and widths around the wrong way when compared to the image, but If I was to recreate the answer I would use the same process below but amend the lengths and widths)

  • Using the dimensions provided I worked out what the lengths and spacing of my lines.

enter image description here

The spacing of the lines included a buffer distance to incorporate for ally ways and spacing between plots. Eg a plot width of 3.8m would have .5m add to its width (.25m for each side of the line) giving a total of 4.3m.

The columns on either end will have similar dimensions as they cater for ally ways of 1.3m, while the rows on top and on the bottom cater for the ally ways of 1m

enter image description here

The next step was buffering. I created a new field in my attribute table called buffer and entered the required buffer distance (If I needed a buffer/area of 1m, then I would half that distance and input that value eg .5m)

enter image description here enter image description here

With the buffering done, I have a shapefile (see green polygon below) showing all the allay ways and spacing corridors around and between the plots.

enter image description here

enter image description here

The next step is to create a new polygon covering my entire area (see blue polygon below)

enter image description here

From there I used the Erase Tool to remove those areas of allay ways and spacing corridors from my new polygon. The end result is a polygon coverage of 10 x 3 plots.

enter image description here

If you wanted to do more plots, then you can join together multiple copies of the original line shape file and then go though the processing of buffering and erasing. Below shows multiple plots.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.