예제 #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}
}