AGI Grow
Farm-management web app for crops, storage, and contracts
Front-end features and fixes, notably importing field boundaries from shapefiles; a few small API fixes
AGI Grow is a farm-management app from AGI (Ag Growth International), built by Apply Digital. Farmers draw their fields on an aerial map, add crops, log activities such as planting, fertilizing, and spraying, keep track of grain storage and contracts, and see revenue forecasts. It’s designed to keep working in the field, with or without a connection.
Tech
The web app is React and Redux (with redux-form), talking to a GraphQL API on AWS AppSync, with Google Maps for drawing fields and Victory for the charts. The API, a separate repository which was mostly someone else’s work, uses the Serverless Framework, Lambda, and DynamoDB.
Where I came in
The project had been running since May 2018 when I joined the front-end team at the end of March 2019, and I was on it until early June. I fixed bugs and polished a lot of screens, but the main thing I built was importing fields from shapefiles.
Importing fields from shapefiles
Until then the only way to add a field was to draw it on the map. Now a user can upload a zipped shapefile instead, and choose which of the shapes in it to import.
Parsing happens entirely in the browser. shpjs turns the zip into GeoJSON, any MultiPolygons are flattened to plain Polygons, and Turf calculates each shape’s area (in acres) and picks a point on it for labelling.
The shapes appear together on a map and in a list, largest first. The ten largest within an area range are ticked to start with, and a slider adjusts that range. Each row has an editable name, checked for uniqueness, and an editable area, and hovering over a row highlights its shape on the map. Chosen shapes which overlap an existing field, or each other, are flagged. That needs an intersection test between every pair, which gets slow with a lot of shapes, so the results are memoized by pair, and the number of shapes ticked on load is limited.
To check for overlaps with the fields people had already drawn by hand, I generate GeoJSON for those legacy fields too, and the map component now draws every field the same way. On submit the fields go to the GraphQL API, with validation and server errors shown in the form, and a banner on success. It shipped behind a feature flag so it could be switched on remotely.
Other work
I followed up a teammate’s offline mode, which had been merged and then reverted: I re-landed it and fixed how the map, storage, and activity screens behave without a connection.
Smaller pieces: a switch to redux-responsive so JavaScript layout decisions agree with the CSS breakpoints; trimming whitespace on every text input; tooltip and scrolling fixes for the bar charts; and a few small fixes in the API, including one for null crop varieties breaking the revenue forecast.