public static IGeometry GetShapeCopy([NotNull] IRow row) { if (row is IFeature) { var feature = (IFeature)row; // TODO optimize // - feature.Extent creates a copy (feature.Shape.QueryEnvelope() does not) // - the feature may really have no geometry (shapefield was in subfields), in this case the additional get just makes it slow if (feature.Extent.IsEmpty) { // this may be the case when the ShapeField was not queried (i.e. QueryFilter.SubFields = 'OID, Field') if (row.HasOID && row.Table.HasOID) { feature = GdbQueryUtils.GetFeature((IFeatureClass)row.Table, row.OID); if (feature != null) { return(feature.ShapeCopy); } } } else { return(feature.ShapeCopy); } } return(null); }
public void CanGetNullForNonExistingFeatureFastEnough() { IFeatureWorkspace ws = OpenTestWorkspace(); IFeatureClass fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE"); const int iterations = 200; var watch = new Stopwatch(); watch.Start(); for (var iteration = 0; iteration < iterations; iteration++) { int oid = 999999999 + iteration; Assert.Null(GdbQueryUtils.GetFeature(fc, oid)); } watch.Stop(); double msPerIteration = watch.ElapsedMilliseconds / (double)iterations; _msg.InfoFormat(@"GetFeature() per iteration: {0} ms", msPerIteration); const int maxMilliseconds = 35; Assert.True(msPerIteration < maxMilliseconds, "GetFeature with non-existing feature takes too long ({0} ms)", msPerIteration); }
public void CanGetExistingFeaturesFastEnough() { IFeatureWorkspace ws = OpenTestWorkspace(); IFeatureClass fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE"); const int count = 100; IDictionary <int, IRow> rows = GetFirstNRows((ITable)fc, count); var watch = new Stopwatch(); watch.Start(); foreach (int oid in rows.Keys) { Assert.NotNull(GdbQueryUtils.GetFeature(fc, oid)); _msg.Info($"Oid {oid} time: {watch.ElapsedMilliseconds}"); } watch.Stop(); double msPerIteration = watch.ElapsedMilliseconds / (double)rows.Count; _msg.InfoFormat(@"GetFeature() per iteration: {0} ms", msPerIteration); Assert.True(msPerIteration < 50, "GetFeature with existing feature takes too long ({0} ms)", msPerIteration); }
public void CanGetNullForNonExistingFeature() { IFeatureWorkspace ws = OpenTestWorkspace(); IFeatureClass fc = ws.OpenFeatureClass("TOPGIS_TLM.TLM_STRASSE"); Assert.Null(GdbQueryUtils.GetFeature(fc, 999999999)); }