Include field contour in ISOXML generation from GeoJSON
Closed this issue · 3 comments
Hi,
I am using isoxml-js to convert spraying maps from GeoJSON to ISOXML. I am using the example script create.ts
, and check the results using https://isoxml-viewer.dev4ag.com/.
I addition to the treatment areas that are already covered in the example, I would like to include the contour of the field in the ISOXML file, and I am having trouble with this.
This is very probably not an error but rather me missing a step when building the ISOXML. I tried searching through the code to understand what I am doing wrong, but I think I only scratched the surface this far. If this isn't too much effort, any help would be appreciated!
In order to include the field contour, starting from create.ts
, I tried adding either a partField
entity or an ExtendedPolygon
entity to the isoxmlManager
by adding the code below before saving ISOXML as zip file. But the field contour still isn't visible when viewing the resulting file in isoxml-viewer.
const geoJSONfieldData = JSON.parse(readFileSync(join(__dirname, '../data/contour2.geojson'), 'utf-8'))
const partField = isoxmlManager.createEntityFromAttributes(TAGS.Partfield, {
PartfieldDesignator: "field"
}) as ExtendedPartfield
partField.boundaryFromGeoJSON(geoJSONfieldData, isoxmlManager)
isoxmlManager.registerEntity(partField)
isoxmlManager.rootElement.attributes.Partfield = [partField]
Or
const geoJSONfieldData = JSON.parse(readFileSync(join(__dirname, '../data/contour2.geojson'), 'utf-8'))
const polygon = ExtendedPolygon.fromGeoJSON(geoJSONfieldData, PolygonPolygonTypeEnum.Mainfield, isoxmlManager)[0]
isoxmlManager.registerEntity(polygon)
I will keep investigating on my side. Many thanks in advance,
Thibaut
@tvoirand The first approach (with partfield creation) looks good to me, the second one (with polygon creation) is not quite correct because you don't create a partfield, only geometry not linked with anything in the ISOXML file.
What is missing in your snippet is adding a reference to your partfield into your task:
....
const partFieldRef = isoxmlManager.registerEntity(partField)
task.attributes.PartfieldIdRef = partFieldRef
...
This link is important - if your partfield is not linked to any task, it can't be used properly. For example, in ISOXML Visualization tool, we start iterate over tasks and show only partfields linked to those tasks. We ignore all the partfields that are not linked to any task.
Could you please try the fix above and tell me if it works? If not, I'll create a separate working example for creating tasks with partfields...
@aparshin I tried this fix and it works correctly. Thank you!
Duly noted for your explanation about linking partfield to a task.
By the way, I now realize that there's already an example illustrating this in create_partfield.ts
. Even though this other example doesn't combine partfield and grid creation in the same task, the information I missed about linking partfield was there, and I would have solved my problem if I had read all usage examples before looking at the code.
Thanks again for your help.