OGRFeature feature(layerDefn); feature.SetField("name", "New York"); feature.SetField("population", 8405837); OGRLinearRing ring; OGRPolygon poly; // create a rectangular polygon ring.addPoint(0, 0); ring.addPoint(0, 1); ring.addPoint(1, 1); ring.addPoint(1, 0); ring.closeRings(); poly.addRing(&ring); feature.SetGeometry(&poly); layer->CreateFeature(&feature);
OGRFeature *feature = layer->GetFeature(0); const char* name = feature->GetFieldAsString("name"); int population = feature->GetFieldAsInteger("population"); OGRGeometry *geom = feature->GetGeometryRef();This code retrieves the first feature from a layer. It then extracts the "name", "population", and geometry attributes from the feature. OGRFeature belongs to the OGR library, which is a part of the GDAL (Geospatial Data Abstraction Library) package.