# [OSGeo Africa] Split a polygon into smaller parts based on percentage values

Jacobus Strydom jcstay123 at gmail.com
Tue Jun 30 02:13:57 PDT 2015

```Good day,

I need to automatically split polygons based on a percentage value of the
original polygon.

For example, if I have a polygon with a size of 100 ha, I want to split it
so that I have two polygons one that is 25ha  (25% of the size of the
original) and another that is 75ha (75% of the size of the original).

The split can be done from any direction as long as the polygon is split in
the the right sized parts.

I have found an SQL script , working in PostGIS of course, that is suppose
to split a polygon in to two equal parts, but I'm having some trouble
modifying it to slits based on the percentage values. The script is below.
Will it even be possible to use this to do what I want?

Can anyone help,

-----script to split a polygon in to 2 equal parts

WITH RECURSIVE
ref(the_geom, env) AS (
SELECT the_geom,
ST_Envelope(the_geom) As env,
ST_Area(The_geom)/2 As targ_area,
1000 As nit
FROM Table
),

T(n,overlap) AS (
VALUES (CAST(0 As Float),CAST(0 As Float))
UNION ALL
SELECT n + nit, ST_Area(ST_Intersection(the_geom, ST_Translate(env, n+nit, 0)))
FROM T CROSS JOIN ref
WHERE ST_Area(ST_Intersection(the_geom, ST_Translate(env, n+nit, 0)))>
ref.targ_area
) ,

bi(n) AS
(SELECT n
FROM T
ORDER BY n DESC LIMIT 1)

SELECT bi.n,
ST_Difference(the_geom, ST_Translate(ref.env, n,0)) As geom_part1,
ST_Intersection(the_geom, ST_Translate(ref.env, n,0)) As geom_part2
FROM bi CROSS JOIN ref;

----end script