I have the following test code:
var fs = new FeatureSet()
fs.FilePath = ("c:\\temp\\test.shp")
Assert.Greater(fs.Features.Count) //fails - Features.Count is still zero
The test fails, because setting the FilePath doesn't have the expected side effect of populating the Features and the AttributeTable.
This creates a problem in Serialization. Sometimes a FeatureSet instance is serialized using the DotSpatial.Data.FeatureSet data type. When it is being deserialized, first the default constructor is used (this creates a new empty FeatureSet) and then the FilePath property is being set (this doesn't populate the features as the original author of XmlDeserializer expected).
Suggested solution ideas:
Option 1 - When the FeatureSet is empty and the FilePath property is set, populate the features and attributes of the current instance from the FilePath file.
Option 2 - When serializing a FeatureSet, try to serialize all its geometry features and attributes to the xml file (this would solve the issue of user-generated in-memory FeatureSets that don't have a source file)
Option 3 - When serializing a FeatureSet, try to check the data type. If it's SHP, then serialize it as a PointShapefile, LineShapefile or PolygonShapefile. In other words, delegate the responsibility of serializing from FeatureSet to the DataProvider. For example, the ShapefileProvider would serialize the FilePath but the SpatiaLite provider would serialize the database connection and table name.
var fs = new FeatureSet()
fs.FilePath = ("c:\\temp\\test.shp")
Assert.Greater(fs.Features.Count) //fails - Features.Count is still zero
The test fails, because setting the FilePath doesn't have the expected side effect of populating the Features and the AttributeTable.
This creates a problem in Serialization. Sometimes a FeatureSet instance is serialized using the DotSpatial.Data.FeatureSet data type. When it is being deserialized, first the default constructor is used (this creates a new empty FeatureSet) and then the FilePath property is being set (this doesn't populate the features as the original author of XmlDeserializer expected).
Suggested solution ideas:
Option 1 - When the FeatureSet is empty and the FilePath property is set, populate the features and attributes of the current instance from the FilePath file.
Option 2 - When serializing a FeatureSet, try to serialize all its geometry features and attributes to the xml file (this would solve the issue of user-generated in-memory FeatureSets that don't have a source file)
Option 3 - When serializing a FeatureSet, try to check the data type. If it's SHP, then serialize it as a PointShapefile, LineShapefile or PolygonShapefile. In other words, delegate the responsibility of serializing from FeatureSet to the DataProvider. For example, the ShapefileProvider would serialize the FilePath but the SpatiaLite provider would serialize the database connection and table name.