Skip to content

Commit

Permalink
Merge pull request #207 from ADAPT/develop
Browse files Browse the repository at this point in the history
Merge to master for release
  • Loading branch information
Stuart Rhea authored Feb 15, 2023
2 parents 1b98d4c + 2fc6108 commit 7284620
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ISOv4Plugin/Mappers/GridMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private void ImportRates(ISOTask task, GridDescriptor gridDescriptor, RasterGrid
prescription.OutOfFieldRate = ImportTreatmentZoneAsNumericRepValue(task.OutOfFieldTreatmentZone, null);
foreach (RxProductLookup rxProductLookup in prescription.RxProductLookups)
{
rxProductLookup.OutOfFieldRate = ImportTreatmentZoneAsNumericRepValue(task.PositionLostTreatmentZone, rxProductLookup);
rxProductLookup.OutOfFieldRate = ImportTreatmentZoneAsNumericRepValue(task.OutOfFieldTreatmentZone, rxProductLookup);
}
}

Expand Down
9 changes: 5 additions & 4 deletions ISOv4Plugin/Mappers/GuidancePatternMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,6 @@ public GuidancePattern ImportGuidancePattern(ISOGuidancePattern isoGuidancePatte
LineStringMapper lineStringMapper = new LineStringMapper(TaskDataMapper);
PointMapper pointMapper = new PointMapper(TaskDataMapper);
var isoLineString = isoGuidancePattern.LineString ?? new ISOLineString();
if (isoLineString.LineStringWidth.HasValue)
{
pattern.SwathWidth = ((int)isoLineString.LineStringWidth.Value).AsNumericRepresentationValue("mm");
}
switch (isoGuidancePattern.GuidancePatternType)
{
case ISOGuidancePatternType.AB:
Expand Down Expand Up @@ -318,6 +314,11 @@ public GuidancePattern ImportGuidancePattern(ISOGuidancePattern isoGuidancePatte
pattern.NumbersOfSwathsRight = (int?)(isoGuidancePattern.NumberOfSwathsRight);
pattern.OriginalEpsgCode = isoGuidancePattern.OriginalSRID;

if (isoLineString.LineStringWidth.HasValue)
{
pattern.SwathWidth = ((int)isoLineString.LineStringWidth.Value).AsNumericRepresentationValue("mm");
}

return pattern;
}

Expand Down
65 changes: 65 additions & 0 deletions ISOv4Plugin/Mappers/Manufacturers/CNH.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using AgGateway.ADAPT.ApplicationDataModel.Common;
using AgGateway.ADAPT.ApplicationDataModel.LoggedData;
using AgGateway.ADAPT.ApplicationDataModel.Products;
using AgGateway.ADAPT.ApplicationDataModel.Representations;
using AgGateway.ADAPT.ApplicationDataModel.Shapes;
using AgGateway.ADAPT.ISOv4Plugin.ExtensionMethods;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;

Expand Down Expand Up @@ -245,5 +248,67 @@ public IEnumerable<OperationData> PostProcessOperationData(TaskDataMapper taskDa
}
return result;
}

public void PostProcessPolygons(List<Polygon> polygons)
{
var groupedPolygons = polygons.GroupBy(x => x.ExteriorRing != null).ToDictionary(x => x.Key, x => x.ToList());
if (!groupedPolygons.TryGetValue(true, out var exteriorPolygons) ||
!groupedPolygons.TryGetValue(false, out var interiorPolygons))
{
return;
}

foreach (var exteriorPolygon in exteriorPolygons)
{
var exteriorRing = exteriorPolygon.ExteriorRing;
var boundingBox = new BoundingBox
{
MaxX = new NumericRepresentationValue(null, new NumericValue(null, exteriorRing.Points.Max(p => p.X))),
MinX = new NumericRepresentationValue(null, new NumericValue(null, exteriorRing.Points.Min(p => p.X))),
MaxY = new NumericRepresentationValue(null, new NumericValue(null, exteriorRing.Points.Max(p => p.Y))),
MinY = new NumericRepresentationValue(null, new NumericValue(null, exteriorRing.Points.Min(p => p.Y))),
};

foreach (var interiorPolygon in interiorPolygons)
{
if (interiorPolygon.InteriorRings == null || interiorPolygon.InteriorRings.Count <= 0)
{
continue;
}

// Test if a single point from interior polygon lies within exterior polygon
if (IsPointInPolygon(boundingBox, exteriorRing, interiorPolygon?.InteriorRings.First().Points.FirstOrDefault()))
{
exteriorPolygon.InteriorRings = exteriorPolygon.InteriorRings ?? new List<LinearRing>();
exteriorPolygon.InteriorRings.AddRange(interiorPolygon.InteriorRings);

polygons.Remove(interiorPolygon);
}
}
}
}

private bool IsPointInPolygon(BoundingBox boundingBox, LinearRing ring, Point testPoint)
{
if (testPoint.X < boundingBox.MinX.Value.Value || testPoint.X > boundingBox.MaxX.Value.Value ||
testPoint.Y < boundingBox.MinY.Value.Value || testPoint.Y > boundingBox.MaxY.Value.Value)
{
return false;
}

// Following code adapted from https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html
bool inside = false;
for (int i = 0, j = ring.Points.Count - 1; i < ring.Points.Count; j = i++)
{
var pointI = ring.Points[i];
var pointJ = ring.Points[j];
if ((pointI.Y > testPoint.Y) != (pointJ.Y > testPoint.Y) &&
testPoint.X < (pointJ.X - pointI.X) * (testPoint.Y - pointI.Y) / (pointJ.Y - pointI.Y) + pointI.X)
{
inside = !inside;
}
}
return inside;
}
}
}
2 changes: 2 additions & 0 deletions ISOv4Plugin/Mappers/Manufacturers/ManufacturerFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using AgGateway.ADAPT.ApplicationDataModel.LoggedData;
using AgGateway.ADAPT.ApplicationDataModel.Products;
using AgGateway.ADAPT.ApplicationDataModel.Shapes;
using AgGateway.ADAPT.ISOv4Plugin.ExtensionMethods;
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;

