func (ds *DataSource) Query(query string) (*Layer, error) { // create select query if it is only a where statement if !strings.HasPrefix(strings.ToLower(query), "select") { layer, err := ds.Layer() if err != nil { return nil, err } layerDef := C.OGR_L_GetLayerDefn(layer.v) name := C.OGR_FD_GetName(layerDef) query = fmt.Sprintf("SELECT * FROM %s WHERE %s", C.GoString(name), query) } queryc := C.CString(query) defer C.free(unsafe.Pointer(queryc)) layer := C.OGR_DS_ExecuteSQL(ds.v, queryc, nil, nil) if layer == nil { return nil, lastOgrError("unable to execute query '" + query + "'") } return &Layer{layer}, nil }
// Fetch the schema information for this layer func (layer Layer) Definition() FeatureDefinition { defn := C.OGR_L_GetLayerDefn(layer.cval) return FeatureDefinition{defn} }