GIS C# 라이브러리를 사용하여 벡터 레이어 결합

벡터 레이어 결합

Aspose.GIS API를 사용하면 아래 코드 스니펫에 표시된 대로 벡터 레이어를 결합할 수 있습니다.

// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET
//one-to-one left join two layers by 'city' attribute
var options = new JoinOptions
{
JoinAttributeName = "city",
TargetAttributeName = "city"
};
using (var main = Drivers.Kml.OpenLayer(Path.Combine(workFolder, "main.kml")))
using (var second = Drivers.Kml.OpenLayer(Path.Combine(workFolder, "second.kml")))
using (var joined = main.Join(second, options))
{
// read and print joined
var featuresCount = joined.Count;
var attributesCount = joined.Attributes.Count;
var spatialRefSys = joined.SpatialReferenceSystem;
var code = spatialRefSys == null ? "'no srs'" : spatialRefSys.EpsgCode.ToString();
var joinedTempValue = joined[0].GetValue("joined_temp");
Console.WriteLine($"featuresCount: {featuresCount}");
Console.WriteLine($"attributesCount: {attributesCount}");
Console.WriteLine($"spatialRefSys: {code}");
Console.WriteLine($"joinedTempValue: {joinedTempValue}");
}

몇 가지 속성을 사용하여 레이어 결합

Aspose.GIS API를 사용하면 아래 코드 스니펫에 표시된 대로 몇 가지 속성을 결합할 수 있습니다.

// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET
//one-to-one left join two layers by 'city' attribute
var options = new JoinOptions
{
JoinAttributeName = "city",
TargetAttributeName = "city",
//define attributes to join
JoinAttributeNames = new List<string> { "temp", "date" }
};
using (var main = Drivers.Kml.OpenLayer(Path.Combine(workFolder, "main.kml")))
using (var second = Drivers.Kml.OpenLayer(Path.Combine(workFolder, "second.kml")))
using (var joined = main.Join(second, options))
{
// read and print joined
var featuresCount = joined.Count;
var attributesCount = joined.Attributes.Count;
var spatialRefSys = joined.SpatialReferenceSystem;
var code = spatialRefSys == null ? "'no srs'" : spatialRefSys.EpsgCode.ToString();
Console.WriteLine($"featuresCount: {featuresCount}");
Console.WriteLine($"attributesCount: {attributesCount}");
Console.WriteLine($"spatialRefSys: {code}");
}

자체 비교기를 사용하여 레이어 결합

Aspose.GIS API를 사용하면 아래 코드 스니펫에 표시된 대로 자체 비교기를 사용하여 레이어를 결합할 수 있습니다. 이 접근 방식은 대소문자를 구분하지 않는 문자열을 사용하여 데이터를 결합해야 할 때 유용합니다.

// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET
//one-to-one left join two layers by 'city' attribute
var options = new JoinOptions
{
JoinAttributeName = "city",
TargetAttributeName = "city",
//use custom comparer
ConditionComparer = new InsensitiveComparer()
};
using (var main = Drivers.Kml.OpenLayer(Path.Combine(workFolder, "main.kml")))
using (var second = Drivers.Kml.OpenLayer(Path.Combine(workFolder, "second.kml")))
using (var joined = main.Join(second, options))
{
// read and print joined
var featuresCount = joined.Count;
var attributesCount = joined.Attributes.Count;
var spatialRefSys = joined.SpatialReferenceSystem;
var code = spatialRefSys == null ? "'no srs'" : spatialRefSys.EpsgCode.ToString();
var cityValue = joined[4].GetValue("city");
var joinedCityValue = joined[4].GetValue("joined_city");
Console.WriteLine($"featuresCount: {featuresCount}");
Console.WriteLine($"attributesCount: {attributesCount}");
Console.WriteLine($"spatialRefSys: {code}");
Console.WriteLine($"cityValue: {cityValue}");
Console.WriteLine($"joinedCityValue: {joinedCityValue}");
}

비교기 구현.

// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET
private class InsensitiveComparer : IEqualityComparer<object>
{
bool IEqualityComparer<object>.Equals(object x, object y)
{
if (x == null || y == null)
{
return x == y;
}
var xString = x.ToString();
var yString = y.ToString();
return xString.Equals(yString, StringComparison.InvariantCultureIgnoreCase);
}
public int GetHashCode(object obj)
{
return obj.ToString().ToLower().GetHashCode();
}
}