Expand All @@ -15,6 +16,7 @@ internal interface IManufacturer
string GetProductManufacturer(ISOProduct isoProduct);

IEnumerable<OperationData> PostProcessOperationData(TaskDataMapper taskDataMapper, IEnumerable<OperationData> operationDatas);
void PostProcessPolygons(List<Polygon> polygons);
}

internal static class ManufacturerFactory
Expand Down
7 changes: 7 additions & 0 deletions ISOv4Plugin/Mappers/PolygonMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using AgGateway.ADAPT.ApplicationDataModel.Common;
using AgGateway.ADAPT.ApplicationDataModel.Shapes;
using AgGateway.ADAPT.ISOv4Plugin.ISOEnumerations;
using AgGateway.ADAPT.ISOv4Plugin.Mappers.Manufacturers;

namespace AgGateway.ADAPT.ISOv4Plugin.Mappers
{
Expand All @@ -24,8 +25,11 @@ public interface IPolygonMapper

public class PolygonMapper : BaseMapper, IPolygonMapper
{
private readonly IManufacturer _manufacturer;

public PolygonMapper(TaskDataMapper taskDataMapper) : base(taskDataMapper, "PLN")
{
_manufacturer = ManufacturerFactory.GetManufacturer(taskDataMapper);
}

#region Export
Expand Down Expand Up @@ -129,6 +133,9 @@ public IEnumerable<Polygon> ImportBoundaryPolygons(IEnumerable<ISOPolygon> isoPo
adaptPolygons.AddRange(polygonOutput);
}
}

_manufacturer?.PostProcessPolygons(adaptPolygons);

return adaptPolygons;
}

Expand Down

0 comments on commit 7284620

Please sign in to comment.