التحقق من الهندسة
Contents
[
Hide
]
تتيح لك واجهة برمجة تطبيقات Aspose.GIS التحقق من صحة الأشكال الهندسية لعدد من العمليات. إنه يوفر لك القدرة على التحقق من صحة الشكل الهندسي للقواعد المتعلقة بالأشكال الهندسية بالإضافة إلى المواصفات بواسطة تنسيقات الملفات الجغرافية المكانية.
التحقق من صحة الشكل الهندسي
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 | |
LinearRing linearRing = new LinearRing(); | |
linearRing.AddPoint(0, 0); | |
linearRing.AddPoint(0, 1); | |
linearRing.AddPoint(1, 0); | |
bool valid = linearRing.IsValid; // valid == false | |
linearRing.AddPoint(0, 0); | |
valid = linearRing.IsValid; // valid == true |
التحقق من صحة الشكل الهندسي البسيط
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 | |
LineString lineString = new LineString(); | |
bool simple = lineString.IsSimple; // simple == true | |
lineString.AddPoint(0, 0); | |
lineString.AddPoint(1, 0); | |
simple = lineString.IsSimple; // simple == true | |
lineString.AddPoint(0.5, 0); | |
simple = lineString.IsSimple; // simple == false (line string crosses itself) |
التحقق من صحة الأشكال الهندسية عند الكتابة
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 | |
var exteriorRing = new LinearRing(); | |
exteriorRing.AddPoint(0, 0); | |
exteriorRing.AddPoint(0, 1); | |
exteriorRing.AddPoint(1, 1); | |
exteriorRing.AddPoint(1, 0); | |
exteriorRing.AddPoint(0, 0); | |
var interiorRing = new LinearRing(); | |
interiorRing.AddPoint(0.5, 0.5); | |
interiorRing.AddPoint(1, 0.5); | |
interiorRing.AddPoint(1, 1); | |
interiorRing.AddPoint(0.5, 1); | |
interiorRing.AddPoint(0.5, 0.5); | |
var invalidPolygon = new Polygon(); | |
invalidPolygon.ExteriorRing = exteriorRing; | |
invalidPolygon.AddInteriorRing(interiorRing); | |
// invalidPolygon.IsValid == false, since polygon rings share segments (have infinite number of intersection points) | |
GeoJsonOptions options = new GeoJsonOptions(); | |
options.ValidateGeometriesOnWrite = false; // false is default | |
File.Delete(dataDir + "not_validated_data_out.shp"); | |
using (var nonValidatingLayer = Drivers.GeoJson.CreateLayer(dataDir + "not_validated_data_out.shp", options)) | |
{ | |
Feature feature = nonValidatingLayer.ConstructFeature(); | |
feature.Geometry = invalidPolygon; | |
// no exception is thrown, since ValidateGeometriesOnWrite == false, and GeoJson specification doesn't say that rings of polygon can't share segments. | |
nonValidatingLayer.Add(feature); | |
} | |
options.ValidateGeometriesOnWrite = true; | |
File.Delete(dataDir + "validated_data_out.shp"); | |
using (var validatingLayer = Drivers.GeoJson.CreateLayer(dataDir + "validated_data_out.shp", options)) | |
{ | |
Feature feature = validatingLayer.ConstructFeature(); | |
feature.Geometry = invalidPolygon; | |
try | |
{ | |
validatingLayer.Add(feature); // GisException is thrown, since polygon is not valid | |
} | |
catch (GisException e) | |
{ | |
Console.WriteLine(e.Message); | |
} | |
} |
التحقق من صحة الأشكال الهندسية عند الكتابة مع الالتزام بالمواصفات
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 | |
LineString lineStrinWithOnePoint = new LineString(); | |
lineStrinWithOnePoint.AddPoint(0, 0); | |
GeoJsonOptions options = new GeoJsonOptions(); | |
options.ValidateGeometriesOnWrite = false; | |
using (var layer = Drivers.GeoJson.CreateLayer(dataDir + "ValidateOnWriteObeyingSpecifications_out.json", options)) | |
{ | |
Feature feature = layer.ConstructFeature(); | |
// GeoJSON specification says that line string must have at least two coordinates. | |
feature.Geometry = lineStrinWithOnePoint; | |
try | |
{ | |
// Geometry of feature doesn't match data format specification, so exception is thrown | |
// regardless what ValidateGeometriesOnWrite option is. | |
layer.Add(feature); | |
} | |
catch (GisException e) | |
{ | |
Console.WriteLine(e.Message); | |
} | |
} |