예제 #1
0
 public static Position MapPoint(AgGateway.ADAPT.ApplicationDataModel.Shapes.Point point, AffineTransformation affineTransformation = null)
 {
     if (affineTransformation != null)
     {
         var movedPoint = AnonymizeUtils.MovePoint(point, affineTransformation);
         return(new Position(movedPoint.Y, movedPoint.X, point.Z));
     }
     else
     {
         return(new Position(point.Y, point.X, point.Z));
     }
 }
예제 #2
0
        public static GeoJSON.Net.Geometry.Point MapPoint2Point(AgGateway.ADAPT.ApplicationDataModel.Shapes.Point point, AffineTransformation affineTransformation = null)
        {
            Position position = null;

            if (affineTransformation != null)
            {
                var movedPoint = AnonymizeUtils.MovePoint(point, affineTransformation);
                position = new Position(movedPoint.Y, movedPoint.X, point.Z);
            }
            else
            {
                position = new Position(point.Y, point.X, point.Z);
            }
            return(new GeoJSON.Net.Geometry.Point(position));
        }
예제 #3
0
 public static AgGateway.ADAPT.ApplicationDataModel.Shapes.Point MapPosition(IPosition position, AffineTransformation affineTransformation = null)
 {
     if (affineTransformation != null)
     {
         var movedPosition = AnonymizeUtils.MovePosition(position, affineTransformation);
         return(new AgGateway.ADAPT.ApplicationDataModel.Shapes.Point
         {
             Y = movedPosition.Latitude,
             X = movedPosition.Longitude,
             Z = position.Altitude
         });
     }
     else
     {
         return(new AgGateway.ADAPT.ApplicationDataModel.Shapes.Point
         {
             Y = position.Latitude,
             X = position.Longitude,
             Z = position.Altitude
         });
     }
 }
