aw7152: make lib open source, remove farmmaps dependencies
All checks were successful
FarmMaps.Develop/CarbonLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/CarbonLib/pipeline/head This commit looks good
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
using Base.Core.Common;
|
//using Base.Core.Common;
|
||||||
using Base.Core.Common.Geometry;
|
//using Base.Core.Common.Geometry;
|
||||||
using CarbonLib;
|
using CarbonLib;
|
||||||
using CarbonService.Models;
|
using CarbonService.Models;
|
||||||
using FarmMapsAPI.Carbon.Models;
|
using FarmMapsAPI.Carbon.Models;
|
||||||
@@ -2055,12 +2055,12 @@ namespace FarmMapsAPI.Carbon
|
|||||||
var climateVariable = new Dictionary<string, List<ClimateVariable>>();
|
var climateVariable = new Dictionary<string, List<ClimateVariable>>();
|
||||||
|
|
||||||
var farmPostalCode = farmInput.PostalCode;
|
var farmPostalCode = farmInput.PostalCode;
|
||||||
if (farmInput.geometry != null)
|
//if (farmInput.geometry != null)
|
||||||
{
|
//{
|
||||||
// determine poatalcode from geometry
|
// // determine poatalcode from geometry
|
||||||
string res = GetPostalCodeFromGeometry(farmInput.geometry);
|
// string res = GetPostalCodeFromGeometry(farmInput.geometry);
|
||||||
farmPostalCode = 8211;
|
// farmPostalCode = 8211;
|
||||||
}
|
//}
|
||||||
var farmZone = dataTransformationSet.KNMI_zone_Reg.SingleOrDefault(x => x.Reg.Contains(farmPostalCode)).KNMI_zone;
|
var farmZone = dataTransformationSet.KNMI_zone_Reg.SingleOrDefault(x => x.Reg.Contains(farmPostalCode)).KNMI_zone;
|
||||||
foreach (var field in farmInput.CropFields.Select(s => s.Name))
|
foreach (var field in farmInput.CropFields.Select(s => s.Name))
|
||||||
{
|
{
|
||||||
@@ -2106,12 +2106,12 @@ namespace FarmMapsAPI.Carbon
|
|||||||
}
|
}
|
||||||
|
|
||||||
var farmPostalCode = farmInput.PostalCode;
|
var farmPostalCode = farmInput.PostalCode;
|
||||||
if (farmInput.geometry != null)
|
//if (farmInput.geometry != null)
|
||||||
{
|
//{
|
||||||
// determine poatalcode from geometry
|
// // determine poatalcode from geometry
|
||||||
string res = GetPostalCodeFromGeometry(farmInput.geometry);
|
// string res = GetPostalCodeFromGeometry(farmInput.geometry);
|
||||||
farmPostalCode = 8211;
|
// farmPostalCode = 8211;
|
||||||
}
|
//}
|
||||||
|
|
||||||
var farmZone = dataTransformationSet.KNMI_zone_Reg.SingleOrDefault(x => x.Reg.Contains(farmPostalCode)).KNMI_zone;
|
var farmZone = dataTransformationSet.KNMI_zone_Reg.SingleOrDefault(x => x.Reg.Contains(farmPostalCode)).KNMI_zone;
|
||||||
// climate (zone, month, year)
|
// climate (zone, month, year)
|
||||||
@@ -2219,40 +2219,40 @@ namespace FarmMapsAPI.Carbon
|
|||||||
return carbonInputGreenManure;
|
return carbonInputGreenManure;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetPostalCodeFromGeometry(NetTopologySuite.Geometries.Geometry geometry)
|
//private static string GetPostalCodeFromGeometry(NetTopologySuite.Geometries.Geometry geometry)
|
||||||
{
|
//{
|
||||||
//// Set crs default geometry factory to EPSG:4326
|
// //// Set crs default geometry factory to EPSG:4326
|
||||||
NetTopologySuite.NtsGeometryServices.Instance = new NetTopologySuite.NtsGeometryServices(NetTopologySuite.Geometries.Implementation.CoordinateArraySequenceFactory.Instance,
|
// NetTopologySuite.NtsGeometryServices.Instance = new NetTopologySuite.NtsGeometryServices(NetTopologySuite.Geometries.Implementation.CoordinateArraySequenceFactory.Instance,
|
||||||
new PrecisionModel(PrecisionModels.Floating), 4326);
|
// new PrecisionModel(PrecisionModels.Floating), 4326);
|
||||||
// Register all vector drivers
|
// // Register all vector drivers
|
||||||
Ogr.RegisterAll();
|
// Ogr.RegisterAll();
|
||||||
|
|
||||||
// item.geometry is always in WGS84 so reproject to EPSG:28992
|
// // item.geometry is always in WGS84 so reproject to EPSG:28992
|
||||||
var localReference = new LocalReference("EPSG:28992");
|
// var localReference = new LocalReference("EPSG:28992");
|
||||||
var localGeometry = localReference.ToLocalPolygon(geometry as Polygon);
|
// var localGeometry = localReference.ToLocalPolygon(geometry as Polygon);
|
||||||
|
|
||||||
// get postal code from shape file
|
// // get postal code from shape file
|
||||||
// open shape file
|
// // open shape file
|
||||||
using (var postalcodes = Ogr.Open("config/PC4/PC4.shp", 0))
|
// using (var postalcodes = Ogr.Open("config/PC4/PC4.shp", 0))
|
||||||
{
|
// {
|
||||||
// get first layer
|
// // get first layer
|
||||||
var pc4Layer = postalcodes.GetLayerByIndex(0);
|
// var pc4Layer = postalcodes.GetLayerByIndex(0);
|
||||||
|
|
||||||
// set spatial filter to geometry ( only intersecting features are retrieved )
|
// // set spatial filter to geometry ( only intersecting features are retrieved )
|
||||||
pc4Layer.SetSpatialFilter(localGeometry.Centroid.ToOGRGeometry());
|
// pc4Layer.SetSpatialFilter(localGeometry.Centroid.ToOGRGeometry());
|
||||||
|
|
||||||
// get next feature
|
// // get next feature
|
||||||
var pc4Feature = pc4Layer.GetNextFeature();
|
// var pc4Feature = pc4Layer.GetNextFeature();
|
||||||
|
|
||||||
// if feature retrieved get the PC4 attribute from it
|
// // if feature retrieved get the PC4 attribute from it
|
||||||
if (pc4Feature is object)
|
// if (pc4Feature is object)
|
||||||
{
|
// {
|
||||||
return pc4Feature.GetFieldAsString("PC4");
|
// return pc4Feature.GetFieldAsString("PC4");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return "";
|
// return "";
|
||||||
}
|
//}
|
||||||
|
|
||||||
private string MapSoil(string soil)
|
private string MapSoil(string soil)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Base.Core.Common;
|
//using Base.Core.Common.Geometry;
|
||||||
using Base.Core.Common.Geometry;
|
|
||||||
using CarbonLib;
|
using CarbonLib;
|
||||||
using CarbonService.Models;
|
using CarbonService.Models;
|
||||||
using FarmMapsAPI.Carbon.Models;
|
using FarmMapsAPI.Carbon.Models;
|
||||||
@@ -2148,12 +2147,12 @@ namespace FarmMapsAPI.Carbon
|
|||||||
var climateVariable = new Dictionary<string, List<ClimateVariable>>();
|
var climateVariable = new Dictionary<string, List<ClimateVariable>>();
|
||||||
|
|
||||||
var farmPostalCode = farmInput.PostalCode;
|
var farmPostalCode = farmInput.PostalCode;
|
||||||
if (farmInput.geometry != null)
|
//if (farmInput.geometry != null)
|
||||||
{
|
//{
|
||||||
// determine poatalcode from geometry
|
// // determine poatalcode from geometry
|
||||||
string res = GetPostalCodeFromGeometry(farmInput.geometry);
|
// string res = GetPostalCodeFromGeometry(farmInput.geometry);
|
||||||
farmPostalCode = 8211;
|
// farmPostalCode = 8211;
|
||||||
}
|
//}
|
||||||
var farmZone = dataTransformationSet.KNMI_zone_Reg.SingleOrDefault(x => x.Reg.Contains(farmPostalCode)).KNMI_zone;
|
var farmZone = dataTransformationSet.KNMI_zone_Reg.SingleOrDefault(x => x.Reg.Contains(farmPostalCode)).KNMI_zone;
|
||||||
foreach (var field in farmInput.CropFields.Select(s => s.Name))
|
foreach (var field in farmInput.CropFields.Select(s => s.Name))
|
||||||
{
|
{
|
||||||
@@ -2199,12 +2198,12 @@ namespace FarmMapsAPI.Carbon
|
|||||||
}
|
}
|
||||||
|
|
||||||
var farmPostalCode = farmInput.PostalCode;
|
var farmPostalCode = farmInput.PostalCode;
|
||||||
if (farmInput.geometry != null)
|
//if (farmInput.geometry != null)
|
||||||
{
|
//{
|
||||||
// determine poatalcode from geometry
|
// // determine poatalcode from geometry
|
||||||
string res = GetPostalCodeFromGeometry(farmInput.geometry);
|
// string res = GetPostalCodeFromGeometry(farmInput.geometry);
|
||||||
farmPostalCode = 8211;
|
// farmPostalCode = 8211;
|
||||||
}
|
//}
|
||||||
|
|
||||||
var farmZone = dataTransformationSet.KNMI_zone_Reg.SingleOrDefault(x => x.Reg.Contains(farmPostalCode)).KNMI_zone;
|
var farmZone = dataTransformationSet.KNMI_zone_Reg.SingleOrDefault(x => x.Reg.Contains(farmPostalCode)).KNMI_zone;
|
||||||
// climate (zone, month, year)
|
// climate (zone, month, year)
|
||||||
@@ -2312,40 +2311,40 @@ namespace FarmMapsAPI.Carbon
|
|||||||
return carbonInputGreenManure;
|
return carbonInputGreenManure;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetPostalCodeFromGeometry(NetTopologySuite.Geometries.Geometry geometry)
|
//private static string GetPostalCodeFromGeometry(NetTopologySuite.Geometries.Geometry geometry)
|
||||||
{
|
//{
|
||||||
//// Set crs default geometry factory to EPSG:4326
|
// //// Set crs default geometry factory to EPSG:4326
|
||||||
NetTopologySuite.NtsGeometryServices.Instance = new NetTopologySuite.NtsGeometryServices(NetTopologySuite.Geometries.Implementation.CoordinateArraySequenceFactory.Instance,
|
// NetTopologySuite.NtsGeometryServices.Instance = new NetTopologySuite.NtsGeometryServices(NetTopologySuite.Geometries.Implementation.CoordinateArraySequenceFactory.Instance,
|
||||||
new PrecisionModel(PrecisionModels.Floating), 4326);
|
// new PrecisionModel(PrecisionModels.Floating), 4326);
|
||||||
// Register all vector drivers
|
// // Register all vector drivers
|
||||||
Ogr.RegisterAll();
|
// Ogr.RegisterAll();
|
||||||
|
|
||||||
// item.geometry is always in WGS84 so reproject to EPSG:28992
|
// // item.geometry is always in WGS84 so reproject to EPSG:28992
|
||||||
var localReference = new LocalReference("EPSG:28992");
|
// var localReference = new LocalReference("EPSG:28992");
|
||||||
var localGeometry = localReference.ToLocalPolygon(geometry as Polygon);
|
// var localGeometry = localReference.ToLocalPolygon(geometry as Polygon);
|
||||||
|
|
||||||
// get postal code from shape file
|
// // get postal code from shape file
|
||||||
// open shape file
|
// // open shape file
|
||||||
using (var postalcodes = Ogr.Open("config/PC4/PC4.shp", 0))
|
// using (var postalcodes = Ogr.Open("config/PC4/PC4.shp", 0))
|
||||||
{
|
// {
|
||||||
// get first layer
|
// // get first layer
|
||||||
var pc4Layer = postalcodes.GetLayerByIndex(0);
|
// var pc4Layer = postalcodes.GetLayerByIndex(0);
|
||||||
|
|
||||||
// set spatial filter to geometry ( only intersecting features are retrieved )
|
// // set spatial filter to geometry ( only intersecting features are retrieved )
|
||||||
pc4Layer.SetSpatialFilter(localGeometry.Centroid.ToOGRGeometry());
|
// pc4Layer.SetSpatialFilter(localGeometry.Centroid.ToOGRGeometry());
|
||||||
|
|
||||||
// get next feature
|
// // get next feature
|
||||||
var pc4Feature = pc4Layer.GetNextFeature();
|
// var pc4Feature = pc4Layer.GetNextFeature();
|
||||||
|
|
||||||
// if feature retrieved get the PC4 attribute from it
|
// // if feature retrieved get the PC4 attribute from it
|
||||||
if (pc4Feature is object)
|
// if (pc4Feature is object)
|
||||||
{
|
// {
|
||||||
return pc4Feature.GetFieldAsString("PC4");
|
// return pc4Feature.GetFieldAsString("PC4");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return "";
|
// return "";
|
||||||
}
|
//}
|
||||||
|
|
||||||
private string MapSoil(string soil)
|
private string MapSoil(string soil)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user