public static void WriteParamData(EpsgData data, BinaryWriter writerText, Func <ushort, BinaryWriter> paramFileGenerator) { var stringLookUp = WriteTextDictionary(data, writerText, data.Repository.ParamTextValues.DistinctNonEmptyStrings() ); foreach (var coordinateOpMethod in data.Repository.CoordinateOperationMethods) { var usedBy = coordinateOpMethod.UsedBy.OrderBy(x => x.Code).ToList(); using (var writerData = paramFileGenerator((ushort)coordinateOpMethod.Code)) { var paramUses = coordinateOpMethod.ParamUse.OrderBy(x => x.SortOrder).ToList(); writerData.Write((byte)paramUses.Count); foreach (var paramUse in paramUses) { writerData.Write((ushort)paramUse.Parameter.Code); writerData.Write((byte)(paramUse.SignReversal.GetValueOrDefault() ? 0x01 : 0x02)); } writerData.Write((ushort)usedBy.Count); foreach (var coordinateOperation in usedBy) { writerData.Write((ushort)coordinateOperation.Code); var paramValues = coordinateOperation.ParameterValues.ToList(); foreach (var paramUse in paramUses) { var paramCode = paramUse.Parameter.Code; var paramValue = paramValues.SingleOrDefault(x => x.Parameter.Code == paramCode); // the value if (null != paramValue && paramValue.NumericValue.HasValue) { writerData.Write((ushort)data.GetNumberIndex(paramValue.NumericValue.Value)); } else if (null != paramValue && !String.IsNullOrWhiteSpace(paramValue.TextValue)) { writerData.Write((ushort)(stringLookUp[paramValue.TextValue] | 0x8000)); } else { writerData.Write((ushort)0xffff); } // the uom of the value if (null != paramValue && null != paramValue.Uom) { writerData.Write((ushort)paramValue.Uom.Code); } else { writerData.Write((ushort)0xffff); } } } writerData.Flush(); } } }
public static void WriteEllipsoids(EpsgData data, BinaryWriter dataWriter, BinaryWriter textWriter) { var stringLookUp = WriteTextDictionary(data, textWriter, data.Repository.Ellipsoids.Select(x => x.Name).DistinctNonEmptyStrings() ); int c = data.Repository.Ellipsoids.Count(); dataWriter.Write((ushort)c); foreach (var ellipsoid in data.Repository.Ellipsoids.OrderBy(x => x.Code)) { dataWriter.Write((ushort)ellipsoid.Code); dataWriter.Write((ushort)data.GetNumberIndex(ellipsoid.SemiMajorAxis)); dataWriter.Write((ushort)data.GetNumberIndex(ellipsoid.InverseFlattening ?? ellipsoid.SemiMinorAxis ?? 0)); dataWriter.Write((ushort)stringLookUp[ellipsoid.Name]); dataWriter.Write((byte)(ellipsoid.Uom.Code - 9000)); } }
public static void WriteUnitOfMeasures(EpsgData data, BinaryWriter lengthWriter, BinaryWriter angleWriter, BinaryWriter scaleWriter, BinaryWriter timeWriter, BinaryWriter textWriter) { var stringLookUp = WriteTextDictionary(data, textWriter, data.Repository.Uoms.Select(x => x.Name).DistinctNonEmptyStrings() ); var uomGroups = data.Repository.Uoms.GroupBy(x => x.Type.ToUpper()); foreach (var uomGroup in uomGroups) { BinaryWriter writer; if (uomGroup.Key == "LENGTH") { writer = lengthWriter; } else if (uomGroup.Key == "ANGLE") { writer = angleWriter; } else if (uomGroup.Key == "SCALE") { writer = scaleWriter; } else if (uomGroup.Key == "TIME") { writer = timeWriter; } else { throw new InvalidDataException("Invalid uom type: " + uomGroup.Key); } writer.Write((ushort)uomGroup.Count()); foreach (var uom in uomGroup.OrderBy(x => x.Code)) { writer.Write((ushort)uom.Code); writer.Write((ushort)stringLookUp[uom.Name]); writer.Write((ushort)data.GetNumberIndex(uom.FactorB ?? 0)); writer.Write((ushort)data.GetNumberIndex(uom.FactorC ?? 0)); } } }
public static void WriteMeridians(EpsgData data, BinaryWriter dataWriter, BinaryWriter textWriter) { var stringLookUp = WriteTextDictionary(data, textWriter, data.Repository.PrimeMeridians.Select(x => x.Name).DistinctNonEmptyStrings() ); int c = data.Repository.PrimeMeridians.Count(); dataWriter.Write((ushort)c); foreach (var meridian in data.Repository.PrimeMeridians.OrderBy(x => x.Code)) { dataWriter.Write((ushort)meridian.Code); dataWriter.Write((ushort)meridian.Uom.Code); dataWriter.Write((ushort)data.GetNumberIndex(meridian.GreenwichLon)); dataWriter.Write((byte)stringLookUp[meridian.Name]); } }
public static void WriteUnitOfMeasures(EpsgData data, BinaryWriter lengthWriter, BinaryWriter angleWriter, BinaryWriter scaleWriter, BinaryWriter timeWriter, BinaryWriter textWriter) { var stringLookUp = WriteTextDictionary(data, textWriter, data.Repository.Uoms.Select(x => x.Name).DistinctNonEmptyStrings() ); var uomGroups = data.Repository.Uoms.GroupBy(x => x.Type.ToUpper()); foreach (var uomGroup in uomGroups) { BinaryWriter writer; if (uomGroup.Key == "LENGTH") writer = lengthWriter; else if (uomGroup.Key == "ANGLE") writer = angleWriter; else if (uomGroup.Key == "SCALE") writer = scaleWriter; else if (uomGroup.Key == "TIME") writer = timeWriter; else throw new InvalidDataException("Invalid uom type: " + uomGroup.Key); writer.Write((ushort)uomGroup.Count()); foreach (var uom in uomGroup.OrderBy(x => x.Code)) { writer.Write((ushort)uom.Code); writer.Write((ushort)stringLookUp[uom.Name]); writer.Write((ushort)data.GetNumberIndex(uom.FactorB ?? 0)); writer.Write((ushort)data.GetNumberIndex(uom.FactorC ?? 0)); } } }
public static void WriteParamData(EpsgData data, BinaryWriter writerText, Func<ushort,BinaryWriter> paramFileGenerator) { var stringLookUp = WriteTextDictionary(data, writerText, data.Repository.ParamTextValues.DistinctNonEmptyStrings() ); foreach (var coordinateOpMethod in data.Repository.CoordinateOperationMethods) { var usedBy = coordinateOpMethod.UsedBy.OrderBy(x => x.Code).ToList(); using(var writerData = paramFileGenerator((ushort)coordinateOpMethod.Code)) { var paramUses = coordinateOpMethod.ParamUse.OrderBy(x => x.SortOrder).ToList(); writerData.Write((byte)paramUses.Count); foreach (var paramUse in paramUses) { writerData.Write((ushort)paramUse.Parameter.Code); writerData.Write((byte)(paramUse.SignReversal.GetValueOrDefault() ? 0x01 : 0x02)); } writerData.Write((ushort)usedBy.Count); foreach (var coordinateOperation in usedBy) { writerData.Write((ushort)coordinateOperation.Code); var paramValues = coordinateOperation.ParameterValues.ToList(); foreach (var paramUse in paramUses) { var paramCode = paramUse.Parameter.Code; var paramValue = paramValues.SingleOrDefault(x => x.Parameter.Code == paramCode); // the value if(null != paramValue && paramValue.NumericValue.HasValue) writerData.Write((ushort)data.GetNumberIndex(paramValue.NumericValue.Value)); else if(null != paramValue && !String.IsNullOrWhiteSpace(paramValue.TextValue)) writerData.Write((ushort)(stringLookUp[paramValue.TextValue] | 0x8000)); else writerData.Write((ushort)0xffff); // the uom of the value if (null != paramValue && null != paramValue.Uom) writerData.Write((ushort)paramValue.Uom.Code); else writerData.Write((ushort)0xffff); } } writerData.Flush(); } } }
public static void WriteMeridians(EpsgData data, BinaryWriter dataWriter, BinaryWriter textWriter) { var stringLookUp = WriteTextDictionary(data, textWriter, data.Repository.PrimeMeridians.Select(x => x.Name).DistinctNonEmptyStrings() ); int c = data.Repository.PrimeMeridians.Count(); dataWriter.Write((ushort)c); foreach (var meridian in data.Repository.PrimeMeridians.OrderBy(x => x.Code)) { dataWriter.Write((ushort)meridian.Code); dataWriter.Write((ushort)meridian.Uom.Code); dataWriter.Write((ushort)data.GetNumberIndex(meridian.GreenwichLon)); dataWriter.Write((byte)stringLookUp[meridian.Name]); } }
public static void WriteEllipsoids(EpsgData data, BinaryWriter dataWriter, BinaryWriter textWriter) { var stringLookUp = WriteTextDictionary(data, textWriter, data.Repository.Ellipsoids.Select(x => x.Name).DistinctNonEmptyStrings() ); int c = data.Repository.Ellipsoids.Count(); dataWriter.Write((ushort)c); foreach (var ellipsoid in data.Repository.Ellipsoids.OrderBy(x => x.Code)) { dataWriter.Write((ushort)ellipsoid.Code); dataWriter.Write((ushort)data.GetNumberIndex(ellipsoid.SemiMajorAxis)); dataWriter.Write((ushort)data.GetNumberIndex(ellipsoid.InverseFlattening ?? ellipsoid.SemiMinorAxis ?? 0)); dataWriter.Write((ushort)stringLookUp[ellipsoid.Name]); dataWriter.Write((byte)(ellipsoid.Uom.Code - 9000)); } }
public static void WriteCoordinateOperations(EpsgData data, BinaryWriter writerText, BinaryWriter writerDataConversion, BinaryWriter writerDataTransformation, BinaryWriter writerDataConcatenated, BinaryWriter writerDataPath) { var stringLookUp = WriteTextDictionary(data, writerText, data.Repository.CoordinateOperations.Select(x => x.Name).DistinctNonEmptyStrings() ); var opGroups = data.Repository.CoordinateOperations.GroupBy(x => x.TypeName.ToLower()); foreach (var opGroup in opGroups) { var ops = opGroup.OrderBy(x => x.Code); var typeName = opGroup.Key; switch (typeName) { case "transformation": { writerDataTransformation.Write((ushort)ops.Count()); foreach (var op in ops) { writerDataTransformation.Write((ushort)op.Code); writerDataTransformation.Write((ushort)op.SourceCrs.Code); writerDataTransformation.Write((ushort)op.TargetCrs.Code); writerDataTransformation.Write((ushort)op.Method.Code); writerDataTransformation.Write((ushort)data.GetNumberIndex(op.Accuracy ?? 999)); writerDataTransformation.Write((ushort)op.Area.Code); writerDataTransformation.Write((byte)(op.Deprecated ? 0xff : 0)); writerDataTransformation.Write((ushort)stringLookUp[op.Name]); } break; } case "conversion": { writerDataConversion.Write((ushort)ops.Count()); foreach (var op in ops) { writerDataConversion.Write((ushort)op.Code); writerDataConversion.Write((ushort)op.Method.Code); writerDataConversion.Write((ushort)op.Area.Code); writerDataConversion.Write((byte)(op.Deprecated ? 0xff : 0)); writerDataConversion.Write((ushort)stringLookUp[op.Name]); } break; } case "concatenated operation": { var pathOffset = 0; writerDataConcatenated.Write((ushort)ops.Count()); foreach (var op in ops) { var catOps = data.Repository.CoordOpPathItems .Where(x => x.CatCode == op.Code) .OrderBy(x => x.Step) .ToList(); foreach (var catOp in catOps) { writerDataPath.Write((ushort)catOp.Operation.Code); } writerDataConcatenated.Write((ushort)op.Code); writerDataConcatenated.Write((ushort)op.SourceCrs.Code); writerDataConcatenated.Write((ushort)op.TargetCrs.Code); writerDataConcatenated.Write((ushort)op.Area.Code); writerDataConcatenated.Write((byte)(op.Deprecated ? 0xff : 0)); writerDataConcatenated.Write((ushort)stringLookUp[op.Name]); writerDataConcatenated.Write((byte)(catOps.Count)); writerDataConcatenated.Write((ushort)pathOffset); pathOffset += catOps.Count * sizeof(ushort); } break; } default: throw new NotSupportedException(); } } }
public static void WriteCoordinateOperations(EpsgData data, BinaryWriter writerText, BinaryWriter writerDataConversion, BinaryWriter writerDataTransformation, BinaryWriter writerDataConcatenated, BinaryWriter writerDataPath) { var stringLookUp = WriteTextDictionary(data, writerText, data.Repository.CoordinateOperations.Select(x => x.Name).DistinctNonEmptyStrings() ); var opGroups = data.Repository.CoordinateOperations.GroupBy(x => x.TypeName.ToLower()); foreach (var opGroup in opGroups) { var ops = opGroup.OrderBy(x => x.Code); var typeName = opGroup.Key; switch (typeName) { case "transformation": { writerDataTransformation.Write((ushort)ops.Count()); foreach (var op in ops) { writerDataTransformation.Write((ushort)op.Code); writerDataTransformation.Write((ushort)op.SourceCrs.Code); writerDataTransformation.Write((ushort)op.TargetCrs.Code); writerDataTransformation.Write((ushort)op.Method.Code); writerDataTransformation.Write((ushort)data.GetNumberIndex(op.Accuracy ?? 999)); writerDataTransformation.Write((ushort)op.Area.Code); writerDataTransformation.Write((byte)(op.Deprecated ? 0xff : 0)); writerDataTransformation.Write((ushort)stringLookUp[op.Name]); } break; } case "conversion": { writerDataConversion.Write((ushort)ops.Count()); foreach (var op in ops) { writerDataConversion.Write((ushort)op.Code); writerDataConversion.Write((ushort)op.Method.Code); writerDataConversion.Write((ushort)op.Area.Code); writerDataConversion.Write((byte)(op.Deprecated ? 0xff : 0)); writerDataConversion.Write((ushort)stringLookUp[op.Name]); } break; } case "concatenated operation": { var pathOffset = 0; writerDataConcatenated.Write((ushort)ops.Count()); foreach (var op in ops) { var catOps = data.Repository.CoordOpPathItems .Where(x => x.CatCode == op.Code) .OrderBy(x => x.Step) .ToList(); foreach (var catOp in catOps) { writerDataPath.Write((ushort)catOp.Operation.Code); } writerDataConcatenated.Write((ushort)op.Code); writerDataConcatenated.Write((ushort)op.SourceCrs.Code); writerDataConcatenated.Write((ushort)op.TargetCrs.Code); writerDataConcatenated.Write((ushort)op.Area.Code); writerDataConcatenated.Write((byte)(op.Deprecated ? 0xff : 0)); writerDataConcatenated.Write((ushort)stringLookUp[op.Name]); writerDataConcatenated.Write((byte)(catOps.Count)); writerDataConcatenated.Write((ushort)pathOffset); pathOffset += catOps.Count * sizeof(ushort); } break; } default: throw new NotSupportedException(); } } }