예제 #4
0
        public void Export(ApplicationDataModel dataModel, string exportPath, Properties properties = null)
        {
            ParseExportProperties(properties);

            if (!Directory.Exists(exportPath))
            {
                Directory.CreateDirectory(exportPath);
            }

            // Path of exportfolder: "PluginFolder - [Name of Catalog]"
            var newPath = Path.Combine(exportPath, InfoFileConstants.PluginFolderPrefix + "-" + ZipUtils.GetSafeName(dataModel.Catalog.Description));

            // ToDo: add more meta data of this export
            _JsonExporter.WriteInfoFile(newPath, Name, Version, dataModel.Catalog.Description, CustomProperties);

            switch (CustomProperties.ApplyingAnonymiseValuesPer)
            {
            case ApplyingAnonymiseValuesEnum.PerField:
                foreach (var fieldId in dataModel.Catalog.Fields.Select(f => f.Id.ReferenceId))
                {
                    List <int> workRecordIds =
                        dataModel.Documents.WorkRecords
                        .Where(wr => wr.FieldIds.Contains(fieldId))
                        .Select(wr => wr.Id.ReferenceId)
                        .ToList();

                    if (CustomProperties.Anonymise)
                    {
                        // Randomize the Anonymization values
                        AnonymizeUtils.GenerateRandomAffineTransformation(CustomProperties);
                    }
                    ;

                    // OperationDataMapper
                    // ToDo: replace with OperationDataMapper
                    //var workRecordDtos = workRecordsMapper.MapAll(workRecordIds);
                    //_JsonExporter.WriteWorkRecordDtos(newPath, workRecordDtos);

                    // FieldBoundaryMapper
                    // ToDo: FieldBoundaryMapper.MapAsSingleFeature([fieldId])

                    // GuidanceGroupMapper
                    // ToDo: GuidanceGroupMapper.MapAs...([all GuidanceGroups for fieldId])

                    // WorkItemOperationMapper
                    // ToDo: WorkItemOperationMapper.MapAs...([all WorkItemOperations for fieldId])
                }
                break;

            case ApplyingAnonymiseValuesEnum.PerWorkRecord:
                foreach (var workRecord in dataModel.Documents.WorkRecords)
                {
                    if (CustomProperties.Anonymise)
                    {
                        // Randomize the Anonymization values
                        AnonymizeUtils.GenerateRandomAffineTransformation(CustomProperties);
                    }
                    ;

                    // OperationDataMapper
                    // ToDo: replace with OperationDataMapper
                    //WorkRecordDto workRecordDto_mapped = workRecordsMapper.MapSingle(workRecord);
                    //_JsonExporter.WriteWorkRecordDto(newPath, workRecordDto_mapped);

                    // FieldBoundaryMapper
                    // ToDo: FieldBoundaryMapper.MapAsMultipleFeatures([all FieldBoundaries for workRecord.Id])

                    // GuidanceGroupMapper
                    // ToDo: GuidanceGroupMapper.MapAs...([all GuidanceGroups for workRecord.Id])

                    // WorkItemOperationMapper
                    // ToDo: GuidanceGroupMapper.MapAs...([all WorkItemOperations for workRecord.Id])
                }
                break;

            default:
                if (CustomProperties.Anonymise)
                {
                    // Randomize the Anonymization values
                    AnonymizeUtils.GenerateRandomAffineTransformation(CustomProperties);
                }
                ;
                foreach (var workRecord in dataModel.Documents.WorkRecords)
                {
                    // OperationDataMapper
                    // ToDo: OperationDataMapper.MapAsFeatureCollection([workRecord])
                }
                FieldBoundaryMapper fieldBoundaryMapper = new FieldBoundaryMapper(CustomProperties, dataModel);
                foreach (var fieldBoundary in dataModel.Catalog.FieldBoundaries)
                {
                    // FieldBoundaryMapper
                    Feature fieldBoundaryFeature  = fieldBoundaryMapper.MapAsSingleFeature(fieldBoundary);
                    string  fileNamePrescriptions = FieldBoundaryMapper.GetFieldBoundaryPrefix();
                    if (fieldBoundaryFeature.Properties.ContainsKey("FieldId"))
                    {
                        fileNamePrescriptions = fileNamePrescriptions + "_for_field_" + fieldBoundaryFeature.Properties["FieldId"];
                    }
                    else if (fieldBoundaryFeature.Properties.ContainsKey("Guid"))
                    {
                        fileNamePrescriptions = fileNamePrescriptions + "_" + fieldBoundaryFeature.Properties["Guid"];
                    }
                    else
                    {
                        fileNamePrescriptions = fileNamePrescriptions + "_" + Guid.NewGuid();
                    }

                    _JsonExporter.WriteAsGeoJson(newPath, new List <Feature>()
                    {
                        fieldBoundaryFeature
                    }, fileNamePrescriptions);


                    // DrivenHeadlandMapper
                    foreach (Headland headland in fieldBoundary.Headlands)
                    {
                        if (headland is DrivenHeadland)
                        {
                            DrivenHeadlandMapper drivenHeadlandMapper = new DrivenHeadlandMapper(CustomProperties, dataModel);
                            Feature drivenHeadlandFeature             = drivenHeadlandMapper.MapAsSingleFeature(headland as DrivenHeadland, fieldBoundaryFeature);
                            if (drivenHeadlandFeature == null)
                            {
                                drivenHeadlandMapper = null;
                            }
                            else
                            {
                                string drivenHeadlandFileName = DrivenHeadlandMapper.GetPrefix();
                                if (drivenHeadlandFeature.Properties.ContainsKey("FieldId"))
                                {
                                    drivenHeadlandFileName += "_for_field_" + drivenHeadlandFeature.Properties["FieldId"];
                                }
                                _JsonExporter.WriteAsGeoJson(newPath, new List <Feature>()
                                {
                                    drivenHeadlandFeature
                                }, drivenHeadlandFileName);
                            }
                        }
                    }
                }
                GuidanceGroupMapper guidanceGroupMapper = new GuidanceGroupMapper(CustomProperties, dataModel);
                foreach (var guidanceGroup in dataModel.Catalog.GuidanceGroups)
                {
                    // GuidanceGroupMapper
                    List <Feature> guidanceGroupFeatures = guidanceGroupMapper.MapAsMultipleFeatures(guidanceGroup);
                    string         fileNameGuidanceGroup = GuidanceGroupMapper.GetPrefix();
                    if (guidanceGroupFeatures[0] != null)
                    {
                        if (guidanceGroupFeatures[0].Properties.ContainsKey("GuidancePatternType"))
                        {
                            fileNameGuidanceGroup = fileNameGuidanceGroup + "_type_" + guidanceGroupFeatures[0].Properties["GuidancePatternType"];
                        }
                        if (guidanceGroupFeatures[0].Properties.ContainsKey("FieldId"))
                        {
                            fileNameGuidanceGroup = fileNameGuidanceGroup + "_for_field_" + guidanceGroupFeatures[0].Properties["FieldId"];
                        }
                        else if (guidanceGroupFeatures[0].Properties.ContainsKey("Guid"))
                        {
                            fileNameGuidanceGroup = fileNameGuidanceGroup + "_" + guidanceGroupFeatures[0].Properties["Guid"];
                        }
                        else
                        {
                            fileNameGuidanceGroup = fileNameGuidanceGroup + "_" + Guid.NewGuid();
                        }
                    }

                    _JsonExporter.WriteAsGeoJson(newPath, guidanceGroupFeatures, fileNameGuidanceGroup);
                }

                //Prescriptions (without gridType)
                List <Feature>     prescriptionFeatures       = new List <Feature>();
                List <Feature>     prescriptionFeaturesSingle = new List <Feature>();
                PrescriptionMapper prescriptionMapper         = new PrescriptionMapper(CustomProperties, dataModel);
                foreach (var workItemOperation in dataModel.Documents.WorkItemOperations)
                {
                    Console.WriteLine("WorkItemOperation: " + workItemOperation.Description + " OperationType " + workItemOperation.OperationType);

                    Prescription adaptPrescription = dataModel.Catalog.Prescriptions.Where(f => f.Id.ReferenceId == workItemOperation.PrescriptionId).FirstOrDefault();
                    if (adaptPrescription != null)
                    {
                        // single
                        var prescriptionFeature = prescriptionMapper.MapAsSingleFeature(adaptPrescription);
                        if (prescriptionFeature != null)
                        {
                            prescriptionFeature.Properties.Add("OperationType", Enum.GetName(typeof(OperationTypeEnum), workItemOperation.OperationType));                                      // Enum:
                            //workItemOperationFeature.Properties.Add("Description", workItemOperation.Description);
                            //workItemOperationFeature.Properties.Add("ID", workItemOperation.Id);
                            prescriptionFeaturesSingle.Add(prescriptionFeature);
                        }
                        else
                        {
                            Console.WriteLine("prescriptionFeature single null for: " + workItemOperation.PrescriptionId);
                        }

                        // multiple
                        var features = prescriptionMapper.MapAsMultipleFeatures(adaptPrescription);
                        if (features != null && features.Count > 0)
                        {
                            prescriptionFeatures.AddRange(features);
                        }
                        else
                        {
                            Console.WriteLine("prescriptionFeatures null or empty for: " + workItemOperation.PrescriptionId);
                        }
                    }
                    else
                    {
                        Console.WriteLine("adaptPrescription not found : " + workItemOperation.PrescriptionId);
                    }
                }

                // Todo: [Check] if all dataModel.Catalog.Prescriptions has been mapped
                if (dataModel.Catalog.Prescriptions.Count() != dataModel.Documents.WorkItemOperations.Count())
                {
                    Console.WriteLine("Count prescriptions and WorkItemOperations differ: " + dataModel.Catalog.Prescriptions.Count() + " " + dataModel.Documents.WorkItemOperations.Count());
                }
                //else
                //	Console.WriteLine("Count prescriptions and WorkItemOperations same: " + dataModel.Catalog.Prescriptions.Count() + " " + dataModel.Documents.WorkItemOperations.Count());

                string fileNamePs;
                // @ToDo only when count > 0?
                fileNamePs = PrescriptionMapper.GetWorkItemOperationPrefix();
                fileNamePs = fileNamePs + "_single_" + Guid.NewGuid();
                _JsonExporter.WriteAsGeoJson(newPath, prescriptionFeaturesSingle, fileNamePs);

                string fileNamePm;
                fileNamePm = PrescriptionMapper.GetWorkItemOperationPrefix();
                fileNamePm = fileNamePm + "_" + Guid.NewGuid();
                _JsonExporter.WriteAsGeoJson(newPath, prescriptionFeatures, fileNamePm);

                // LoggedData
                OperationTimelogMapper operationTimelogMapper = new OperationTimelogMapper(CustomProperties, dataModel);

                // starting from workRecords --> Not doing this as some loggedData may have not been referenced in a workrecord; we want to catch all logged data in the adm
                // starting from LoggedData
                foreach (var loggedData in dataModel.Documents.LoggedData)
                {
                    foreach (OperationData operation in loggedData.OperationData)
                    {
                        Console.WriteLine("OperationTimelog - operationData: " + operation.Id.ReferenceId + " " + operation.OperationType + " maxDepth " + operation.MaxDepth);

                        IEnumerable <SpatialRecord> spatialRecords = operation.GetSpatialRecords != null?operation.GetSpatialRecords() : null;

                        if (spatialRecords != null && spatialRecords.Any())                                 //No need to export a timelog if no data
                        {
                            var operationTimelogFeatures = operationTimelogMapper.MapMultiple(operation, spatialRecords);



                            string fileNameL = OperationTimelogMapper.GetPrefix() + "_" + operation.OperationType + "_" + Guid.NewGuid();
                            _JsonExporter.WriteAsGeoJson(newPath, operationTimelogFeatures, fileNameL);
                        }
                    }
                }

                break;                         // Default ApplyingAnonymiseValuesPer switch
            }
        }