Hello,
I am trying to combine multiple shape files into one. But there does not appear to be a straight forward way to do it. Can you provide an example of how I can combine two independent shape files into one?
Thank you.
Hello,
I am trying to combine multiple shape files into one. But there does not appear to be a straight forward way to do it. Can you provide an example of how I can combine two independent shape files into one?
Thank you.
Hi, @vbwizardry
Thank you for your interest in the Aspose.GIS product.
Please try the below code:
using (VectorLayer layer = VectorLayer.Create("output.shp", Drivers.Shapefile))
{
// copy attribute from first layer
using (VectorLayer inputLayer = VectorLayer.Open("input01.shp", Drivers.Shapefile))
{
foreach (FeatureAttribute sourceAttribute in inputLayer.Attributes)
{
var attribute = new FeatureAttribute(sourceAttribute.Name, sourceAttribute.DataType);
layer.Attributes.Add(attribute);
}
}
// copy attribute from second layer
using (VectorLayer inputLayer = VectorLayer.Open("input02.shp", Drivers.Shapefile))
{
foreach (FeatureAttribute sourceAttribute in inputLayer.Attributes)
{
var attribute = new FeatureAttribute(sourceAttribute.Name, sourceAttribute.DataType);
layer.Attributes.Add(attribute);
}
}
// copy data from first
using (VectorLayer inputLayer = VectorLayer.Open("input01.shp", Drivers.Shapefile))
{
foreach (Feature inputFeature in inputLayer)
{
//Construct a new feature
Feature outputFeature = layer.ConstructFeature();
outputFeature.Geometry = inputFeature.Geometry;
outputFeature.CopyValues(inputFeature);
}
}
// copy data from second
using (VectorLayer inputLayer = VectorLayer.Open("input01.shp", Drivers.Shapefile))
{
foreach (Feature inputFeature in inputLayer)
{
//Construct a new feature
Feature outputFeature = layer.ConstructFeature();
outputFeature.Geometry = inputFeature.Geometry;
outputFeature.CopyValues(inputFeature);
}
}
}
Thanks