Download a feature

In this example, we assume that the following feature is already stored in GST.

The feature is stored in the feature class “example_tin_fc” of the owner “EVERYBODY_pool”. It has the following object properties.

name value
id 13
name “example_tin_feature”
color rgb(1,0,1)
transparency 0
external_id 5
contact_person “Max Mustermann”

Also the following points and simplex properties.

id x y z gold silver
0 5 0 0 0.3 5.0
1 7 1 0 NULL NULL
2 3 0 1 NULL 0.1
3 1 1 0 0.4 2.1

And the following triangulation.

v1 v2 v3
0 1 2
2 1 3

In a registered format

First we need to get the feature description of the feature we want to download. We have two options.

Getting the feature description

From feature class with name.

fc = next((fc for fc in ni.list_feature_classes()
           if fc.owner == "EVERYBODY_pool" and fc.name == "example_tin_fc"))

f = next((f for f in ni.list_features(fc) if f.name == "example_tin_feature"))

From the feature id.

f = ni.get_feature_desc_by_id(13)

Download Parameter

Using the default parameters.

This downloads the complete feature in the SFS+ format, with the SRS of the feature class

dl = ni.get_feature(f)

Setting the download format.

Here we choose the GOCAD format.

request_format = GSTPy.RequestFormat.GCD
dl = ni.get_feature(f, request_format)

Setting the request SRS.

Here we see how to download a feature in a specific SRS.

srs = GSTPy.SRS.from_proj4("+proj=utm +zone=34 +datum=WGS84 +units=m +no_defs")
dl = ni.get_feature(f, srs=srs)

Setting the query box.

This limits the feature to the spatial extent set by the box parameter.

box = GSTPy.Box(0, 0, 0, 1, 1, 1)
qb = GSTPy.QueryBox(box, srs=srs)
dl = ni.get_feature(f, query_box=qb)

Or we can do all of the above combined.

dl = ni.get_feature(f, request_format=request_format, srs=srs, query_box=qb)

In a custom format with IParsingActions

Downloading a feature in a custom format has the same parameters as with a registered format. The only difference is that request_format is replaced by a custom callback.

Here we use the CsvCallback that we implemented in another example.

import GSTPy
from csv_points_only import CsvCallback

f = ni.get_feature_desc_by_id(13)

cb = CsvCallback()
ni.get_feature_custom_format(f, cb)
print cb.get_csv_string()

This should ouput the following.

>>> x,y,z,gold,silver
>>> 5,0,0,0.3,0.5
>>> 7,1,0,,
>>> 3,0,1,,0.1
>>> 1,1,0,0.4,2.1