속성 및 기능 - C# GIS 라이브러리
Contents
[
Hide
]
레이어의 기능 개수 가져오기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
using (VectorLayer layer = VectorLayer.Open(dataDir + "InputShapeFile.shp", Drivers.Shapefile)) | |
{ | |
Console.WriteLine("Total Features in this file: " + layer.Count); | |
} |
레이어 속성에 대한 정보 가져오기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
using (VectorLayer layer = VectorLayer.Open(dataDir + "InputShapeFile.shp", Drivers.Shapefile)) | |
{ | |
Console.WriteLine("The layer has {0} attributes defined.\n", layer.Attributes.Count); | |
foreach (FeatureAttribute attribute in layer.Attributes) | |
{ | |
Console.WriteLine("Name: {0}", attribute.Name); | |
Console.WriteLine("Data type: {0}", attribute.DataType); | |
Console.WriteLine("Can be null: {0}", attribute.CanBeNull); | |
} | |
} |
레이어의 기능 반복
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
using (VectorLayer layer = VectorLayer.Open(dataDir + "InputShapeFile.shp", Drivers.Shapefile)) | |
{ | |
foreach (Feature feature in layer) | |
{ | |
Console.WriteLine(feature.Geometry.AsText()); | |
} | |
} |
기능 속성의 값 가져오기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
using (VectorLayer layer = VectorLayer.Open(dataDir + "InputShapeFile.shp", Drivers.Shapefile)) | |
{ | |
for (int i = 0; i < layer.Count; i++) | |
{ | |
Feature feature = layer[i]; | |
Console.WriteLine("Entry {0} information\n ========================", i); | |
// case 1 | |
string nameValue = feature.GetValue<string>("name"); // attribute name is case-sensitive | |
int ageValue = feature.GetValue<int>("age"); | |
string dobValue = feature.GetValue<DateTime>("dob").ToString(); | |
Console.WriteLine("Attribute value for feature #{0} is: {1}, {2}", nameValue, ageValue, dobValue); | |
// case 2 | |
var objName = feature.GetValue("name"); // attribute name is case-sensitive | |
var objAge = feature.GetValue("age"); | |
var objDob = feature.GetValue("dob"); | |
Console.WriteLine("Attribute object for feature #{0} is: {1}, {2}", objName, objAge, objDob); | |
} | |
} |
기능 속성의 값 가져오기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
using (VectorLayer layer = VectorLayer.Open(dataDir + "InputShapeFile.shp", Drivers.Shapefile)) | |
{ | |
foreach (var feature in layer) | |
{ | |
// reads all the attributes into an array. | |
object[] all = new object[3]; | |
feature.GetValues(all); | |
Console.WriteLine("all : {0}, {1}, {2}", all); | |
// reads several the attributes into an array. | |
object[] several = new object[2]; | |
feature.GetValues(several); | |
Console.WriteLine("several: {0}, {1}", several); | |
// reads the attributes as dump of objects. | |
var dump = feature.GetValuesDump(); | |
Console.WriteLine("dump : {0}, {1}, {2}", dump); | |
Console.WriteLine(); | |
} | |
} |
속성 값으로 기능 필터링
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
using (VectorLayer layer = VectorLayer.Open(dataDir + "InputShapeFile.shp", Drivers.Shapefile)) | |
{ | |
// all features with the date value in the attribute "dob" later than 1982-01-01. | |
foreach (Feature feature in layer.WhereGreater("dob", new DateTime(1982, 1, 1, 0, 0, 0))) | |
{ | |
Console.WriteLine(feature.GetValue<DateTime>("dob").ToShortDateString()); | |
} | |
} |
ShapeFile에서 GeoJSON으로 기능 추출
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
using (VectorLayer inputLayer = VectorLayer.Open(dataDir + "InputShapeFile.shp", Drivers.Shapefile)) | |
{ | |
using (VectorLayer outputLayer = VectorLayer.Create(dataDir + "ExtractFeaturesFromShapeFileToGeoJSON_out.json", Drivers.GeoJson)) | |
{ | |
outputLayer.CopyAttributes(inputLayer); | |
foreach (Feature inputFeature in inputLayer) | |
{ | |
DateTime? date = inputFeature.GetValue<DateTime?>("dob"); | |
if (date == null || date < new DateTime(1982, 1, 1)) | |
{ | |
continue; | |
} | |
//Construct a new feature | |
Feature outputFeature = outputLayer.ConstructFeature(); | |
outputFeature.Geometry = inputFeature.Geometry; | |
outputFeature.CopyValues(inputFeature); | |
outputLayer.Add(outputFeature); | |
} | |
} | |
} |
속성 값 길이 지정
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
using (VectorLayer layer = VectorLayer.Create(dataDir + "SpecifyAttributeValueLength_out.shp", Drivers.Shapefile)) | |
{ | |
// add attributes before adding features | |
FeatureAttribute attribute = new FeatureAttribute("wide", AttributeDataType.String); | |
attribute.Width = 120; | |
layer.Attributes.Add(attribute); | |
Feature feature = layer.ConstructFeature(); | |
feature.SetValue("wide", "this string can be up to 120 characters long now."); | |
layer.Add(feature); | |
} |
Null 값 속성의 값 가져오기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
using (VectorLayer layer = VectorLayer.Open(dataDir + "InputShapeFile.shp", Drivers.Shapefile)) | |
{ | |
int index = 0; | |
foreach (Feature feature in layer) | |
{ | |
DateTime? date = feature.GetValue<DateTime?>("dob"); | |
Console.WriteLine("Feature #{0}", index); | |
Console.WriteLine("\tAttribute value present: {0}", date.HasValue); | |
if (date.HasValue) | |
{ | |
Console.WriteLine("\tAttribute value: {0}", date.Value); | |
} | |
index++; | |
} | |
} |
기능의 값 또는 기본값 가져오기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
//You can set default value for a feature of attribute in a layer | |
using (var layer = Drivers.GeoJson.CreateLayer(dataDir + "data1_out.json")) | |
{ | |
var attribute = new FeatureAttribute("attribute", AttributeDataType.Integer); | |
attribute.CanBeNull = true; | |
attribute.CanBeUnset = true; | |
layer.Attributes.Add(attribute); | |
Feature feature = layer.ConstructFeature(); | |
int? nullValue = feature.GetValueOrDefault<int?>("attribute"); // value == null | |
var defValue1 = feature.GetValueOrDefault<int?>("attribute", 10); // value == 10 | |
var defValue2 = feature.GetValueOrDefault("attribute", 25); // value == 10 | |
Console.WriteLine($"'{nullValue}' vs '{defValue1}' vs '{defValue2}'"); | |
} | |
//Another example where we set the default value to 100 | |
using (var layer = Drivers.GeoJson.CreateLayer(dataDir + "data2_out.json")) | |
{ | |
var attribute = new FeatureAttribute("attribute", AttributeDataType.Double); | |
attribute.CanBeNull = false; | |
attribute.CanBeUnset = false; | |
attribute.DefaultValue = 100; | |
layer.Attributes.Add(attribute); | |
Feature feature = layer.ConstructFeature(); | |
double defValue1 = feature.GetValueOrDefault<double>("attribute"); // value == 100 | |
var defValue2 = feature.GetValueOrDefault("attribute"); // value == 100 | |
feature.SetValue("attribute", 50); | |
var newValue = feature.GetValueOrDefault<double>("attribute"); // value == 50 | |
Console.WriteLine($"'{defValue1}' vs '{defValue2}' vs '{newValue}'"); | |
} |