Upload a feature from a file — GSTPy documentation

# Upload a feature from a file

In this example we upload a feature from a Gocad file. We assume that we already have a feature class similar to the one created in the example Create a feature class. Its feature class description is stored in a variable named `fc`.

We load the geometries of a file with `ParsedGeometry.load_file()`. Note that some files can contain multiple geometries, that is why this function returns a list of geometries.

The first parameter is the file location. For multi file geometries, use the main file, for example the .shp file for a shapefile.

The second parameter is the file type of the file.

The third parameter is the geometry type you want to retrieve.

    import GSTPy

    parsed_geometries = GSTPy.ParsedGeometry.load_file(
        R"python_files\example.ts",
        GSTPy.FileType.GocadFile,
        fc.geometry_type,
    )

We can take look at the parsed geometries to get some information about them. Here we just print the name of the ones we found, which in our example is one geometry named “example_geometry”.

    for parsed_geometry in parsed_geometries:
        print(parsed_geometry.get_name())

For further use, we create a variable of our one geometry.

    parsed_geometry = parsed_geometries[0]

To upload a geometry, we need to set its SRS. Here we know it is the same as the one from the feature class, so we set it to that.

    parsed_geometry.set_srs(fc.srs)

To upload a the properties of geometry, we need to tell how the properties of the geometry should be matched to the ones of the feature class. Here we already know that we want to match the properties of the parsed geometry to the ones in the feature class with the same name.

The matching is done by with a dict that matches the geometry property name to the feature class property name. In our case, these are the same on both side, but this is not required.

For other scenarios, you can get the simplex property information from a feature class with `NetworkInterface.list_simplex_properties()` and from a parsed geometry with `ParsedGeometry.list_simplex_properties()`.

    property_matching = {"gold": "gold", "silver": "silver"}
    parsed_geometry.set_simplex_property_matching(property_matching)

Finally we upload the parsed geometry to GST.

    f = ni.upload_feature(parsed_geometry, fc)

Full code sample

    import GSTPy

    parsed_geometries = GSTPy.ParsedGeometry.load_file(
        R"python_files\example.ts",
        GSTPy.FileType.GocadFile,
        fc.geometry_type,
    )

    for parsed_geometry in parsed_geometries:
        print(parsed_geometry.get_name())

    parsed_geometry = parsed_geometries[0]

    parsed_geometry.set_srs(fc.srs)

    property_matching = {"gold": "gold", "silver": "silver"}
    parsed_geometry.set_simplex_property_matching(property_matching)

    f = ni.upload_feature(parsed_geometry, fc)

Example Gocad file

    GOCAD TSurf 1.0
    HEADER{
    name: example_geometry
    color: 1 0.5 1 1
    }

    GOCAD_ORIGINAL_COORDINATE_SYSTEM
    NAME Default
    AXIS_NAME "X" "Y" "Z"
    AXIS_UNIT "m" "m" "m"
    ZPOSITIVE Elevation
    END_ORIGINAL_COORDINATE_SYSTEM

    PROPERTIES gold silver
    ESIZES 1 1
    NO_DATA_VALUES -99999 -99999

    TFACE
    PVRTX 0 5 0 0 0.3 5.0
    PVRTX 1 7 1 0 -99999 -99999
    PVRTX 2 3 0 1 -99999 0.1
    PVRTX 3 1 1 0 0.4 2.1
    TRGL 0 1 2
    TRGL 2 1 3
    END

See also

`ParsedGeometry`

`NetworkInterface.upload_feature()`

Create a feature class