Update 'Create-b-cropfield.md'

This commit is contained in:
Wilco Krikke 2021-08-27 19:23:50 +00:00
parent 3763bb735e
commit c9f5fc00b9

View File

@ -8,7 +8,6 @@ Farmmaps also uses the cropfield to collect and prepare context data such as wea
To create a cropfield we: To create a cropfield we:
* Get the parent folder to place the cropfield under * Get the parent folder to place the cropfield under
* Create a folder under this element (optional)
* Create the cropfield * Create the cropfield
**Prerequisites** **Prerequisites**
@ -20,12 +19,17 @@ To create a cropfield we need:
### Get parent element ### Get parent element
First, we'll get the parent code needed to place the cropfield in the hierarchy. First, we'll get the parent code needed to place the cropfield in the hierarchy.
Usually this is a cropping scheme.
So when the code of the crop field is known, use this code as parent code to create the crop field and go to the next chapter.
## Get cropping scheme
When the cropping scheme code is not known, we need to start from the top of the hierarchy, which is my_roots.
**Request** **Request**
Replace `<acces token>` with your actual token. Replace `<acces token>` with your actual token.
```http ```http
GET https://farmmaps.awacc.nl/api/v1/folders/my_drive? HTTP/1.1 GET https://farmmaps.eu/api/v1/folders/my_roots HTTP/1.1
Host: farmmaps.awacc.nl Host: farmmaps.eu
Accept: application/json Accept: application/json
Authorization: Bearer <access token> Authorization: Bearer <access token>
``` ```
@ -35,19 +39,17 @@ The response will be something similar to:
```http ```http
HTTP/1.1 200 OK HTTP/1.1 200 OK
Server: nginx/1.14.0 (Ubuntu) Date: Fri, 27 Aug 2021 19:00:55 GMT
Date: Tue, 21 Apr 2020 09:57:07 GMT
Content-Type: application/json; charset=utf-8 Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive Connection: keep-alive
Server: Kestrel
Cache-Control: no-store,no-cache Cache-Control: no-store,no-cache
Pragma: no-cache Pragma: no-cache
Content-Encoding: br Content-Length: 835
Vary: Accept-Encoding
{ {
"url":"/api/v1/folders/f25d8765a1cd407cb235961c73c268cf:USER_FILES", "url":"/api/v1/folders/f25d8765a1cd407cb235961c73c268cf:USER_IN",
"code":"f25d8765a1cd407cb235961c73c268cf:USER_FILES", "code":"f25d8765a1cd407cb235961c73c268cf:USER_IN",
"name":"My Drive", "name":"My Drive",
"created":"2019-09-25T19:39:33.841835", "created":"2019-09-25T19:39:33.841835",
"updated":"2019-09-25T19:39:33.841835", "updated":"2019-09-25T19:39:33.841835",
@ -57,64 +59,66 @@ Vary: Accept-Encoding
"thumbnail":false "thumbnail":false
} }
``` ```
So the `parentcode` we need is **"f25d8765a1cd407cb235961c73c268cf:USER_FILES"**
You can also find the code of a folder by browsing the folders in your FarmMaps account through the web interface.
The item code is the last part of the URL.
### Create folder In the list returned, search for item which ends with USER_IN, which is shown above.
Depending on how you want to organise things, you might choose to make a separate folder for the cropfield. This item will be the parent of the cropping scheme.
A folder can be created by creating an item with itemType `FOLDER`.
> **Note:** At the moment, subfolders can not be created directly under the root folder, create a folder through the web interface first. So make another call to check if a cropping scheme exist.
**Request** **Request**
Replace `<acces token>` with your actual token.
```http ```http
POST /api/v1/items HTTP/1.1 GET https://farmmaps.eu/api/v1/items/f25d8765a1cd407cb235961c73c268cf:USER_IN/children HTTP/1.1
Host: farmmaps.eu
Accept: application/json Accept: application/json
Authorization: Bearer <access token> Authorization: Bearer <access token>
Content-Type: application/json
Cache-Control: no-cache
Host: farmmaps.awacc.nl
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 210
{
"parentCode": "f25d8765a1cd407cb235961c73c268cf:USER_FILES",
"itemType": "FOLDER",
"name": "My_new_folder",
"data": {},
"dataDate": "2020-04-24T09:59:18.893Z",
"geometry": {},
"tags": [ "string" ]
}
``` ```
When the folder is created successfully we should recieve something like this: **Response**
The response will be something similar to:
**Response**
```http ```http
HTTP/1.1 200 OK
Date: Fri, 27 Aug 2021 19:17:36 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Server: Kestrel
Cache-Control: no-store,no-cache
Pragma: no-cache
Content-Length: 1519
{ {
"parentCode": "string", "parentCode": "f25d8765a1cd407cb235961c73c268cf:USER_IN",
"geometry": {}, "geometry": {
"data": {}, "type": "Point",
"tags": [ "coordinates": [
"string" 47.566119,
], 7.605974
"url": "string", ]
"code": "string", },
"name": "My_new_folder", "data": {},
"created": "2019-12-18T10:16:21.455Z", "tags": [],
"updated": "2019-12-18T10:16:21.455Z", "isEditable": false,
"dataDate": "2019-12-18T10:16:21.455Z", "url": "/api/v1/items/f3ee8e3ac55b43bc89757bcaedc89992",
"itemType": "string", "code": "f3ee8e3ac55b43bc89757bcaedc89992",
"sourceTask": "string", "name": "test scheme",
"size": 0, "created": "2021-08-27T19:11:40.195449Z",
"state": 0, "updated": "2021-08-27T19:11:40.195449Z",
"thumbnail": true "dataDate": null,
"dataEndDate": null,
"itemType": "vnd.farmmaps.itemtype.croppingscheme",
"sourceTask": null,
"size": 0,
"state": 0,
"thumbnail": false
} }
``` ```
When the list is empty, you need to create a new cropping scheme, which is described in another thread.
The `parentcode` we need for creating a crop field is **"f3ee8e3ac55b43bc89757bcaedc89992"**
### Create the cropfield ### Create the cropfield
Now we can create the cropfield. We do so by setting `"itemType": "vnd.farmmaps.itemtype.cropfield"` and adding data to the geometry parameter. Now we can create the cropfield. We do so by setting `"itemType": "vnd.farmmaps.itemtype.cropfield"` and adding data to the geometry parameter.
Generally, a cropfield contour would be defined as a polygon, so we add `"type":"Polygon" and all the coordinates. Generally, a cropfield contour would be defined as a polygon, so we add `"type":"Polygon" and all the coordinates.
@ -137,22 +141,19 @@ Content-Length: 916
{ {
"parentCode": "6601a06d812b40f9830c9fe4e63b1944", "parentCode": "6601a06d812b40f9830c9fe4e63b1944",
"itemType": "vnd.farmmaps.itemtype.cropfield", "itemType": "vnd.farmmaps.itemtype.cropfield",
"name": "cropfield for VRA", "name": "cropfield test",
"dataDate": "2019-1-18T10:16:21.455Z", "dataDate": "2021-1-18T00:00:0.0Z",
"dataEndDate": "2019-12-18T10:16:21.455Z", "dataEndDate": "2021-12-18T00:00:00.0Z",
"data": {}, "data": {},
"geometry": {"type":"Polygon","coordinates":[[[6.09942873984307,53.070025028087],[6.09992507404607,53.0705617890585],[6.10036959220086,53.0710679529031],[6.10065149010421,53.0714062774307],[6.10087493644271,53.0716712354474],[6.10091082982487,53.0716936039203],[6.10165087441291,53.0712041549161],[6.10204994718318,53.0709349338005],[6.10263143118855,53.0705789370018],[6.10311578125011,53.0702657538294],[6.10331686552072,53.0701314102389],[6.103326530575,53.070119463569],[6.10309137950343,53.0699829669055],[6.10184241586523,53.0692902201371],[6.10168497998891,53.0691984306747],[6.10092987659869,53.0694894453514],[6.09942873984307,53.070025028087]]]} "geometry": {"type":"Polygon","coordinates":[[[6.09942873984307,53.070025028087],[6.09992507404607,53.0705617890585],[6.10036959220086,53.0710679529031],[6.10065149010421,53.0714062774307],[6.10087493644271,53.0716712354474],[6.10091082982487,53.0716936039203],[6.10165087441291,53.0712041549161],[6.10204994718318,53.0709349338005],[6.10263143118855,53.0705789370018],[6.10311578125011,53.0702657538294],[6.10331686552072,53.0701314102389],[6.103326530575,53.070119463569],[6.10309137950343,53.0699829669055],[6.10184241586523,53.0692902201371],[6.10168497998891,53.0691984306747],[6.10092987659869,53.0694894453514],[6.09942873984307,53.070025028087]]]}
} }
``` ```
**Response** **Response**
When the cropfield is created, it should be visible through the FarmMaps web interface (under "My Drive" in the respective parent folder).
We should have the following response:
```http ```http
HTTP/1.1 201 Created HTTP/1.1 201 Created
Server: nginx/1.14.0 (Ubuntu) Server: nginx/1.14.0 (Ubuntu)
Date: Fri, 24 Apr 2020 08:56:45 GMT Date: Fri, 27 Aug 2021 19:21:36 GMT
Content-Type: application/json; charset=utf-8 Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked Transfer-Encoding: chunked
Connection: keep-alive Connection: keep-alive