6

I have a single polygon shapefile (EPSG: 3044) which I want to enlarge using QGIS 2.18.16. I tried to use the vector affine transformation plugin, but whenever I try to change the size of the polygon, the whole layer changes its position and shape. Is there a tool in QGIS where I can do this task or is it possible with the affine transformation plugin and I just cannot find the right values?

What I have: Some csv points and a country-border. The points do not have the correct positional accuracy. Therefore I want to enlarge the country-border so that all points fit into the poylgon.

What I get when I change the X and Y scale from 1,0 to 2,0: enter image description here

9
  • Buffering has the downside of producing round corners, hence I would go with extracting the desired polygon from the layer, transform/enlarge it, and then paste it back in. Assuming there are more than one features in your layer?
    – Erik
    Mar 6, 2018 at 14:16
  • I tried buffering and you're right.. the result resulted in round corners which I don't want. The layer consists of only the one polygon which I want to enlarge, I just don't know how to do that.
    – Blabsl
    Mar 6, 2018 at 14:29
  • The transform-tool from the GRASS-GIS toolbox is rather self-explanatory. What happens when you use that one?
    – Erik
    Mar 6, 2018 at 14:34
  • I added two screenshots. The first one is what I have right now. I want the polygon just to be a little bigger so that every point fits in within the border. When I use the v.transform GRASS tool and change the x and y scale the polygon also changes its position and thats what I don't want.
    – Blabsl
    Mar 6, 2018 at 15:36
  • shouldn't the polygon be shrinked to match the points? So that the upper left point is in Sylt?
    – pLumo
    Mar 6, 2018 at 15:54

3 Answers 3

12

Both GRASS (as Erik Lohmann points out) and SAGA have tools that can accomplish this. I've accomplished this in the past using the tool SAGA > Vector General > Transform vector layer.

  1. In order to prevent your shape from "drifting", you'll need to derive the centroid first. Run Centroid, using input polygon_layer. Here's an example, with the centroid labelled using the expression x($geometry)||' '||y($geometry).

polygon w/ centroid

  1. Run Transform vector layer:

    • Shapes = polygon_layer
    • Scale Factor X/Y = the coefficient you want to enlarge by. In this example, I've specified a scale factor of 2 for both, meaning my output will be double the size of the input.
    • For parameters X and Y, input the centroid coordinates. These values serve as the anchor points from which your input will be scaled.

transform dialog

Output from the above shape, with the new shape's centroid visible:

transformed polygon

3
  • 1
    The SAGA tool with help of the centroids did the job! Thanks!
    – Blabsl
    Mar 7, 2018 at 8:38
  • Can this approach be adapted for batch processing, such as if you had a layer with hundreds of polygons you wanted to do this to?
    – Kirkman14
    Sep 17, 2020 at 19:14
  • Oh, absolutely! Just wrap the centroid -> transform process into a model and then batch process the model. It's also worth noting that in the time since my original answer, the latest QGIS version has an affine transform tool built in, and can take data-defined overrides, so you could have the centroid being calculated and insert those values for the translation.
    – jcarlson
    Sep 18, 2020 at 2:11
2

I just had the same issue, and it turns out geopandas allows to do precisely what I needed (i.e. shrink a polygon without changing its centroid) https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.scale.html

It looks something like that:

import geopandas as gpd
polygon = 'yourpolygon.shp'

polygon_shrunk = gpd.read_file(polygon)
polygon_shrunk = temp.scale(x=0.8, y=0.8, origin='center')
polygon_shrunk.to_file('path_to_shrunk_polygon.shp')

1
  • 1
    This is the best alternative for me. Nonetheless, this code did not work for me. I wrote my own code: import geopandas from geopandas import GeoSeries from shapely.geometry import Polygon polygon = geopandas.read_file('2021_sv_peanut_plot_boundary.shp') polygon_shrunk = polygon.scale(0.8,0.8,origin='center') polygon_shrunk.to_file('2021_sv_peanut_plot_boundary_resized.shp') May 23, 2022 at 21:51
1

You seem to have some very conflicting objectives and I can't let this question stand as is when.

You say you don't want to change the shape and you don't want round corners but you don't say why.

The above answer will achieve what you are trying to do but it will not be a good fit to your underlying problem.

You say your points aren't very accurate. Do they get more inaccurate the further they are away from Germany? And do they do so in a linear fashion? and in a radially outward fixed direction? I cannot image that this would ever be the case and as it is the sole reason why you would want to enlarge your shape with an affine expansion, it's safe to say you should not be performing an affine expansion to fit your points.

E.g have a look at the pink and green polygon of the accepted answer. At one section their boundaries are touching. An affine expansion provides no advantage in being able to include inaccurate points here. Imagine what would happen to Sylt by an affine expansion? It would move and although it may catch some inaccurate points off the coast away from Germany, it would exclude points on the mainland side of the island if not potentially exclude the whole thing.

If; however, your inaccurate points are in error by an amount that is uncorrelated with their location, then what you DO want is buffering. Yes it will give round edges and yes it will change the shape but if you want to check if points are near enough then that IS the operation you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.