Create a feature class — GSTPy documentation

# Create a feature class

To create a feature class we need its name, its type and its SRS. Optionally we can supply a list of object and simplex properties and set its owner.

name

Each feature class needs a name. This name has to be unique for the owner of the feature class. One owner cannot have two feature classes named “surfaces”, for instance.

In this example we use “example_tin_fc”.

    name = "example_tin_fc"

geom_type

A feature class also needs a type. This determines which kind of feature can be stored in this feature class.

    geom_type = GSTPy.GeometryTypes.Tin3

srs

A feature class should have an SRS. This SRS needs to be one stored in GST.

We can get an SRS by a known id / key:

    srs = GSTPy.SRS.from_gstsrs_id(20012)

Or we can get an SRS by its cody_type and code_value pair.

    srs = next(
        (
            srs
            for srs in ni.list_srs()
            if srs.code_type == "EPSG" and srs.code_value == "25834"
        )
    )

Note

Strictly speaking, an SRS is optional, but it is highly recommended to always set an SRS for a feature class. Ignoring this advice will cause issues with GST Web.

object_properties

Further we can add object properties to a feature class.

    object_properties = [
        GSTPy.NewProperty("external_id", GSTPy.PropertyTypes.TypeInt),
        GSTPy.NewProperty("contact_person", GSTPy.PropertyTypes.TypeText),
    ]

This will add two object properties. One with the name “external_id” and type Int. The other with the name “contact_person” and type text.

simplex_properties

Simplex properties work the same.

    simplex_properties = [
        GSTPy.NewSimplexProperty(
            "gold", GSTPy.PropertyTypes.TypeFloat, GSTPy.PropertyAlignments.VERTEX_ALIGNED
        ),
        GSTPy.NewSimplexProperty(
            "silver", GSTPy.PropertyTypes.TypeFloat, GSTPy.PropertyAlignments.VERTEX_ALIGNED
        ),
    ]

This will add two simplex properties. One with the name “gold”, the other with the name “silver”. Both are of the type float.

owner

At last, we can also set a the owner of the feature class. This is useful if we want to set the owner to a group. The default owner is the current user.

This is how we get the owner for the “EVERYBODY” group.

    owner = next((owner for owner in ni.list_owners() if owner.name == "EVERYBODY_pool"))

create_feature_class

Finally we call the create_feature_class method.

    ni.create_feature_class(
        name=name,
        geom_type=geom_type,
        owner=owner,
        srs=srs,
        object_properties=object_properties,
        simplex_properties=simplex_properties,
    )

Only name, geom_type and srs are really necessary. If you do not have any object and simplex properties to add and the feature class should belong to the current user, you can call it like the following.

    ni.create_feature_class(name, geom_type, srs=srs)

Full code sample

    import GSTPy

    name = "example_tin_fc"
    geom_type = GSTPy.GeometryTypes.Tin3
    srs = GSTPy.SRS.from_gstsrs_id(20012)
    object_properties = [
        GSTPy.NewProperty("external_id", GSTPy.PropertyTypes.TypeInt),
        GSTPy.NewProperty("contact_person", GSTPy.PropertyTypes.TypeText),
    ]
    simplex_properties = [
        GSTPy.NewSimplexProperty(
            "gold", GSTPy.PropertyTypes.TypeFloat, GSTPy.PropertyAlignments.VERTEX_ALIGNED
        ),
        GSTPy.NewSimplexProperty(
            "silver", GSTPy.PropertyTypes.TypeFloat, GSTPy.PropertyAlignments.VERTEX_ALIGNED
        ),
    ]
    owner = next((owner for owner in ni.list_owners() if owner.name == "EVERYBODY_pool"))
    ni.create_feature_class(
        name=name,
        geom_type=geom_type,
        owner=owner,
        srs=srs,
        object_properties=object_properties,
        simplex_properties=simplex_properties,
    )

See also

`GeometryTypes`

`SRS`

`GSTSRSRef`

`SRS.from_gstsrs_id()`

`NetworkInterface.list_srs()`

`NewProperty`

`NetworkInterface.create_feature_class()`