示例#1
0
文件: ogr.go 项目: renderless/imposm3
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
}
示例#2
0
文件: ogr.go 项目: colek42/gdal
// Fetch the schema information for this layer
func (layer Layer) Definition() FeatureDefinition {
	defn := C.OGR_L_GetLayerDefn(layer.cval)
	return FeatureDefinition{defn}
}