Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Python API Feature Operations

Johannes Kolbe edited this page Aug 5, 2014 · 2 revisions

Accessing Feature Data

There are several ways to access the data of a FeatureCoverage. A fairly simple one is with the help of the Feature Iterator. It's implementation makes the Coverage iterable and thus easy to handle with for feature in featurecoverage.

fc = FeatureCoverage("drainage.shp")
featlist = []

for feature in fc
    featlist.append(feature)

With the above code we get a list with all the features of the Feature Coverage, which in this case has 163 entries.

An other way to access this data is with the help of an Attribute Table you can find an extensive description of how it works on this site of our wiki.

Add new Features

If you want to extend your existing FeatureCoverage or fill a comlpletely new one with feature, you have different options. For once, you can use the .newFeature() method and just pass it a Geometry. This will automatically create the new feature and add it to the existing coverage. You could as well pass a string, that defines a geometry in WKT formatting and the coordinate system in which it is defined to the method.

fc = FeatureCoverage("rainfall.shp")

# define a new geometry and create a new feature from it. 
g = Geometry("POINT(5.4 6 9.0)", fc.coordinateSystem())
newfeatureGeom = fc.newFeature(g)

# don't create a geometry but pass the infromation directly
newfeature = fc.newFeature("POINT(5.4 6 9.0)", fc.coordinateSystem())

Another way to create a new feature is with the help of .newFeatureFrom(). This method is mainly meant to transform an existing feature to a new coordinate system. The two things you need to make this work are of course a feature and actually the old coordinate system, because the method should be called on the coverage that holds the new coordinate system.

You can find more on the method in this part of the wiki.

Clone this wiki locally