Regularize building footprints from a vector file. Args: filepath (str): Path to the input vector file. output (str): Path to the output vector file. tempath (str, optional): Path to the temporary directory. Defaults to None. prj_flag (bool, optional)
(
filepath, output, tempath=None, prj_flag=False, min_length=6, min_area=6
)
| 902 | |
| 903 | |
| 904 | def regularize( |
| 905 | filepath, output, tempath=None, prj_flag=False, min_length=6, min_area=6 |
| 906 | ): |
| 907 | """ |
| 908 | Regularize building footprints from a vector file. |
| 909 | |
| 910 | Args: |
| 911 | filepath (str): Path to the input vector file. |
| 912 | output (str): Path to the output vector file. |
| 913 | tempath (str, optional): Path to the temporary directory. Defaults to None. |
| 914 | prj_flag (bool, optional): Flag to indicate if projection transformation is needed. Defaults to False. |
| 915 | min_length (int, optional): Minimum length for regularization. Defaults to 6. |
| 916 | min_area (int, optional): Minimum area for regularization. Defaults to 6. |
| 917 | |
| 918 | Returns: |
| 919 | None |
| 920 | """ |
| 921 | ids = ReadVectorLayer(filepath) |
| 922 | idsMessage = ReadVectorMessage(ids) |
| 923 | ilayer = ids.GetLayer(0) |
| 924 | ilayerDefn = ilayer.GetLayerDefn() |
| 925 | ifeatureCount = ilayer.GetFeatureCount() |
| 926 | delepolygon = ogr.Geometry(ogr.wkbPolygon) |
| 927 | r = 0 |
| 928 | |
| 929 | if tempath is None: |
| 930 | tempath = os.path.join(os.path.dirname(output), "temp") |
| 931 | if not os.path.exists(tempath): |
| 932 | os.makedirs(tempath) |
| 933 | |
| 934 | for i in range(0, ifeatureCount): |
| 935 | ifeature = ilayer.GetFeature(i) |
| 936 | ifeatureOid = ifeature.GetFID() |
| 937 | if r == 0 or r % 3000 == 0: |
| 938 | npath = os.path.join(tempath, str(int(r / 3000)) + ".shp") |
| 939 | ods = CreateVectorFile(npath, idsMessage) |
| 940 | olayer = ods.GetLayer(0) |
| 941 | r = r + 1 |
| 942 | |
| 943 | attrList = GetAttribute(ifeature) |
| 944 | |
| 945 | igeom = ifeature.GetGeometryRef() |
| 946 | if not prj_flag: |
| 947 | igeom = TranformPrj(igeom) |
| 948 | |
| 949 | # aa = igeom.Area() |
| 950 | if igeom.Area() < min_area or igeom is None: |
| 951 | continue |
| 952 | |
| 953 | iringCount = igeom.GetGeometryCount() |
| 954 | |
| 955 | oupolygon = ogr.Geometry(ogr.wkbPolygon) |
| 956 | |
| 957 | for j in range(iringCount): |
| 958 | new = 0 |
| 959 | iring = igeom.GetGeometryRef(j) |
| 960 | delepolygon.AddGeometry(iring) |
| 961 | iringpts = Ring2Pts(iring) |
no test coverage detected