Geometry hook
Posted: Mon 23 Jul 2018 14:12
Hi
An unusual inquiry that most likely requires a developer to answer.
We have very complex geometries. Sometimes NetTopologySuite fails to do intersection/differences in a robust way.
What we have done so far is to pass the calculation on to Oracle and let Oracle do the calculations using Oracles more advanced spatial engine. Its a rare case so performance is not a concern.
We have implemented an extension method on the DBGeometry type, but this is a pain since team members need to remember to use this and not the build in methods.
What we´re looking for i to extend the NTS spatial provider like below.
public class CustomNetTopologySuiteSpatialServices : EntityNetTopologySuiteSpatialServices
{
...
public override DbGeometry Intersection(DbGeometry geometryValue, DbGeometry otherGeometry)
{
var result = base.Intersection(geometryValue, otherGeometry);
if (!result.IsValid)
{
// Call Oracle
}
return result;
}
}
I.e. let NTS do the job and if it cannot then ask Oracle to do this.
The problem is to register this custom slightly extended version with EntityFramework. There does not seem to be any really good way. Since all config objects are Singletons there is no way to derive these.
The only way I´ve found so far is to enherit from DbConfiguration and in the constructor use reflection to do what Devart implementation does internally. Like so.
public class DataModelConfiguration : DbConfiguration
{
public DataModelConfiguration()
{
var result = typeof(EntitySpatialServices).GetMethods(BindingFlags.NonPublic | BindingFlags.Static);
var method = result.FirstOrDefault(x => x.GetParameters().Select(y
=>y.ParameterType).Contains(typeof(EntitySpatialServices)));
method.Invoke(this, new object[] { new CustomNetTopologySuiteSpatialServices() });
}
}
This of course is using non public API which we really does not like since this potentially would compromise upgrading.
Is there a way to accomplish such a task using only public API.
An unusual inquiry that most likely requires a developer to answer.
We have very complex geometries. Sometimes NetTopologySuite fails to do intersection/differences in a robust way.
What we have done so far is to pass the calculation on to Oracle and let Oracle do the calculations using Oracles more advanced spatial engine. Its a rare case so performance is not a concern.
We have implemented an extension method on the DBGeometry type, but this is a pain since team members need to remember to use this and not the build in methods.
What we´re looking for i to extend the NTS spatial provider like below.
public class CustomNetTopologySuiteSpatialServices : EntityNetTopologySuiteSpatialServices
{
...
public override DbGeometry Intersection(DbGeometry geometryValue, DbGeometry otherGeometry)
{
var result = base.Intersection(geometryValue, otherGeometry);
if (!result.IsValid)
{
// Call Oracle
}
return result;
}
}
I.e. let NTS do the job and if it cannot then ask Oracle to do this.
The problem is to register this custom slightly extended version with EntityFramework. There does not seem to be any really good way. Since all config objects are Singletons there is no way to derive these.
The only way I´ve found so far is to enherit from DbConfiguration and in the constructor use reflection to do what Devart implementation does internally. Like so.
public class DataModelConfiguration : DbConfiguration
{
public DataModelConfiguration()
{
var result = typeof(EntitySpatialServices).GetMethods(BindingFlags.NonPublic | BindingFlags.Static);
var method = result.FirstOrDefault(x => x.GetParameters().Select(y
=>y.ParameterType).Contains(typeof(EntitySpatialServices)));
method.Invoke(this, new object[] { new CustomNetTopologySuiteSpatialServices() });
}
}
This of course is using non public API which we really does not like since this potentially would compromise upgrading.
Is there a way to accomplish such a task using only public API.