Is it possible to return the boundary (outside) perimeter of a polygon layer?
Let's say you have the map of the USA, for simplicity, broken down to the county level, is it possible to return the boundary map of the whole country from that map?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityIs it possible to return the boundary (outside) perimeter of a polygon layer?
Let's say you have the map of the USA, for simplicity, broken down to the county level, is it possible to return the boundary map of the whole country from that map?
You can just do a dissolve on the county layer (be sure to have just the counties you want to dissolve selected).
You can use GRASS module: v.dissolve
You only need to import your data into GRASS. Here is a screen-cast of transferring your data to Grass from inside QGis.
Allow me to plug my own project... Boundary Generator will give you both external and internal boundaries of every polygon (as line features).
Internal boundaries are attributed with the FID for each of the two polygons that share that border. External boundaries should have an FID of zero for one of those two, so they are easy to select out of the full result.
The nice thing about it vs doing dissolves is that I've added a couple of knobs over precision so it can deal with not-quite-perfect data. (How far apart should two polygon borders be to be considered a shared border? How much angle deviation is required?)
It's still in alpha and it's been a while since I've tackled an update; I'd love to hear how well it works for you!
public static IPolygon getPolygonFromLayer(ILayer layer)
{
IFeatureLayer FLayer = layer as IFeatureLayer;
IFeatureClass FClass = FLayer.FeatureClass;
return polygonMerge(FClass);
}
private static IPolygon polygonMerge(IFeatureClass featureClass)
{
if (featureClass == null) return null;
IGeoDataset geoDataset = featureClass as IGeoDataset;
//You can use a spatial filter to create a subset of features to union together.
//To do that, uncomment the next line, and set the properties of the spatial filter here.
//Also, change the first parameter in the IFeatureCursor.Seach method.
//ISpatialFilter queryFilter = new SpatialFilterClass();
IGeometry geometryBag = new GeometryBagClass();
//Define the spatial reference of the bag before adding geometries to it.
geometryBag.SpatialReference = geoDataset.SpatialReference;
//Use a nonrecycling cursor so each returned geometry is a separate object.
IFeatureCursor featureCursor = featureClass.Search(null, false);
IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;
IFeature currentFeature = featureCursor.NextFeature();
while (currentFeature != null)
{
//Add a reference to this feature's geometry to the bag.
//Since you don't specify the before or after geometry (missing),
//the currentFeature.Shape IGeometry is added to the end of the geometryCollection.
object missing = Type.Missing;
geometryCollection.AddGeometry(currentFeature.Shape, ref missing, ref missing);
currentFeature = featureCursor.NextFeature();
}
// Create the polygon that will be the union of the features returned from the search cursor.
// The spatial reference of this feature does not need to be set ahead of time. The
// ConstructUnion method defines the constructed polygon's spatial reference to be the
// same as the input geometry bag.
ITopologicalOperator unionedPolygon = new PolygonClass();
unionedPolygon.ConstructUnion(geometryBag as IEnumGeometry);
return unionedPolygon as IPolygon;
}
}
Your getting lines when you do a dissolve because the boundaries are not seamless.
Regardless of software product, do the following:
Do an integrate.
Then do a dissolve.
It sounds like the Bounding Containers sample posted on arcgis.com will work for what you want.
I know this is an old question, but I think the answer I just found was introduced since the previous ones here, so I'm sharing it for people who find this in a search.
QGIS (as of version 2.14 at least), has a "Fill Holes" in the Processing toolbox, under QGIS geoalgorithms > Vectory geometry tools. I find that dissolving shapes and then running Fill Holes with the Max area parameter set very high solves this problem.
You may also be looking for what used to be called DROPLINE functionality.
Although it did not survive the ArcInfo Workstation to ArcGIS Desktop transition, there is currently an ArcGIS Idea to have it restored:
It would be nice to have the option to drop the lines between polygons that have the same values for a specified field. This functionality used to be available in ArcPlot as the DROPLINE command and was widely used as a way to avoid creating a new dataset with the dissolve command.
You can use the ST_UNION
function in PostGIS from QGIS DB Manager to aggregate all polygons in the layer (or many groups of polygons into larger polygons). From the documentation:
Variant 2 is an aggregate function that takes a set of geometries and unions them into a single ST_Geometry resulting in no intersecting regions