AreaLimiter — GSTPy documentation

# AreaLimiter

The AreaLimiter allows to specify a selection area, either a polygon or a bounding box, the condition geometries have to meet in regards to the to be loaded (contained in area or intersecting the area) and how selected geometries will be loaded (full geometry or only the parts inside the area).

In this example we use an existing feature class with polygons and dowload features from a layers feature class with an area limiter.

    import GSTPy
    from pathlib import Path

    # base dir where we want to store the output
    base_dir = Path(r"D:\temp\area_limiter")
    # define a fixed load mode and threshold for the whole operation
    #
    # selected features will load the part inside the selection area
    load_mode = GSTPy.GeometryLoadMode.Partial
    # only load features, if they intersect the selection area
    load_threshold = GSTPy.GeometryLoadThreshold.Intersected
    # download format will be Gocad
    request_format = GSTPy.RequestFormat.GCD
    # Get all feature classes
    feature_classes = ni.list_feature_classes()
    # Store the polygon feature class
    polygon_feature_class = next(
        (fc for fc in feature_classes
         if fc.owner_name == "EVERYBODY_pool" and fc.name == "polygons"))
    # Store the layer feature class
    layer_feature_class = next(
        (fc for fc in feature_classes
         if fc.owner_name == "EVERYBODY_pool" and fc.name == "layers"))
    # loop through each polygon feature of the polgyon feature class
    print("Starting download.")
    # retrieve the polygon features
    polygon_features = ni.list_features(polygon_feature_class)
    for polygon_feature in polygon_features:
        # define our selection area to be the current polygon_feature
        area = GSTPy.Area(GSTPy.PolygonSelection(polygon_feature))
        # define the area limiter with the selection area and our defined load
        # mode and threshold
        area_limiter = GSTPy.AreaLimiter(area, load_mode, load_threshold)
        # define download dir to
        # "base_dir / the layer feature class / polygon feature with feature class"
        # note: the filename will be set by GST to the (sanitized) feature name
        polygon_feature_full_name = polygon_feature_class.full_name + "." + polygon_feature.name
        download_dir = base_dir / layer_feature_class.full_name / polygon_feature_full_name
        # create the download dir on the filesytem
        download_dir.mkdir(parents=True, exist_ok=True)
        # loop through all layers and save them to the download dir with the above
        # area  limiter
        print(f"  Starting download with polygon {polygon_feature.name}.")
        # retrieve the layers
        layers = ni.list_features(layer_feature_class)
        for layer in layers:
            print(f"    Starting download layer {layer.name}...",
                  end='',
                  flush=True)
            # to not abort on the first error, we wrap this call in a try..except
            # block and print the error
            #
            # note: trying to dowload a feature that is rejected by the area
            # limiter, e.g. if it is not inside the area, will also raise an
            # exception
            try:
                ni.save_feature_area_limiter(layer,
                                             str(download_dir),
                                             request_format=request_format,
                                             area_limiter=area_limiter)
                print(f"Success.")
            except Exception as e:
                print(f"Failure: {e}.")
        print(f"  Finished download with polygon {polygon_feature.name}.")
    print("Finished download.")

See also

`NetworkInterface.save_feature_area_limiter()`

`AreaLimiter`

`GeometryLoadMode`

`GeometryLoadThreshold`