diff --git a/CarbonCalculation24.cs b/CarbonCalculation24.cs index eae6e58..d729fe4 100644 --- a/CarbonCalculation24.cs +++ b/CarbonCalculation24.cs @@ -1,5 +1,5 @@ -using Base.Core.Common; -using Base.Core.Common.Geometry; +//using Base.Core.Common; +//using Base.Core.Common.Geometry; using CarbonLib; using CarbonService.Models; using FarmMapsAPI.Carbon.Models; @@ -2055,12 +2055,12 @@ namespace FarmMapsAPI.Carbon var climateVariable = new Dictionary>(); var farmPostalCode = farmInput.PostalCode; - if (farmInput.geometry != null) - { - // determine poatalcode from geometry - string res = GetPostalCodeFromGeometry(farmInput.geometry); - farmPostalCode = 8211; - } + //if (farmInput.geometry != null) + //{ + // // determine poatalcode from geometry + // string res = GetPostalCodeFromGeometry(farmInput.geometry); + // farmPostalCode = 8211; + //} var farmZone = dataTransformationSet.KNMI_zone_Reg.SingleOrDefault(x => x.Reg.Contains(farmPostalCode)).KNMI_zone; foreach (var field in farmInput.CropFields.Select(s => s.Name)) { @@ -2106,12 +2106,12 @@ namespace FarmMapsAPI.Carbon } var farmPostalCode = farmInput.PostalCode; - if (farmInput.geometry != null) - { - // determine poatalcode from geometry - string res = GetPostalCodeFromGeometry(farmInput.geometry); - farmPostalCode = 8211; - } + //if (farmInput.geometry != null) + //{ + // // determine poatalcode from geometry + // string res = GetPostalCodeFromGeometry(farmInput.geometry); + // farmPostalCode = 8211; + //} var farmZone = dataTransformationSet.KNMI_zone_Reg.SingleOrDefault(x => x.Reg.Contains(farmPostalCode)).KNMI_zone; // climate (zone, month, year) @@ -2219,40 +2219,40 @@ namespace FarmMapsAPI.Carbon return carbonInputGreenManure; } - private static string GetPostalCodeFromGeometry(NetTopologySuite.Geometries.Geometry geometry) - { - //// Set crs default geometry factory to EPSG:4326 - NetTopologySuite.NtsGeometryServices.Instance = new NetTopologySuite.NtsGeometryServices(NetTopologySuite.Geometries.Implementation.CoordinateArraySequenceFactory.Instance, - new PrecisionModel(PrecisionModels.Floating), 4326); - // Register all vector drivers - Ogr.RegisterAll(); + //private static string GetPostalCodeFromGeometry(NetTopologySuite.Geometries.Geometry geometry) + //{ + // //// Set crs default geometry factory to EPSG:4326 + // NetTopologySuite.NtsGeometryServices.Instance = new NetTopologySuite.NtsGeometryServices(NetTopologySuite.Geometries.Implementation.CoordinateArraySequenceFactory.Instance, + // new PrecisionModel(PrecisionModels.Floating), 4326); + // // Register all vector drivers + // Ogr.RegisterAll(); - // item.geometry is always in WGS84 so reproject to EPSG:28992 - var localReference = new LocalReference("EPSG:28992"); - var localGeometry = localReference.ToLocalPolygon(geometry as Polygon); + // // item.geometry is always in WGS84 so reproject to EPSG:28992 + // var localReference = new LocalReference("EPSG:28992"); + // var localGeometry = localReference.ToLocalPolygon(geometry as Polygon); - // get postal code from shape file - // open shape file - using (var postalcodes = Ogr.Open("config/PC4/PC4.shp", 0)) - { - // get first layer - var pc4Layer = postalcodes.GetLayerByIndex(0); + // // get postal code from shape file + // // open shape file + // using (var postalcodes = Ogr.Open("config/PC4/PC4.shp", 0)) + // { + // // get first layer + // var pc4Layer = postalcodes.GetLayerByIndex(0); - // set spatial filter to geometry ( only intersecting features are retrieved ) - pc4Layer.SetSpatialFilter(localGeometry.Centroid.ToOGRGeometry()); + // // set spatial filter to geometry ( only intersecting features are retrieved ) + // pc4Layer.SetSpatialFilter(localGeometry.Centroid.ToOGRGeometry()); - // get next feature - var pc4Feature = pc4Layer.GetNextFeature(); + // // get next feature + // var pc4Feature = pc4Layer.GetNextFeature(); - // if feature retrieved get the PC4 attribute from it - if (pc4Feature is object) - { - return pc4Feature.GetFieldAsString("PC4"); - } - } + // // if feature retrieved get the PC4 attribute from it + // if (pc4Feature is object) + // { + // return pc4Feature.GetFieldAsString("PC4"); + // } + // } - return ""; - } + // return ""; + //} private string MapSoil(string soil) { diff --git a/CarbonCalculation25.cs b/CarbonCalculation25.cs index 008f3b7..cca81f3 100644 --- a/CarbonCalculation25.cs +++ b/CarbonCalculation25.cs @@ -1,5 +1,4 @@ -using Base.Core.Common; -using Base.Core.Common.Geometry; +//using Base.Core.Common.Geometry; using CarbonLib; using CarbonService.Models; using FarmMapsAPI.Carbon.Models; @@ -2148,12 +2147,12 @@ namespace FarmMapsAPI.Carbon var climateVariable = new Dictionary>(); var farmPostalCode = farmInput.PostalCode; - if (farmInput.geometry != null) - { - // determine poatalcode from geometry - string res = GetPostalCodeFromGeometry(farmInput.geometry); - farmPostalCode = 8211; - } + //if (farmInput.geometry != null) + //{ + // // determine poatalcode from geometry + // string res = GetPostalCodeFromGeometry(farmInput.geometry); + // farmPostalCode = 8211; + //} var farmZone = dataTransformationSet.KNMI_zone_Reg.SingleOrDefault(x => x.Reg.Contains(farmPostalCode)).KNMI_zone; foreach (var field in farmInput.CropFields.Select(s => s.Name)) { @@ -2199,12 +2198,12 @@ namespace FarmMapsAPI.Carbon } var farmPostalCode = farmInput.PostalCode; - if (farmInput.geometry != null) - { - // determine poatalcode from geometry - string res = GetPostalCodeFromGeometry(farmInput.geometry); - farmPostalCode = 8211; - } + //if (farmInput.geometry != null) + //{ + // // determine poatalcode from geometry + // string res = GetPostalCodeFromGeometry(farmInput.geometry); + // farmPostalCode = 8211; + //} var farmZone = dataTransformationSet.KNMI_zone_Reg.SingleOrDefault(x => x.Reg.Contains(farmPostalCode)).KNMI_zone; // climate (zone, month, year) @@ -2312,40 +2311,40 @@ namespace FarmMapsAPI.Carbon return carbonInputGreenManure; } - private static string GetPostalCodeFromGeometry(NetTopologySuite.Geometries.Geometry geometry) - { - //// Set crs default geometry factory to EPSG:4326 - NetTopologySuite.NtsGeometryServices.Instance = new NetTopologySuite.NtsGeometryServices(NetTopologySuite.Geometries.Implementation.CoordinateArraySequenceFactory.Instance, - new PrecisionModel(PrecisionModels.Floating), 4326); - // Register all vector drivers - Ogr.RegisterAll(); + //private static string GetPostalCodeFromGeometry(NetTopologySuite.Geometries.Geometry geometry) + //{ + // //// Set crs default geometry factory to EPSG:4326 + // NetTopologySuite.NtsGeometryServices.Instance = new NetTopologySuite.NtsGeometryServices(NetTopologySuite.Geometries.Implementation.CoordinateArraySequenceFactory.Instance, + // new PrecisionModel(PrecisionModels.Floating), 4326); + // // Register all vector drivers + // Ogr.RegisterAll(); - // item.geometry is always in WGS84 so reproject to EPSG:28992 - var localReference = new LocalReference("EPSG:28992"); - var localGeometry = localReference.ToLocalPolygon(geometry as Polygon); + // // item.geometry is always in WGS84 so reproject to EPSG:28992 + // var localReference = new LocalReference("EPSG:28992"); + // var localGeometry = localReference.ToLocalPolygon(geometry as Polygon); - // get postal code from shape file - // open shape file - using (var postalcodes = Ogr.Open("config/PC4/PC4.shp", 0)) - { - // get first layer - var pc4Layer = postalcodes.GetLayerByIndex(0); + // // get postal code from shape file + // // open shape file + // using (var postalcodes = Ogr.Open("config/PC4/PC4.shp", 0)) + // { + // // get first layer + // var pc4Layer = postalcodes.GetLayerByIndex(0); - // set spatial filter to geometry ( only intersecting features are retrieved ) - pc4Layer.SetSpatialFilter(localGeometry.Centroid.ToOGRGeometry()); + // // set spatial filter to geometry ( only intersecting features are retrieved ) + // pc4Layer.SetSpatialFilter(localGeometry.Centroid.ToOGRGeometry()); - // get next feature - var pc4Feature = pc4Layer.GetNextFeature(); + // // get next feature + // var pc4Feature = pc4Layer.GetNextFeature(); - // if feature retrieved get the PC4 attribute from it - if (pc4Feature is object) - { - return pc4Feature.GetFieldAsString("PC4"); - } - } + // // if feature retrieved get the PC4 attribute from it + // if (pc4Feature is object) + // { + // return pc4Feature.GetFieldAsString("PC4"); + // } + // } - return ""; - } + // return ""; + //} private string MapSoil(string soil) { diff --git a/Helper.cs b/Helper.cs new file mode 100644 index 0000000..60718cf --- /dev/null +++ b/Helper.cs @@ -0,0 +1,13 @@ +using System.IO; + +namespace CarbonLib +{ + public class Helper + { + public static string GetPlatformIndependentDirectoryPath(string path) + { + return path.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + } + + } +}