private static bool GetFeatureClassTypes([NotNull] TextReader textReader, [NotNull] Matrix matrix) { string featureClassName = null; string featureClassFilter = null; int iRow = 0; while (true) { string matLine = textReader.ReadLine(); if (string.IsNullOrEmpty(matLine)) { foreach (FeatureTypeProps fcProps in matrix._featureClassTypes) { fcProps.SubType.FeatureClassFilter = featureClassFilter; } return(false); } string[] matStrings = matLine.Split(';'); string defString = matStrings[0].Trim(); string featureClassSubtype = matStrings[1].Trim(); string defaultDistance = matStrings[2]; string rightSideDistance = matStrings[3]; if (iRow == 0) { featureClassName = defString; } if (iRow == 1) { featureClassFilter = defString; } iRow++; FeatureTypeProps props = new FeatureTypeProps { SubType = new ConnectionType(Assert.NotNull(featureClassName), featureClassSubtype) }; props.CanOverlap = new List <int>(); props.DefaultDistance = double.Parse(defaultDistance); if (!string.IsNullOrWhiteSpace(rightSideDistance)) { props.RightSideDistance = double.Parse(rightSideDistance); } // TODO: verify size for (int iRefType = 0; iRefType < matrix._referenceTypes.Count; iRefType++) { string overlapString = matStrings[_matStart + iRefType].Trim(); if (overlapString == "x") { overlapString = "-1"; } props.CanOverlap.Add(int.Parse(overlapString)); } matrix._featureClassTypes = matrix._featureClassTypes ?? new List <FeatureTypeProps>(); matrix._featureClassTypes.Add(props); } }
private static Matrix InitMatrix( [NotNull] VectorDataset featureClassDataset, [CanBeNull] string featureClassFilter, [NotNull] VectorDataset referenceDataset, [CanBeNull] string referenceFilter, [NotNull] IList <int> referenceSubtypes, [NotNull] IList <string> featuresubtypeRules) { List <ConnectionType> refSubtypes = new List <ConnectionType>(); { GetSubtypes(referenceDataset, out string field, out IList <Subtype> refTypes); Assert.NotNull(refTypes); string reference = referenceDataset.Name; foreach (int referenceSubtype in referenceSubtypes) { string subtype = refTypes.First(x => x.Code == referenceSubtype).Name; refSubtypes.Add( new ConnectionType(reference, field, subtype, referenceSubtype) { FeatureClassFilter = referenceFilter }); } if (refSubtypes.Count == 0) { foreach (Subtype refType in refTypes) { refSubtypes.Add( new ConnectionType(reference, field, refType.Name, refType.Code) { FeatureClassFilter = referenceFilter }); } } } List <FeatureTypeProps> featureClassSubtypes = new List <FeatureTypeProps>(); { GetSubtypes(featureClassDataset, out string field, out IList <Subtype> fcTypes); Assert.NotNull(fcTypes); string featureclass = featureClassDataset.Name; foreach (string rule in featuresubtypeRules) { IList <string> ruleParts = rule.Split(';'); int fcSubtype = int.Parse(ruleParts[0]); string subtype = fcTypes.First(x => x.Code == fcSubtype).Name; List <int> canOverlaps = new List <int>(); foreach (int overlapIndex in EnumOverlapIndices( ruleParts, rule, referenceSubtypes)) { if (!int.TryParse(ruleParts[overlapIndex], out int canOverlap)) { throw new InvalidOperationException( $"Invalid overlap index '{ruleParts[overlapIndex]}' in featureSubtypeRule '{rule}'"); } canOverlaps.Add(canOverlap); } ConnectionType conn = new ConnectionType(featureclass, field, subtype, fcSubtype) { FeatureClassFilter = featureClassFilter }; FeatureTypeProps props = new FeatureTypeProps { SubType = conn, DefaultDistance = double.Parse(ruleParts[1]), CanOverlap = canOverlaps }; if (!string.IsNullOrWhiteSpace(ruleParts[2])) { props.RightSideDistance = double.Parse(ruleParts[2]); } featureClassSubtypes.Add(props); } if (featuresubtypeRules.Count == 0) { foreach (Subtype fcType in fcTypes) { ConnectionType conn = new ConnectionType(featureclass, field, fcType.Name, fcType.Code) { FeatureClassFilter = featureClassFilter }; featureClassSubtypes.Add(new FeatureTypeProps { SubType = conn, DefaultDistance = 1, CanOverlap = new List <int>(new int[refSubtypes.Count]) }); } } } return(new Matrix(featureClassSubtypes, refSubtypes)); }